-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
First of all, maybe this is intentional and Boot should do what it does today but maybe the behavior of registering MeterBinder and CompositeMeterRegistry have some inconsistencies (maybe MeterFilter too).
In the latest GA version of Boot (3.3.3), if I create a custom registry bean, let's say a SimpleMeterRegistry in addition to what Boot creates, (let's say PrometheusMeterRegistry), binders are bound once, and the registry that will be injected if I ask for a MeterRegistry is AutoConfiguredCompositeMeterRegistry (what binders bound to).
@Bean
SimpleMeterRegistry simpleMeterRegistry() {
return new SimpleMeterRegistry();
}
@Bean
MeterBinder debuggingHelperBinder() {
return registry -> {
System.out.println("Binder bound to " + registry);
registry.counter("test").increment();
};
}This behavior looks expected to me.
If I also create a CompositeMeterRegistry on top of the previous scenario (so I will have 1. Composite, 2. Simple, 3. Prometheus) Boot will create an AutoConfiguredCompositeMeterRegistry where all three registries are registered (expected) but it will also bind every binders to two registries: to AutoConfiguredCompositeMeterRegistry (expected) and to the CompositeMeterRegistry that I created (unexpected?).
@Bean
SimpleMeterRegistry simpleMeterRegistry() {
return new SimpleMeterRegistry();
}
@Bean
CompositeMeterRegistry compositeMR() {
CompositeMeterRegistry compositeMeterRegistry = new CompositeMeterRegistry();
compositeMeterRegistry.add(new SimpleMeterRegistry());
return compositeMeterRegistry;
}
@Bean
MeterBinder debuggingHelperBinder() {
return registry -> {
System.out.println("Binder bound to " + registry);
registry.counter("test").increment();
};
}This will result in the following structure:
AutoConfiguredCompositeMeterRegistry
PrometheusMeterRegistry
SimpleMeterRegistry
CompositeMeterRegistry
SimpleMeterRegistry
Should there be two composites or should Boot back off and use the user-created composite to register other registries? If so, should binders be bound to all the composites?