Skip to content

Micrometer registries pin the application context - #50886

Merged
mhalbritter merged 2 commits into
spring-projects:4.0.xfrom
LordKay-sudo:gh-36737-meter-registry-global-cleanup
Jul 28, 2026
Merged

mhalbritter merged 2 commits into
spring-projects:4.0.xfrom
LordKay-sudo:gh-36737-meter-registry-global-cleanup

Conversation

@LordKay-sudo

Copy link
Copy Markdown
Contributor

Summary

Related to spring-framework#36737.

  • Fix MeterRegistryCloser so it tracks registries added to Metrics.globalRegistry at registration time instead of snapshotting MeterRegistry beans in its constructor (which often runs before registries exist).
  • On ContextClosedEvent, remove tracked registries from the global registry and close them.
  • Add DisableGlobalMeterRegistryContextCustomizerFactory so tests default management.metrics.use-global-registry=false when 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

@mhalbritter

mhalbritter commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

@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.

LordKay-sudo and others added 2 commits July 28, 2026 10:14
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>
@mhalbritter mhalbritter added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 28, 2026
@mhalbritter mhalbritter changed the title Prevent Micrometer global registry from pinning application contexts Micrometer registries pin the application context Jul 28, 2026
@mhalbritter mhalbritter added this to the 4.0.8 milestone Jul 28, 2026
@mhalbritter
mhalbritter changed the base branch from main to 4.0.x July 28, 2026 08:16
@mhalbritter
mhalbritter force-pushed the gh-36737-meter-registry-global-cleanup branch from c61ff15 to 19153b6 Compare July 28, 2026 08:16
@mhalbritter
mhalbritter merged commit e1a1e1b into spring-projects:4.0.x Jul 28, 2026
1 check failed
@mhalbritter

Copy link
Copy Markdown
Contributor

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 main (Spring Boot 4.2.x)? Thanks!

@LordKay-sudo

Copy link
Copy Markdown
Contributor Author

@mhalbritter Thanks. Opened #51142 against main with only the disable-global-registry-in-tests customizer.

@LordKay-sudo
LordKay-sudo deleted the gh-36737-meter-registry-global-cleanup branch July 28, 2026 13:59
@mhalbritter

Copy link
Copy Markdown
Contributor

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants