-
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
7
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
7 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 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
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
| import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
|
|
||
| plugins { | ||
| id("ai.smoke-test-jar") | ||
| } | ||
|
|
||
| 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" | ||
| ) | ||
| } | ||
|
|
||
| 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") | ||
| } | ||
|
|
||
| tasks.named<ShadowJar>("shadowJar") { | ||
| append("META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports") | ||
| append("META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports") | ||
| } |
30 changes: 30 additions & 0 deletions
30
...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,30 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.microsoft.applicationinsights.smoketestapp; | ||
|
|
||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import io.micrometer.core.instrument.Metrics; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.boot.tomcat.servlet.TomcatServletWebServerFactory; | ||
| import org.springframework.boot.web.server.servlet.ServletWebServerFactory; | ||
| import org.springframework.context.annotation.Bean; | ||
|
|
||
| @SpringBootApplication | ||
| public class SpringBootApp { | ||
|
|
||
| @Bean | ||
| public ServletWebServerFactory servletWebServerFactory() { | ||
| return new TomcatServletWebServerFactory(); | ||
| } | ||
|
|
||
| @Bean | ||
| public MeterRegistry meterRegistry() { | ||
| return Metrics.globalRegistry; | ||
| } | ||
|
|
||
| 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!"; | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
...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,78 @@ | ||
| // 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(); | ||
| if (!"test".equals(data.getProperties().get("endpoint"))) { | ||
| return false; | ||
| } | ||
| 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