Class ActuatorHealthStatusProvider

java.lang.Object
com.github.jpmsilva.jsystemd.DelayableHealthProvider
com.github.jpmsilva.jsystemd.spring.ActuatorHealthStatusProvider
All Implemented Interfaces:
HealthProvider, StatusProvider

public class ActuatorHealthStatusProvider extends DelayableHealthProvider implements StatusProvider
Provides the application health based on Spring Boot Actuator health contributors: as a HealthProvider, for the systemd watchdog, and as a StatusProvider, for the systemd status.

The health contributors are those of the Spring Boot health contributor registries, the ones shown by the health endpoint, with the same names, such as db or diskSpace. They are read on every evaluation, so that contributors registered or unregistered later are taken into account. A composite contributor, such as the one of several data sources, is unhealthy while any of its members is, and its details are those of its unhealthy members, under their names.

The health indicators can be limited to the members of a health group of Spring Boot Actuator, such as one set up with management.endpoint.health.group.<name>.include: the others are neither shown in the status nor taken into account for the health. Membership is tested as the health endpoint does, with the path of each health indicator, such as db, or db/primary for a member of a composite.

The application is unhealthy while any of the health contributors reports one of the status codes considered as unhealthy. The systemd status always shows that health, while the watchdog is only told about it when enabled, as it lets systemd restart the application: otherwise, the application is always healthy for the watchdog. As the health contributors often depend on external systems, whose outages may be short, reporting the unhealthy state to the watchdog can also be delayed, with DelayableHealthProvider.setUnhealthyDelay(Duration). The systemd status always shows the actual health, without the delay.

Author:
Christian Lorenz, Joao Silva
  • Constructor Details

    • ActuatorHealthStatusProvider

      public ActuatorHealthStatusProvider(HealthContributors contributors, Set<Status> unhealthyStatusCodes, Predicate<String> member, boolean health)
      Creates a new instance using the provided health contributors and unhealthy status codes.
      Parameters:
      contributors - the health contributors, such as the Spring Boot health contributor registry: the details of each unhealthy contributor are reported under its name
      unhealthyStatusCodes - the status codes considered as unhealthy
      member - tells if a health indicator, by its path, such as db or db/primary, is shown in the status and taken into account for the health, such as HealthEndpointGroup.isMember(String), or name -> true for all of them
      health - true to report the unhealthy state to the watchdog, false to only show it in the systemd status
  • Method Details

    • evaluateHealth

      protected HealthProvider.Health evaluateHealth()
      Provides the health of the application for the watchdog, without the delay: always healthy unless reporting the unhealthy state to the watchdog is enabled.
      Specified by:
      evaluateHealth in class DelayableHealthProvider
      Returns:
      the health of the application for the watchdog
    • status

      public String status()
      Provides the application health for the systemd status, naming the unhealthy contributors, if any.

      The details of the unhealthy contributors are left out, as they often contain sensitive information (error messages, host names, paths, ...), and the systemd status can be read by any local user, for instance with systemctl status, regardless of how health details are exposed by Spring Boot Actuator. The details are logged instead when the watchdog heartbeat is suppressed.

      Specified by:
      status in interface StatusProvider
      Returns:
      the application health, such as health status: unhealthy (db, redis)