-
Notifications
You must be signed in to change notification settings - Fork 210
Fix Spring Boot 4 Micrometer auto-configuration and add actuator metrics smoke coverage #4672
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
Open
xiang17
wants to merge
19
commits into
microsoft:main
Choose a base branch
from
xiang17:xiang17/SpringBoot4-ActuatorMetrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ba8e9d3
Created a new smoke test to validate Micrometer/ActuatorMetrics instr…
xiang17 becaf96
fixed the startup blocker: 1. adding module-local version forcing for…
xiang17 6f01b66
Fix the incompatible bug due to Spring Boot 4 metrics auto-config ren…
xiang17 5ea57a1
Add additional JDK versions for the smoke tests
xiang17 b304e77
Remove unused empty file
xiang17 7f04f1b
./gradlew spotlessApply
xiang17 827a7b1
Added Java 17 in smoke tests. Minimum supported Java version by Sprin…
xiang17 70c46a2
revert fix
xiang17 25be67b
Update smoke test so that it misses the metrics when reverting the fix
xiang17 ea12d34
Revert "revert fix"
xiang17 96f0726
add missed file for auto-config classes
xiang17 e413d43
simplify
trask d97cbfc
simplify
trask 5b3ec5d
comment
trask 8a6479f
comment
trask 767f2de
simplify
trask 9ff9ff8
comment
trask 500f934
Match ActuatorMetricsSpringBoot4 target metric on counter name only
trask 7537ec9
Force slf4j bridges to 2.x in ActuatorMetricsSpringBoot4
trask File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
smoke-tests/apps/ActuatorMetricsSpringBoot4/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import com.microsoft.applicationinsights.gradle.AiSmokeTestExtension | ||
|
|
||
| plugins { | ||
| id("ai.smoke-test") | ||
| id("org.springframework.boot") version "4.0.0" | ||
| } | ||
|
|
||
| // The ai.smoke-test convention plugin applies `resolutionStrategy.force` on every | ||
| // configuration to pin logback-classic to 1.2.12 and the slf4j bridges (slf4j-api, | ||
| // log4j-over-slf4j, jcl-over-slf4j, jul-to-slf4j) to 1.7.36 (needed by the older | ||
| // Spring Boot smoke-test apps). Spring Boot 4 requires logback 1.5.x and slf4j 2.x | ||
| // and fails at startup with AbstractMethodError against SB4's RootLogLevelConfigurator | ||
| // otherwise. Re-force the newer versions here to override the convention's force, | ||
| // including all slf4j bridges so they stay binary-compatible with slf4j-api 2.x. | ||
| configurations.configureEach { | ||
| resolutionStrategy.force( | ||
| "ch.qos.logback:logback-classic:1.5.21", | ||
| "ch.qos.logback:logback-core:1.5.21", | ||
| "org.slf4j:slf4j-api:2.0.17", | ||
| "org.slf4j:log4j-over-slf4j:2.0.17", | ||
| "org.slf4j:jcl-over-slf4j:2.0.17", | ||
| "org.slf4j:jul-to-slf4j:2.0.17" | ||
| ) | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation("org.springframework.boot:spring-boot-starter-web:4.0.0") | ||
| implementation("org.springframework.boot:spring-boot-starter-actuator:4.0.0") | ||
| implementation("org.springframework.boot:spring-boot-starter-micrometer-metrics:4.0.0") | ||
| } | ||
|
|
||
| val aiSmokeTest = extensions.getByType(AiSmokeTestExtension::class) | ||
| aiSmokeTest.testAppArtifactDir.set(tasks.bootJar.flatMap { it.destinationDirectory }) | ||
| aiSmokeTest.testAppArtifactFilename.set(tasks.bootJar.flatMap { it.archiveFileName }) |
15 changes: 15 additions & 0 deletions
15
...ringBoot4/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.smoketestapp; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class SpringBootApp { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(SpringBootApp.class, args); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...ingBoot4/src/main/java/com/microsoft/applicationinsights/smoketestapp/TestController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.smoketestapp; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| public class TestController { | ||
|
|
||
| private final Counter counter; | ||
|
|
||
| public TestController(MeterRegistry meterRegistry) { | ||
| this.counter = | ||
| Counter.builder("demo.requests.total").tag("endpoint", "test").register(meterRegistry); | ||
| } | ||
|
|
||
| @GetMapping("/") | ||
| public String root() { | ||
| return "OK"; | ||
| } | ||
|
|
||
| @GetMapping("/test") | ||
| public String test() { | ||
| counter.increment(); | ||
| return "OK!"; | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
...Test/java/com/microsoft/applicationinsights/smoketest/ActuatorMetricsSpringBoot4Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.smoketest; | ||
|
|
||
| import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_17; | ||
| import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_17_OPENJ9; | ||
| import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_21; | ||
| import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_21_OPENJ9; | ||
| import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_25; | ||
| import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.JAVA_25_OPENJ9; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.microsoft.applicationinsights.smoketest.schemav2.Data; | ||
| import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; | ||
| import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; | ||
| import com.microsoft.applicationinsights.smoketest.schemav2.MetricData; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| @UseAgent | ||
| abstract class ActuatorMetricsSpringBoot4Test { | ||
|
|
||
| @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); | ||
|
|
||
| @Test | ||
| @TargetUri("/test") | ||
| void shouldCaptureCustomMetricRegisteredOnSpringMeterRegistry() throws Exception { | ||
| testing.getTelemetry(0); | ||
|
|
||
| List<Envelope> metricItems = | ||
| testing.mockedIngestion.waitForItems( | ||
| ActuatorMetricsSpringBoot4Test::isTargetMetric, 1, 20, TimeUnit.SECONDS); | ||
|
|
||
| MetricData data = (MetricData) ((Data<?>) metricItems.get(0).getData()).getBaseData(); | ||
| List<DataPoint> points = data.getMetrics(); | ||
|
|
||
| assertThat(points) | ||
| .anySatisfy(point -> assertThat(point.getName()).isEqualTo("demo_requests_total")); | ||
| assertThat(data.getProperties()).containsEntry("endpoint", "test"); | ||
| } | ||
|
|
||
| static boolean isTargetMetric(Envelope input) { | ||
| if (!input.getData().getBaseType().equals("MetricData")) { | ||
| return false; | ||
| } | ||
| MetricData data = (MetricData) ((Data<?>) input.getData()).getBaseData(); | ||
| for (DataPoint point : data.getMetrics()) { | ||
| if ("demo_requests_total".equals(point.getName()) && point.getValue() >= 1) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Environment(JAVA_17) | ||
| static class Java17Test extends ActuatorMetricsSpringBoot4Test {} | ||
|
|
||
| @Environment(JAVA_17_OPENJ9) | ||
| static class Java17OpenJ9Test extends ActuatorMetricsSpringBoot4Test {} | ||
|
|
||
| @Environment(JAVA_21) | ||
| static class Java21Test extends ActuatorMetricsSpringBoot4Test {} | ||
|
|
||
| @Environment(JAVA_21_OPENJ9) | ||
| static class Java21OpenJ9Test extends ActuatorMetricsSpringBoot4Test {} | ||
|
|
||
| @Environment(JAVA_25) | ||
| static class Java25Test extends ActuatorMetricsSpringBoot4Test {} | ||
|
|
||
| @Environment(JAVA_25_OPENJ9) | ||
| static class Java25OpenJ9Test extends ActuatorMetricsSpringBoot4Test {} | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
smoke-tests/apps/ActuatorMetricsSpringBoot4/src/smokeTest/resources/applicationinsights.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "role": { | ||
| "name": "testrolename", | ||
| "instance": "testroleinstance" | ||
| }, | ||
| "sampling": { | ||
| "percentage": 100 | ||
| }, | ||
| "metricIntervalSeconds": 5 | ||
| } |
11 changes: 11 additions & 0 deletions
11
smoke-tests/apps/ActuatorMetricsSpringBoot4/src/smokeTest/resources/logback-test.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <configuration> | ||
| <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <encoder> | ||
| <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> | ||
| </encoder> | ||
| </appender> | ||
| <root level="warn"> | ||
| <appender-ref ref="CONSOLE"/> | ||
| </root> | ||
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spring Boot 4.0 requires Java 17 or later. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Migration-Guide