From b645a3bcd11c15a429774fa416c652ce497fa6a8 Mon Sep 17 00:00:00 2001 From: Colin Harrington Date: Thu, 16 Mar 2017 16:54:45 -0500 Subject: [PATCH] Added configuration for disabling the actuator trace filter (WebRequestTraceFilter) following the pattern in MetricFilterAutoConfiguration #8322 --- .../TraceWebFilterAutoConfiguration.java | 2 ++ .../TraceWebFilterAutoConfigurationTests.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java index aee07ad61d9f..10c8b02b7653 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java @@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.web.servlet.error.ErrorAttributes; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -42,6 +43,7 @@ */ @ConditionalOnClass({ Servlet.class, DispatcherServlet.class, ServletRegistration.class }) @AutoConfigureAfter(TraceRepositoryAutoConfiguration.class) +@ConditionalOnProperty(name = "endpoints.trace.filter.enabled", matchIfMissing = true) @EnableConfigurationProperties(TraceProperties.class) @Configuration public class TraceWebFilterAutoConfiguration { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java index 91cd9c7bcb40..0574dacdee35 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfigurationTests.java @@ -24,6 +24,7 @@ import org.springframework.boot.actuate.trace.TraceRepository; import org.springframework.boot.actuate.trace.WebRequestTraceFilter; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -58,6 +59,19 @@ public void overrideTraceFilter() throws Exception { context.close(); } + @Test + public void skipsFilterIfPropertyDisabled() throws Exception { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + EnvironmentTestUtils.addEnvironment(context, + "endpoints.trace.filter.enabled:false"); + context.register(PropertyPlaceholderAutoConfiguration.class, + TraceRepositoryAutoConfiguration.class, + TraceWebFilterAutoConfiguration.class); + context.refresh(); + assertThat(context.getBeansOfType(WebRequestTraceFilter.class).size()).isEqualTo(0); + context.close(); + } + @Configuration static class CustomTraceFilterConfig {