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 046280a
Show file tree
Hide file tree
Showing 3 changed files with 39 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 @@ -251,6 +251,11 @@ private static WriteClient makeWriteClient(GreptimeOptions opts, RouterClient ro
return writeClient;
}

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

static final class RpcConnectionObserver implements RpcClient.ConnectionObserver {

static final Counter CONN_COUNTER = MetricsUtil.counter("connection_counter");
Expand Down
13 changes: 13 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,13 @@
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 046280a

Please sign in to comment.