Closed edwardsre closed 2 years ago
Ideally, the spring cloud starter's auto configuration would remove the metrics configuration and defer to the resilience4j auto configuration for metrics setup. That way, both blocking and reactive circuit breaker factories could be used and metrics would have a single shut off property using resilience4j.circuitbreaker.metrics.legacy.enabled=false
.
Using
spring-cloud-starter-circuitbreaker-reactor-resilience4j
with default settings is causing the circuit breaker meter volume to be 3 times the expected volume.Sample Build and run the spring-cloud-circuitbreaker-demo-reactive-resilience4j application in spring cloud samples.
http :8080 /delay/1
.Result: The count for the delay circuit breaker is 3 instead of 1.
Investigation:
I have found there are three places where the same event listeners are being registered which is causing the metrics to be reported three times for each circuit breaker call.
The first instance is
ReactiveResilience4JAutoConfiguration.MicrometerReactiveResilience4JCustomizerConfiguration
which usesTaggedCircuitBreakerMetrics
ininit()
method.The second instance is
Resilience4JAutoConfiguration.MicrometerResilience4JCustomizerConfiguration
which also usesTaggedCircuitBreakerMetrics
ininit()
method.While both of these use the correct reactive/non-reactive circuit breaker factory, both of them use the same underlying registry instance. At this point, the event listeners have been doubled.
The third set of event listeners comes from
org.springframework.cloud:spring-cloud-circuitbreaker-resilience4j
includingio.github.resilience4j:resilience4j-spring-boot2
where there is the auto-configuration classCircuitBreakerMetricsAutoConfiguration
. This creates aTaggedCircuitBreakerMetricsPublisher
which callsaddMetrics
and registers the third set of even listeners.All three of these can be controlled by the properties below, but by default, it is unexpected that the metric volume is 3 times what is expected.
This is how I have had to configure my application to get the meter counts to be correct.
spring.cloud.circuitbreaker.resilience4j.reactive.enabled=true
(disables all reactive circuit breaker auto configuration, including metrics)spring.cloud.circuitbreaker.resilience4j.blocking.enabled=false
(disables all blocking circuit breaker auto configuration, including metrics)resilience4j.circuitbreaker.metrics.legacy.enabled=false
(only disables metrics)If an application uses both blocking and reactive circuit breakers (i.e. servlet container using
spring-boot-starter-web
andspring-boot-starter-webflux
), the meter publishing would at least be doubled since the first two properties would have to be enabled.