Search code examples
micronautkubernetes-health-check

Micronaut liveness always unknown


I'm currently trying to add liveness and readiness endpoints to my service to deploy it on k8s.

I'm using the latest micronaut release (2.5.4), and having the following setup:

application.yml:

micronaut:
  application:
    name: sandbox

endpoints:
  health:
    enabled: true
    sensitive: false
    details-visible: ANONYMOUS

build.gradle:

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.4.32"
    id("org.jetbrains.kotlin.kapt") version "1.4.32"
    id("com.github.johnrengelman.shadow") version "7.0.0"
    id("io.micronaut.application") version "1.5.0"
    id("org.jetbrains.kotlin.plugin.allopen") version "1.4.32"
}

version = "0.1"
group = "com.example"

repositories {
    mavenCentral()
}

micronaut {
    runtime("netty")
    testRuntime("junit5")
    processing {
        incremental(true)
        annotations("com.example.*")
    }
}

dependencies {
    implementation("io.micronaut:micronaut-http-client")
    implementation("io.micronaut:micronaut-management")
    implementation("io.micronaut:micronaut-runtime")
    implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
    implementation("javax.annotation:javax.annotation-api")
    implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
    runtimeOnly("ch.qos.logback:logback-classic")
    implementation("io.micronaut:micronaut-validation")

    runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")

}


application {
    mainClass.set("com.example.ApplicationKt")
}
java {
    sourceCompatibility = JavaVersion.toVersion("11")
}

tasks {
    compileKotlin {
        kotlinOptions {
            jvmTarget = "11"
        }
    }
    compileTestKotlin {
        kotlinOptions {
            jvmTarget = "11"
        }
    }


}

Whenever I'm hitting the endpoint localhost:8080/health/liveness the response I'm getting is:

{"name":"sandbox","status":"UNKNOWN"}

However, when I'm calling localhost:8080/health/readiness I'm getting correct response:

{"name":"sandbox","status":"UP","details":{"compositeDiscoveryClient()":{"name":"sandbox","status":"UP"},"diskSpace":{"name":"sandbox","status":"UP","details":{"total":499963174912,"free":384382533632,"threshold":10485760}},"service":{"name":"sandbox","status":"UP"}}}

It seems that I'm missing something but I couldn't find anything in Micronaut documentation about this...


Solution

  • With the help in the comments, I've managed to solve the issue.

    To make the liveness work you need to add a Liveness implementation in form similar to the following:

    @Singleton
    @Liveness
    class LivenessIndicator : HealthIndicator {
        override fun getResult(): Publisher<HealthResult> =
            Flowable.just(HealthResult.builder(LIVENESS_NAME).status(HealthStatus.UP).build())
    
        companion object {
            private const val LIVENESS_NAME = "liveness"
        }
    }