There is some confusion online about whether health indicators contribute to the liveness / readiness probe status. Research below confirms that liveness / readiness probe status does not depend on the health indicators as long as these conditions (causing the health indicators failure) do not prevent application from starting.
https://spring.io/blog/2020/03/25/liveness-and-readiness-probes-with-spring-boot
You should carefully consider tying external state to Liveness or Readiness and this is why Spring Boot is not adding any by default. Each application and deployment is different, but we’re committed to providing guidance and adapt defaults with the help of the community - check out the "Checking external state with Kubernetes Probes" section in our reference documentation.
Looking in the code, the usages of LivenessState.CORRECT
are listed below:
- EventPublishingRunListener.started(ConfigurableApplicationContext, Duration) (org.springframework.boot.context.event)
- SpringApplicationRunListeners.started(ConfigurableApplicationContext, Duration) (org.springframework.boot)
- SpringApplication.run(String...) (org.springframework.boot)
- SpringApplication.run(Class[], String[]) (org.springframework.boot)
- SpringApplicationBuilder.run(String...) (org.springframework.boot.builder)
- SpringBootServletInitializer.run(SpringApplication) (org.springframework.boot.web.servlet.support)
- SpringApplication.run(String...) (org.springframework.boot)
- SpringApplicationRunListeners.started(ConfigurableApplicationContext, Duration) (org.springframework.boot)
Which confirms that application LivenessState.CORRECT
is published regardless of the custom health indicators as long
as these conditions do not prevent application from starting (i.e. Kafka, etc).
Similarly, the usage of ReadinessState.ACCEPTING_TRAFFIC
event publish are listed below:
- EventPublishingRunListener.ready(ConfigurableApplicationContext, Duration) (org.springframework.boot.context.event)
- SpringApplicationRunListeners.ready(ConfigurableApplicationContext, Duration) (org.springframework.boot)
- SpringApplication.run(String...) (org.springframework.boot)
- SpringApplication.run(Class[], String[]) (org.springframework.boot)
- SpringApplicationBuilder.run(String...) (org.springframework.boot.builder)
- SpringBootServletInitializer.run(SpringApplication) (org.springframework.boot.web.servlet.support)
- SpringApplication.run(String...) (org.springframework.boot)
- SpringApplicationRunListeners.ready(ConfigurableApplicationContext, Duration) (org.springframework.boot)
If debug
level logging is enabled for ApplicationAvailabilityBean
:
logging:
level:
org.springframework.boot.availability.ApplicationAvailabilityBean: DEBUG
Then you will see something similar to this locally:
15:24:35.509 [main] DEBUG o.s.b.a.ApplicationAvailabilityBean -- Application availability state LivenessState changed to CORRECT
15:24:35.512 [main] DEBUG o.s.b.a.ApplicationAvailabilityBean -- Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
right after the application is started.