Health Status not propagated to Eureka
We have a Spring Boot App registered to a Eureka Server (Brixton Release). Everything is working well but we have a problem with the Healthcheck (we have a dependency to the actuators). Although we set eureka.client.healthcheck.enabled to true the correct Health Status is not propagated to Eureka, if the Oracle Database we are using is going offline. If The Database goes down the /health Indicator says correctly DOWN but in Eureka it stays UP. The strange thing is if we add a simple HealthIndicator Implementation which always returns UP then the Status is correctly reported to Eureka. Are we missing some configuration settings or is this behavior correct?
I can't explain that. Can you create a simple sample that reproduces the problem? Debugging it would probably tell you why it's behaving that way.
You can use a very simple Setup.
Just start an Eureka Server.
Create a simple spring-boot Application with @EnableEurekaClient and add a dependency to spring-starter-jdbc with a h2 db.
Settings application.yml:
spring:
datasource:
test-on-borrow: true
url: jdbc:h2:tcp://localhost/~/test;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
eureka:
client:
healthcheck:
enabled: true
Start the h2 in standalone mode. Now Start the Boot App. It registers successfull to Eureka an propagates a Status UP to Eureka. But when you kill the h2 process the /health says correctly DOWN, but in Eureka it stays UP.
Now if you add the follwing class :
package com.example;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class AlwaysUpHealthIndicator implements HealthIndicator {
@Override
public Health health() {
return Health.up().build();
}
}
Everything works as expected.
Just a simple question. Have you imported spring-boot-starter-security in your dependencies ? If so, the /health end point will limit itself to a UP or DOWN status if you access the endpoint without pre authorized headers.
in the simple example i didn't use spring-boot-starter-security. I see all the infos at the /health endpoint.
The reason it works when you add a HealthIndicator bean is because it is @ConditionalOnBean(HealthIndicator.class). Without the HealthIndicator bean it is not actually enabled.