Micrometer registries pin the application context - #50886
mhalbritter merged 2 commits into
Conversation
|
@LordKay-sudo no need to deal with the formatting changes, i already have the polish commit locally. Note to myself: This changes the behavior of the global registry in tests: before that PR, the global registry is there, after that PR it's switched off by default. This is an observable change, not sure we should do that in 4.0.x or 4.2.x. |
Track meter registries added to Metrics.globalRegistry and remove them on context close. Disable use of the global registry in tests by default to avoid pinning cached test contexts. See spring-projectsgh-50886 Signed-off-by: LordKay-sudo <lkandiro@gmail.com>
c61ff15 to
19153b6
Compare
|
I had to revert the changes for the tests - we're targeting 4.0.x with that fix, and disabling the global registry in tests is too much of a change in a patch release. Could you please submit the "disable global registry in tests" changes as a new PR, so we can merge that into |
|
@mhalbritter Thanks. Opened #51142 against main with only the disable-global-registry-in-tests customizer. |
|
Thank you. |
Summary
Related to spring-framework#36737.
MeterRegistryCloserso it tracks registries added toMetrics.globalRegistryat registration time instead of snapshottingMeterRegistrybeans in its constructor (which often runs before registries exist).ContextClosedEvent, remove tracked registries from the global registry and close them.DisableGlobalMeterRegistryContextCustomizerFactoryso tests defaultmanagement.metrics.use-global-registry=falsewhen not explicitly configured, mirroring the existing Reactor global-resources customizer and preventing cached test contexts from being pinned via Micrometer.Test plan
./gradlew :module:spring-boot-micrometer-metrics:test --tests MeterRegistryPostProcessorTests./gradlew :core:spring-boot-test:test --tests DisableGlobalMeterRegistryContextCustomizerFactoryTests