public interface HealthCheck
Health checks are typically used for reporting and monitoring purposes.
The results exposed by health checks can be reported via HTTP by a HealthCheckHandler
.
The actual check is implemented by the check(ExecControl, Registry)
method, that returns a promise for a HealthCheck.Result
.
The inspiration for health checks in Ratpack comes from the Dropwizard Metrics library. Ratpack health checks are different in that they support non blocking checks, and all health checks require a unique name.
HealthCheckHandler
Modifier and Type | Interface and Description |
---|---|
static class |
HealthCheck.Result
The result of a health check.
|
Modifier and Type | Method and Description |
---|---|
Promise<HealthCheck.Result> |
check(ExecControl execControl,
Registry registry)
Checks the health of the component, providing a promise for the result.
|
String |
getName()
The unique name of the health check.
|
static HealthCheck |
of(String name,
BiFunction<? super ExecControl,? super Registry,? extends Promise<HealthCheck.Result>> func)
Convenience factory for health check implementations.
|
String getName()
Each health check within an application must have a unique name.
Promise<HealthCheck.Result> check(ExecControl execControl, Registry registry) throws Exception
This method returns a promise to allow check implementations to be asynchronous.
If the implementation does not need to be asynchronous, the result can be returned via ExecControl.promiseOf(Object)
.
The registry
argument is the server registry, from which other supporting objects can be obtained.
If this method throws an exception, it is logically equivalent to returned an unhealthy result with the thrown exception.
If the method returns a failed promise, it will be converted to a result using HealthCheck.Result.unhealthy(Throwable)
.
execControl
- an execution controlregistry
- the server registryException
- anystatic HealthCheck of(String name, BiFunction<? super ExecControl,? super Registry,? extends Promise<HealthCheck.Result>> func)
import ratpack.test.exec.ExecHarness;
import ratpack.registry.Registry;
import ratpack.health.HealthCheck;
import static org.junit.Assert.*;
public class Example {
public static void main(String... args) throws Exception {
HealthCheck.Result result = ExecHarness.yieldSingle(e ->
HealthCheck.of("test", (execControl, registry) ->
execControl.promiseOf(HealthCheck.Result.healthy())
).check(e, Registry.empty())
).getValue();
assertTrue(result.isHealthy());
}
}
name
- a name of health checkfunc
- a health check implementation