Interface HealthIndicator

All Known Implementing Classes:
AgentHealthIndicator, LLMHealthIndicator, ResourceHealthIndicator
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface HealthIndicator
Interface for components that can report their health status.

Implementations should check the component's health and return a HealthCheckResult indicating the current status.

Example implementation:


 public class DatabaseHealthIndicator implements HealthIndicator {

     private final DataSource dataSource;

     @Override
     public String getName() {
         return "database";
     }

     @Override
     public HealthCheckResult check() {
         try (Connection conn = dataSource.getConnection()) {
             if (conn.isValid(5)) {
                 return HealthCheckResult.up()
                     .withDetail("database", "connected");
             }
             return HealthCheckResult.down("Connection invalid");
         } catch (SQLException e) {
             return HealthCheckResult.down(e);
         }
     }
 }
 
See Also:
  • Field Details

    • DEFAULT_TIMEOUT

      static final Duration DEFAULT_TIMEOUT
      Default timeout for health checks.
  • Method Details

    • check

      Performs the health check and returns the result.

      Implementations should:

      • Return quickly (under 10 seconds)
      • Not throw exceptions (return DOWN status instead)
      • Include relevant details in the result
      Returns:
      the health check result
    • getName

      default String getName()
      Gets the name of this health indicator.

      Default implementation returns the simple class name.

      Returns:
      the indicator name
    • getTimeout

      default Duration getTimeout()
      Gets the timeout for this health check.
      Returns:
      the timeout duration
    • checkAsync

      default CompletableFuture<HealthCheckResult> checkAsync()
      Performs the health check asynchronously.
      Returns:
      a future containing the health check result
    • checkWithTimeout

      default HealthCheckResult checkWithTimeout(Duration timeout)
      Performs the health check with a timeout.
      Parameters:
      timeout - the maximum time to wait
      Returns:
      the health check result, or UNKNOWN if timeout exceeded
    • of

      static HealthIndicator of(String name, BooleanSupplier healthCheck)
      Creates a simple health indicator from a boolean supplier.
      Parameters:
      name - the indicator name
      healthCheck - a supplier that returns true if healthy
      Returns:
      a health indicator
    • of

      static HealthIndicator of(String name, Supplier<HealthCheckResult> healthCheck)
      Creates a health indicator from a supplier.
      Parameters:
      name - the indicator name
      healthCheck - a supplier that returns the result
      Returns:
      a health indicator