Kealth is a health check library for external dependencies in Kotlin
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<dependency>
<groupId>io.github.marioalvial</groupId>
<artifactId>kealth</artifactId>
<version>${kealth-version}</version>
</dependency>
repositories {
mavenCentral()
}
dependencies {
implementation "io.github.marioalvial:kealth:$kealth_version"
}
- Create your component:
class HealthComponentA : HealthComponent() {
override val name = "component A"
override fun doHealthCheck(): HealthStatus {
val result = doHealthCheckCallToComponentAService()
return if(result) HealthStatus.HEALTHY else HealthStatus.UNHEALTHY
}
override fun handleFailure(throwable: Throwable) {
sendAlert()
}
}
- Instantiate
HealthAggregator
:
val aggregator = HealthAggregator(listOf(HealthComponentA()))
- Execute
aggregate()
:
val componentMap: Map<String, HealthInfo> = aggregator.aggregate()
Example of componentMap
serialized to json:
{
"component-A": {
"status": "HEALTHY",
"duration": 1500
},
"component-B": {
"status": "UNHEALTHY",
"duration": 400
}
}
handleFailure()
will be trigger only if doHealthCheck()
call throws exception.
When aggregator.aggregate()
is called it will execute health()
of each component in parallel and create a map with the component's name as key and health info as value.
If the doHealthCheck()
throws exception the component will trigger the handleFailure()
method asynchronous with the exception that was thrown.
Test Coverage configured on CodeCov. Checkout the test coverage here.
Continuous Integration is configured on CircleCI. Checkout the continuous integration here
./gradlew test