Move WebMvc observation auto-config into spring-boot-webmvc
This commit is contained in:
committed by
Phillip Webb
parent
46a5ea0ee7
commit
9c634d2fb0
@@ -16,7 +16,6 @@ org.springframework.boot.actuate.autoconfigure.management.ThreadDumpEndpointAuto
|
||||
org.springframework.boot.actuate.autoconfigure.metrics.data.RepositoryMetricsAutoConfiguration
|
||||
org.springframework.boot.actuate.autoconfigure.metrics.task.TaskExecutorMetricsAutoConfiguration
|
||||
org.springframework.boot.actuate.autoconfigure.observability.ObservabilityAutoConfiguration
|
||||
org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration
|
||||
org.springframework.boot.actuate.autoconfigure.sbom.SbomEndpointAutoConfiguration
|
||||
org.springframework.boot.actuate.autoconfigure.scheduling.ScheduledTasksEndpointAutoConfiguration
|
||||
org.springframework.boot.actuate.autoconfigure.scheduling.ScheduledTasksObservabilityAutoConfiguration
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.observability.ObservabilityAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.observation.web.servlet.WebMvcObservationAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration;
|
||||
@@ -57,6 +56,7 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.boot.webflux.observation.autoconfigure.WebFluxObservationAutoConfiguration;
|
||||
import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.webmvc.observation.autoconfigure.WebMvcObservationAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.metrics.web;
|
||||
|
||||
import io.micrometer.core.annotation.Timed;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Test controller used by metrics tests.
|
||||
*
|
||||
* @author Dmytro Nosan
|
||||
* @author Stephane Nicoll
|
||||
* @author Chanhyeong LEE
|
||||
*/
|
||||
@RestController
|
||||
public class TestController {
|
||||
|
||||
@GetMapping("test0")
|
||||
public String test0() {
|
||||
return "test0";
|
||||
}
|
||||
|
||||
@GetMapping("test1")
|
||||
public String test1() {
|
||||
return "test1";
|
||||
}
|
||||
|
||||
@GetMapping("test2")
|
||||
public String test2() {
|
||||
return "test2";
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("test3")
|
||||
public String test3() {
|
||||
return "test3";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,8 @@ dependencies {
|
||||
|
||||
optional(project(":spring-boot-project:spring-boot-actuator-autoconfigure"))
|
||||
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
|
||||
optional(project(":spring-boot-project:spring-boot-metrics"))
|
||||
optional(project(":spring-boot-project:spring-boot-micrometer-observation"))
|
||||
optional(project(":spring-boot-project:spring-boot-tomcat"))
|
||||
optional(project(":spring-boot-project:spring-boot-undertow"))
|
||||
optional(project(":spring-boot-project:spring-boot-validation"))
|
||||
@@ -39,6 +41,7 @@ dependencies {
|
||||
testImplementation(project(":spring-boot-project:spring-boot-web-server-test"))
|
||||
testImplementation(testFixtures(project(":spring-boot-project:spring-boot-actuator-autoconfigure")))
|
||||
testImplementation(testFixtures(project(":spring-boot-project:spring-boot-web-server")))
|
||||
testImplementation("io.micrometer:micrometer-observation-test")
|
||||
testImplementation("jakarta.servlet:jakarta.servlet-api")
|
||||
testImplementation("org.aspectj:aspectjweaver")
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.observation.web.servlet;
|
||||
package org.springframework.boot.webmvc.observation.autoconfigure;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.config.MeterFilter;
|
||||
@@ -31,11 +31,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingFilt
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.metrics.OnlyOnceLoggingDenyMeterFilter;
|
||||
import org.springframework.boot.metrics.autoconfigure.CompositeMeterRegistryAutoConfiguration;
|
||||
import org.springframework.boot.metrics.autoconfigure.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.metrics.autoconfigure.MetricsProperties;
|
||||
import org.springframework.boot.metrics.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration;
|
||||
import org.springframework.boot.micrometer.observation.autoconfigure.ObservationAutoConfiguration;
|
||||
import org.springframework.boot.micrometer.observation.autoconfigure.ObservationProperties;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -54,10 +50,13 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
* @author Brian Clozel
|
||||
* @author Jon Schneider
|
||||
* @author Dmytro Nosan
|
||||
* @since 3.0.0
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@AutoConfiguration(after = { MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class,
|
||||
SimpleMetricsExportAutoConfiguration.class, ObservationAutoConfiguration.class })
|
||||
@AutoConfiguration(
|
||||
afterName = { "org.springframework.boot.metrics.autoconfigure.CompositeMeterRegistryAutoConfiguration",
|
||||
"org.springframework.boot.metrics.autoconfigure.MetricsAutoConfiguration",
|
||||
"org.springframework.boot.metrics.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration",
|
||||
"org.springframework.boot.micrometer.observation.autoconfigure.ObservationAutoConfiguration" })
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
||||
@ConditionalOnClass({ DispatcherServlet.class, Observation.class })
|
||||
@ConditionalOnBean(ObservationRegistry.class)
|
||||
@@ -17,4 +17,4 @@
|
||||
/**
|
||||
* Auto-configuration for Spring MVC observation support.
|
||||
*/
|
||||
package org.springframework.boot.actuate.autoconfigure.observation.web.servlet;
|
||||
package org.springframework.boot.webmvc.observation.autoconfigure;
|
||||
@@ -2,3 +2,4 @@ org.springframework.boot.webmvc.actuate.autoconfigure.health.WebMvcHealthEndpoin
|
||||
org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration
|
||||
org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration
|
||||
org.springframework.boot.webmvc.autoconfigure.error.ErrorMvcAutoConfiguration
|
||||
org.springframework.boot.webmvc.observation.autoconfigure.WebMvcObservationAutoConfiguration
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.observation.web.servlet;
|
||||
package org.springframework.boot.webmvc.observation.autoconfigure;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler;
|
||||
import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler.IgnoredMeters;
|
||||
import io.micrometer.core.instrument.observation.MeterObservationHandler;
|
||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||
import io.micrometer.observation.Observation.Context;
|
||||
import io.micrometer.observation.tck.TestObservationRegistry;
|
||||
import jakarta.servlet.DispatcherType;
|
||||
@@ -29,8 +30,6 @@ import jakarta.servlet.Filter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.web.TestController;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.metrics.autoconfigure.MetricsAutoConfiguration;
|
||||
import org.springframework.boot.micrometer.observation.autoconfigure.ObservationAutoConfiguration;
|
||||
@@ -45,6 +44,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.server.observation.DefaultServerRequestObservationConvention;
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.filter.ServerHttpObservationFilter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -63,9 +64,9 @@ import static org.mockito.Mockito.mock;
|
||||
class WebMvcObservationAutoConfigurationTests {
|
||||
|
||||
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||
.with(MetricsRun.simple())
|
||||
.withConfiguration(AutoConfigurations.of(ObservationAutoConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(WebMvcObservationAutoConfiguration.class));
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(ObservationAutoConfiguration.class, WebMvcObservationAutoConfiguration.class))
|
||||
.withBean(SimpleMeterRegistry.class);
|
||||
|
||||
@Test
|
||||
void backsOffWhenObservationRegistryIsMissing() {
|
||||
@@ -251,4 +252,24 @@ class WebMvcObservationAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@RestController
|
||||
static class TestController {
|
||||
|
||||
@GetMapping("test0")
|
||||
String test0() {
|
||||
return "test0";
|
||||
}
|
||||
|
||||
@GetMapping("test1")
|
||||
String test1() {
|
||||
return "test1";
|
||||
}
|
||||
|
||||
@GetMapping("test2")
|
||||
String test2() {
|
||||
return "test2";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user