Fix Spring Boot 4 Micrometer auto-configuration and add actuator metrics smoke coverage#4672
Fix Spring Boot 4 Micrometer auto-configuration and add actuator metrics smoke coverage#4672xiang17 wants to merge 19 commits intomicrosoft:mainfrom
Conversation
…umentation for Spring Boot 4
… Boot 4 logging so the test can reach the intended Micrometer failure path. 2. making one small adjustment so the app boots with a local SimpleMeterRegistry and the test fails exactly on the missing AI metric behavior
…ame to org.springframework.boot.micrometer.metrics.autoconfigure.* (different module/package)
| return false; | ||
| } | ||
|
|
||
| @Environment(JAVA_17) |
There was a problem hiding this comment.
Spring Boot 4.0 requires Java 17 or later. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide
|
|
||
| @Bean | ||
| public MeterRegistry meterRegistry() { | ||
| return Metrics.globalRegistry; |
There was a problem hiding this comment.
I think returning Metrics.globalRegistry here bypasses the new Spring Boot 4 actuator auto-configuration path. MetricsInstrumentation already adds AzureMonitorMeterRegistry to the global registry, so this smoke test can stay green even if the PR's Boot 4 import hook never runs.
There was a problem hiding this comment.
you could try reverting your fix and re-running this smoke test to make sure it fails without your fix
|
do you have time to finalize this please? |
|
I fixed the smoke test so that in the first commit above (Update smoke test so that it misses the metrics when reverting the fix), the smoke test would fail because the code doesn't have the fix. Then after reapplying the fix in the next commit (Revert "revert fix") and the smoke test should pass, thus proving the smoke test can validate the fix. |
Match on counter name only so that a regression in tag -> property propagation surfaces as a clear assertion failure on the properties check in the test body rather than a waitForItems timeout.
The ai.smoke-test convention forces log4j-over-slf4j, jcl-over-slf4j, and jul-to-slf4j to 1.7.36. Spring Boot 4 can transitively pull these bridges, leaving them binary-incompatible with the slf4j-api 2.0.17 this module already forces. Re-force the bridges to 2.0.17 to match.
Fix #4577.
Spring Boot 4 moved Micrometer metrics auto-configuration classes from
org.springframework.boot.actuate.autoconfigure.metrics.*toorg.springframework.boot.micrometer.metrics.autoconfigure.*.Our Micrometer instrumentation was still keyed only to the Spring Boot 3 class
names, which meant the Azure Monitor meter registry auto-configuration was not
being inserted for Spring Boot 4 applications. As a result, custom Micrometer
metrics such as
demo.requests.totalcould be present locally but never reachApplication Insights.
This change updates the Micrometer instrumentation to support both Spring Boot 3
and Spring Boot 4 auto-configuration class names, and adds smoke coverage for
the Spring Boot 4 path.
Docs for reference
Old package summary, Spring Boot 3.5.8
https://javadoc.io/static/org.springframework.boot/spring-boot-actuator-autoconfigure/3.5.8/org/springframework/boot/actuate/autoconfigure/metrics/package-summary.html
This page explicitly says:
Package org.springframework.boot.actuate.autoconfigure.metrics
Auto-configuration for actuator metrics and Micrometer.
New package summary, Spring Boot 4.0.0
https://javadoc.io/static/org.springframework.boot/spring-boot-micrometer-metrics/4.0.0/org/springframework/boot/micrometer/metrics/autoconfigure/package-summary.html
This page explicitly says:
Package org.springframework.boot.micrometer.metrics.autoconfigure
Auto-configuration for metrics with Micrometer.
Suggested testing
./gradlew :smoke-tests:apps:ActuatorMetricsSpringBoot4:smokeTest --tests '*ActuatorMetricsSpringBoot4Test$Java21Test'./gradlew :smoke-tests:apps:Micrometer:smokeTest --tests "*MicrometerTest*"