New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MeterRegistry throws BeanCreationNotAllowedException on shutdown #38240
Comments
Trying to use "depends on" configuration is turning out to be quite hard. The I'm wondering if the earlier idea floated in #19557 (comment) might be a better solution. It feels like we should close all The following seems to prevent the exception: @Bean
MeterRegistryLifecycle meterRegistryLifecycle(ObjectProvider<MeterRegistry> meterRegistries) {
return new MeterRegistryLifecycle(meterRegistries);
} private static class MeterRegistryLifecycle implements SmartLifecycle {
private volatile boolean running;
private final List<MeterRegistry> meterRegistries;
MeterRegistryLifecycle(ObjectProvider<MeterRegistry> meterRegistries) {
this.meterRegistries = meterRegistries.orderedStream().toList();
}
@Override
public void start() {
this.running = true;
}
@Override
public void stop() {
this.running = false;
meterRegistries.forEach(MeterRegistry::close);
}
@Override
public boolean isRunning() {
return this.running;
}
} |
Configuring all |
We talked about this today as team and decided that we'd like to try the |
As pointed out by @shakuzen, the lifecycle approach may not play nicely with coordinated restore at checkpoint. When the checkpoint is taken, lifecycles will be stopped. This will result in all of the meter registries being closed. With nothing to re-open the registries (and no API that even makes that possible) they'll remain closed upon restore and no more metrics will be published. |
Something like this works (at least in the example, not sure if it works on every occasion): @Bean
MicrometerRegistryCloser micrometerRegistryCloser(ObjectProvider<MeterRegistry> meterRegistries) {
return new MicrometerRegistryCloser(meterRegistries.orderedStream().toList());
}
private static class MicrometerRegistryCloser implements DisposableBean {
private final List<MeterRegistry> meterRegistries;
private MicrometerRegistryCloser(List<MeterRegistry> meterRegistries) {
this.meterRegistries = meterRegistries;
}
@Override
public void destroy() {
for (MeterRegistry meterRegistry : this.meterRegistries) {
if (!meterRegistry.isClosed()) {
meterRegistry.close();
}
}
}
} |
And this would work, too: private static class MicrometerRegistryCloser implements ApplicationListener<ContextClosedEvent> {
private final List<MeterRegistry> meterRegistries;
private MicrometerRegistryCloser(List<MeterRegistry> meterRegistries) {
this.meterRegistries = meterRegistries;
}
@Override
public void onApplicationEvent(ContextClosedEvent event) {
for (MeterRegistry meterRegistry : this.meterRegistries) {
if (!meterRegistry.isClosed()) {
meterRegistry.close();
}
}
}
} Looking at |
I prefer using |
We talked about it in our meeting and decided to go with the |
We use Micrometer with NewRelic in our Spring Boot 3.1.5 applications.
After migration to the newest Spring Boot we noticed that following WARN log always appears during application shutdown:
The exception behind above log looks like:
App is integrated with NewRelic agent - i checked that mentioned exception is triggered when:
Please note that similar bug for older Spring Boot 2.2 version was reported under #19557. I've reproduced reported bug: https://github.com/wojciechkedziora/spring-boot-3-19557 (check this comment for more details).
The text was updated successfully, but these errors were encountered: