Custom Health Indicator for multiple instances of a Spring Boot Application

802 Views Asked by At

I have a Spring Boot (2.3.3) application which is deployed on PCF and it has 5 instances running.

For monitoring the health of this application, I added the custom health indicator where I implemented/override the ReactiveHealthIndicator of actuator package. The health() method calls a session service to tell that whether an instance is up or down after certain count.

The issue is that, even if one instance is going down, the PCF healthcheck bring down all the instances and restarts.

How I can make sure that the PCF healthcheck restart only those instance which is down and not all the instances.

My custom health indicator:

    @Component @Slf4j @ConditionalOnProperty(
            value = "app.custom.health.enabled",
            havingValue = "true",
            matchIfMissing = true) 
public class MyCustomHealthIndicator implements ReactiveHealthIndicator {
    
        private MyAsyncSessionHealthCheck myAsyncSessionHealthCheck;
    
        public MyCustomHealthIndicator(MyAsyncSessionHealthCheck myAsyncSessionHealthCheck) {
            this.myAsyncSessionHealthCheck = myAsyncSessionHealthCheck;
            log.info("Using Custom health indicator.");
        }
    
        @Override
        public Mono<Health> health() {
            Health health = Health.up().build();
    
            // Fire and forget async health check on session
            myAsyncSessionHealthCheck.checkSessionHealth();
    
            // Check counter and fail if greater than max
            if (myAsyncSessionHealthCheck.checkForSessionFailure()) {
                log.error("Health Down because of session service check failed.");
                health = Health.down().withDetail("REASON", "Session service failed.").build();
            }
            return Mono.just(health);
        } }
0

There are 0 best solutions below