Service Health Checks

Helidon gRPC services provide a built-in support for Helidon Health Checks.

Unless a custom health check is implemented by the service developer, each service deployed to the gRPC server will be provisioned with a default health check, which always returns status of UP.

This allows all services, including the ones that don’t have a meaningful health check, to show up in the health report (or to be queried for health) without service developer having to do anything.

However, services that do need custom health checks can easily define one, directly within GrpcService implementation:

public class MyService implements GrpcService {

    @Override
    public void update(ServiceDescriptor.Rules rules) {
        rules.unary("MyMethod", this::myMethod)
                .healthCheck(this::healthCheck);  
    }

    private HealthCheckResponse healthCheck() {
        boolean fUp = isMyServiceUp();            
        return HealthCheckResponse
                .named(name())                    
                .state(fUp)                       
                .withData("ts", System.currentTimeMillis())  
                .build();
    }

    private <ReqT, ResT> void myMethod(ReqT request, StreamObserver<ResT> observer) {
        // do something
    }
}
Copied
  • Configure a custom health check for the service
  • Determine service status
  • Use service name as a health check name for consistency
  • Use determined service status
  • Optionally, provide additional metadata

You can also define custom health check for an existing service, including plain io.grpc.BindableService implementations, using service configurer inside the GrpcRouting deefinition:

private static GrpcRouting createRouting() {
    return GrpcRouting.builder()
            .register(new EchoService(), cfg -> cfg.healthCheck(MyCustomHealthChecks::echoHealthCheck))  
            .build();
}
Copied
  • Configure custom health check for an existing or legacy service

Exposing Health Checks

All gRPC service health checks are managed by the Helidon gRPC Server, and are automatically exposed to the gRPC clients using custom implementation of the standard gRPC HealthService API.

However, they can also be exposed to REST clients via standard Helidon/Microprofile /health endpoint:

        GrpcServer grpcServer = GrpcServer.create(grpcServerConfig(), createRouting(config));  
        grpcServer.start();                                                                    

        HealthSupport health = HealthSupport.builder()
                .add(grpcServer.healthChecks())     
                .build();

        Routing routing = Routing.builder()
                .register(health)                   
                .build();

        WebServer.create(webServerConfig(), routing).start();   
Copied
  • Create GrpcServer instance
  • Start gRPC server, which will deploy all services and register default and custom health checks
  • Add gRPC server managed health checks to HealthSupport instance
  • Add HealthSupport to the web server routing definition
  • Create and start web server

All gRPC health checks will now be available via /health REST endpoint, in addition to the standard gRPC HealthService