-
Notifications
You must be signed in to change notification settings - Fork 41k
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 |
…o v3.2.0 This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [nu.ndw.nls.geometry:nls-geometry](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | minor | `3.1.2` -> `3.2.0` | --- ### Release Notes <details> <summary>spring-projects/spring-boot (nu.ndw.nls.geometry:nls-geometry)</summary> ### [`v3.2.0`](https://github.com/spring-projects/spring-boot/releases/tag/v3.2.0) [Compare Source](spring-projects/spring-boot@v3.1.2...v3.2.0) #### ⭐ New Features - Auto-configure observations for RestClients [#​38500](spring-projects/spring-boot#38500) - Add support for Oracle Free, the replacement for Oracle XE, with Testcontainers and Docker Compose [#​38476](spring-projects/spring-boot#38476) - Provide dependency management for org.crac:crac [#​38378](spring-projects/spring-boot#38378) - Add new properties for Liquibase 4.24.0 [#​38274](spring-projects/spring-boot#38274) - Provide a way to create custom ApplicationContextFactory in SpringBootContextLoader [#​38205](spring-projects/spring-boot#38205) - Report friendly error when failing to find AOT initializer [#​38188](spring-projects/spring-boot#38188) #### 🐞 Bug Fixes - Annotation based ConditionalOnBean checks can cause early initialization of FactoryBeans [#​38507](spring-projects/spring-boot#38507) - CRaC restoration fails when Actuator's running on a separate port [#​38502](spring-projects/spring-boot#38502) - App that depends on Tomcat and on Jetty's websocket-server module fails to start with IllegalStateException: WebSocketComponents has not been created [#​38286](spring-projects/spring-boot#38286) - App fails to start with a NoSuchMethodError when using Flyway 10.0.0 [#​38268](spring-projects/spring-boot#38268) - MeterRegistry throws BeanCreationNotAllowedException on shutdown [#​38240](spring-projects/spring-boot#38240) - Resolution of productionRuntimeClasspath configuration may select the wrong variant and contain a dependency's source jar [#​38233](spring-projects/spring-boot#38233) - Docker JSON parsing fails on certain locales [#​38220](spring-projects/spring-boot#38220) - FileNotFoundException is thrown serving resources due to JarUrlConnection.getLastModified() returning zero [#​38204](spring-projects/spring-boot#38204) - Failed to extract parameter names exception thrown when binding with non-enumerable property source [#​38201](https://github.com/spring-projects/spring...
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: