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.
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncheck()Performs the health check and returns the result.default CompletableFuture<HealthCheckResult> Performs the health check asynchronously.default HealthCheckResultcheckWithTimeout(Duration timeout) Performs the health check with a timeout.default StringgetName()Gets the name of this health indicator.default DurationGets the timeout for this health check.static HealthIndicatorof(String name, BooleanSupplier healthCheck) Creates a simple health indicator from a boolean supplier.static HealthIndicatorof(String name, Supplier<HealthCheckResult> healthCheck) Creates a health indicator from a supplier.
-
Field Details
-
DEFAULT_TIMEOUT
Default timeout for health checks.
-
-
Method Details
-
check
HealthCheckResult 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
Gets the name of this health indicator.Default implementation returns the simple class name.
- Returns:
- the indicator name
-
getTimeout
Gets the timeout for this health check.- Returns:
- the timeout duration
-
checkAsync
Performs the health check asynchronously.- Returns:
- a future containing the health check result
-
checkWithTimeout
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
Creates a simple health indicator from a boolean supplier.- Parameters:
name- the indicator namehealthCheck- a supplier that returns true if healthy- Returns:
- a health indicator
-
of
Creates a health indicator from a supplier.- Parameters:
name- the indicator namehealthCheck- a supplier that returns the result- Returns:
- a health indicator
-