Skip to content

Commit

Permalink
feat: health check
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun committed Sep 10, 2024
1 parent c88b65f commit 680ce3c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
7 changes: 6 additions & 1 deletion ingester-protocol/src/main/java/io/greptime/GreptimeDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/**
* The GreptimeDB client.
*/
public class GreptimeDB implements Write, WriteObject, Lifecycle<GreptimeOptions>, Display {
public class GreptimeDB implements Write, WriteObject, Lifecycle<GreptimeOptions>, HealthCheck, Display {

private static final Logger LOG = LoggerFactory.getLogger(GreptimeDB.class);

Expand Down Expand Up @@ -177,6 +177,11 @@ public StreamWriter<Table, WriteOk> streamWriter(int maxPointsPerSecond, Context
return this.writeClient.streamWriter(maxPointsPerSecond, attachCtx(ctx));
}

@Override
public CompletableFuture<Boolean> is_alive() {
return null;
}

@Override
public void display(Printer out) {
out.println("--- GreptimeDB Client ---")
Expand Down
29 changes: 29 additions & 0 deletions ingester-protocol/src/main/java/io/greptime/HealthCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2023 Greptime Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.greptime;

import java.util.concurrent.CompletableFuture;

/**
* Health check. It just like to probe the database and connections.
* Users can use this status to perform fault tolerance and disaster recovery actions.
*
* @author jiachun.fjc
*/
public interface HealthCheck {
CompletableFuture<Boolean> is_alive();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,42 @@
import io.greptime.rpc.MethodDescriptor;
import io.greptime.rpc.RpcFactoryProvider;
import io.greptime.v1.Database;
import io.greptime.v1.Health;

/**
* The RPC service register.
*/
public class RpcServiceRegister {

private static final String METHOD_TEMPLATE = "greptime.v1.GreptimeDatabase/%s";
private static final String DATABASE_METHOD_TEMPLATE = "greptime.v1.GreptimeDatabase/%s";
private static final String HEALTH_METHOD_TEMPLATE = "greptime.v1.Health/%s";

public static void registerAllService() {
// register protobuf serializer
// Handle
MethodDescriptor handleMethod = MethodDescriptor
.of(String.format(DATABASE_METHOD_TEMPLATE, "Handle"), MethodDescriptor.MethodType.UNARY, 1);
RpcFactoryProvider.getRpcFactory()
.register(
MethodDescriptor.of(
String.format(METHOD_TEMPLATE, "Handle"), MethodDescriptor.MethodType.UNARY, 1),
.register(handleMethod,
Database.GreptimeRequest.class,
Database.GreptimeRequest.getDefaultInstance(),
Database.GreptimeResponse.getDefaultInstance());

// HandleRequests
MethodDescriptor handleRequestsMethod = MethodDescriptor
.of(String.format(DATABASE_METHOD_TEMPLATE, "HandleRequests"), MethodDescriptor.MethodType.CLIENT_STREAMING);
RpcFactoryProvider.getRpcFactory()
.register(
MethodDescriptor.of(
String.format(METHOD_TEMPLATE, "HandleRequests"),
MethodDescriptor.MethodType.CLIENT_STREAMING),
.register(handleRequestsMethod,
Database.GreptimeRequest.class,
Database.GreptimeRequest.getDefaultInstance(),
Database.GreptimeResponse.getDefaultInstance());

// HealthCheck
MethodDescriptor healthCheckMethod = MethodDescriptor.of(
String.format(HEALTH_METHOD_TEMPLATE, "HealthCheck"), MethodDescriptor.MethodType.UNARY);
RpcFactoryProvider.getRpcFactory()
.register(healthCheckMethod,
Health.HealthCheckRequest.class,
Health.HealthCheckRequest.getDefaultInstance(),
Health.HealthCheckResponse.getDefaultInstance());
}
}

0 comments on commit 680ce3c

Please sign in to comment.