Health Checks¶
Create default Health Check¶
The functional interface HealthCheck
together with the annotations @Liveness
and @Readiness
are the key concepts to bring up a new
health check. Following code snipping shows a very basic example on how to use the interface. The parameter isDefault
with value true
makes sure that this health check is covered during server startup (see section Settings in administration guide) and exposed to /health
.
@Liveness(isDefault = true)
public class SampleHealthCheck implements HealthCheck{
@Override
public HealthCheckResponse call() {
return HealthCheckResponse.named("sample-default")
.state(true)
.withData("key", "value")
.build();
}
}
Important
Make sure to use @Liveness
and @Readiness
from package io.ox.proxy.health.impl
otherwise health checks could not be registered.
Create custom Health Check Endpoint¶
To create a health check which should not be exposed via /health
/health/live
or /health/ready
change health check´s default to false
, create a new resource class with proper @PATH
annotation and send health check´s response back to caller.
- Custom Health Check:
@Liveness(isDefault = false) public class SampleHealthCheck implements HealthCheck{ @Override public HealthCheckResponse call() { return HealthCheckResponse.named("sample-custom") .state(true) .withData("key", "value") .build(); } }
- Custom Endpoint:
@Path("/custom") public class SampleResource { @Path("/sample") @GET @Produces(MediaType.APPLICATION_JSON) public Response getCallHealthCheck() { // The Health Check to call return Response.ok().entity(new SampleHealthCheck().call()).build(); } }
Important
The SampleHealthCheck
class can be placed in a package of your choise but make sure to place SampleResource
in package io.ox.proxy.jersey.resource
otherwise this resource could not be bind to JAX-RS context.