Composable health check framework with readiness and liveness probes
implementation com.philiprehberger:healthcheckComposable health check framework with readiness and liveness probes.
implementation("com.philiprehberger:healthcheck:0.2.0")
<dependency>
<groupId>com.philiprehberger</groupId>
<artifactId>healthcheck</artifactId>
<version>0.2.0</version>
</dependency>
import com.philiprehberger.healthcheck.*
val health = healthCheck {
check("database") { dataSource.connection.use { it.isValid(2) } }
check("cache", critical = false) { redis.ping() == "PONG" }
}
val report = health.check()
report.status // UP
report.isHealthy() // true
report.toJson() // {"status":"UP",...}
Non-critical check failures result in DEGRADED status instead of DOWN:
val hc = healthCheck {
check("database", critical = true) { checkDb() }
check("cache", critical = false) { checkCache() } // Failure = DEGRADED, not DOWN
}
val report = hc.check()
// report.status = DEGRADED if only cache fails
val map = report.toMap()
// {"status": "UP", "checks": [...], "duration": "..."}
| Function / Class | Description |
|---|---|
healthCheck { } | Build a health checker |
check(name, critical, timeout) { Boolean } | Define a health check |
HealthChecker.check() | Run all checks, return HealthReport |
HealthReport.isHealthy() | Check overall status |
HealthReport.toJson() | JSON output |
HealthStatus | UP or DOWN |
HealthStatus.DEGRADED | Intermediate status for non-critical failures |
HealthReport.toMap() | Export report as a Map for flexible serialization |
./gradlew test
./gradlew build
If you find this project useful: