javaspring-bootspring-boot-actuatorresilience4j

spring boot actuator health endpoint + dynamic resilience4j circuit breakers


I have a spring boot app, which uses resilience4j AOP-based @CircuitBreakers.

Now I would like to make the circuit breakers' information available in the /actuator/health endpoint, but I'm not seeing the details.circuitBtreakers objects described in the docs in the JSON output.

What am I doing wrong?


By comparison, getting dynamic cache information to appear in the /actuator/metrics endpoint required a small amount of custom wiring, but this is well documented. I wonder if there is a similar trick that I can apply for dynamically defined @CircuitBreakers to be registerd with the /actuator/health endpoint.

MyService.java:

@Service
public class MyService {
    @Autowired
    private CacheManager cacheManager;
    @Autowired
    private CacheMetricsRegistrar cacheMetricsRegistrar;

    @PostConstruct
    public void postConstruct() {
        // On-the-fly defined (annotation-based) caches are not auto-registered with micrometer metrics.
        final Cache cache = cacheManager.getCache("myCache");
        cacheMetricsRegistrar.bindCacheToRegistry(cache);
    }

    @CircuitBreaker(name = "myCB", fallbackMethod = "fallbackCallAnApi")
    public String callAnApi() throws RestClientException {
        // ...
    }

    @Cacheable("myCache")
    public String getSomethingCacheable() {
        // ...
    }
}

application.properties:

resilience4j.circuitbreaker.configs.default.registerHealthIndicator=true
management.endpoints.web.expose=health,metrics
management.endpoints.web.exposure.include=health,metrics
management.endpoint.health.enabled=true
management.endpoint.metrics.enabled=true
management.metrics.enable.resilience4j.circuitbreaker.calls=true
management.health.circuitbreakers.enabled=true

Solution

  • Dynamically registering CircuitBreakers for the HealthIndicator endpoint doesn't work at the moment. Unfortunately you have to configure them:

    resilience4j.circuitbreaker:
        configs:
            default:
                registerHealthIndicator: true
        instances:
            myCB:
                baseConfig: default
    

    You could say it's a bug.

    https://github.com/resilience4j/resilience4j/blob/master/resilience4j-spring-boot2/src/main/java/io/github/resilience4j/circuitbreaker/monitoring/health/CircuitBreakersHealthIndicator.java#L99-L102