Skip to content

Health Checks

Michael Pratt edited this page Apr 29, 2016 · 2 revisions

API Client Framework Health Checks

The core module contains a few classes and interfaces to facilitate building health checks. Note that the core system does not bind you to any particular health and metrics platform. At HomeAdvisor we used Codahale metrics, but the framework is generic enough to let you use any provider you want.

HealthCheck

This interface represents a single health check within the client. A single client may implement multiple checks. It has a single method, doCheck, that returns a HealthCheckResult.

HealthCheckResult

The class represents the result of a single health check. It contains 2 fields:

  1. Status: An enum of possible results (HEALTY, IMPAIRED, UNHEALTHY, UNKNOWN).
  2. String: A message to provide context about the Status.

HealthCheckAwareClient

This interface should be used for any client that wishes to expose health checks. It uses Java 8 default methods to provide some basic functionality, such as rolling up the results of multiple _HealthCheck_s into a single result.

HystrixHealthCheck

This is an implementation of HealthCheck that uses Hystrix failures to determine client health. It relies on HystrixCommandMetrics for a given command name, and by default will report UNHEALTY if there has been at least 1 failure in the last N seconds, where N is defined by metricsRollingStatisticalWindowInMilliseconds.

Neither AbstractApiClient or SpringRestClient create health checks by default. At HomeAdvisor, we have a custom extension of SpringRestClient that uses Codahale MetricsRegistry to create a number of health checks for both Hystrix and Curator, and the expose them into our reporting framework.