Commit 8c140092 authored by Stephane Nicoll's avatar Stephane Nicoll

Fix key to disable the metrics filter

Commit d0cf6b53 introduced a `endpoints.metrics.filter.enabled` property
key meant to disable the filter. Unfortunately, the `endpoints.metrics`
namespace is already managed so setting this property will fail.

We now use the same key than the one used to disable the metrics
endpoint.

Closes gh-4365
parent 791e3048
...@@ -46,7 +46,7 @@ import org.springframework.web.servlet.HandlerMapping; ...@@ -46,7 +46,7 @@ import org.springframework.web.servlet.HandlerMapping;
@ConditionalOnClass({ Servlet.class, ServletRegistration.class, @ConditionalOnClass({ Servlet.class, ServletRegistration.class,
OncePerRequestFilter.class, HandlerMapping.class }) OncePerRequestFilter.class, HandlerMapping.class })
@AutoConfigureAfter(MetricRepositoryAutoConfiguration.class) @AutoConfigureAfter(MetricRepositoryAutoConfiguration.class)
@ConditionalOnProperty(name = "endpoints.metrics.filter.enabled", matchIfMissing = true) @ConditionalOnProperty(name = "endpoints.metrics.enabled", matchIfMissing = true)
public class MetricFilterAutoConfiguration { public class MetricFilterAutoConfiguration {
@Autowired @Autowired
......
...@@ -31,6 +31,7 @@ import org.mockito.stubbing.Answer; ...@@ -31,6 +31,7 @@ import org.mockito.stubbing.Answer;
import org.springframework.boot.actuate.metrics.CounterService; import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.boot.actuate.metrics.GaugeService; import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -77,6 +78,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -77,6 +78,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson * @author Andy Wilkinson
* @@author Stephane Nicoll
*/ */
public class MetricFilterAutoConfigurationTests { public class MetricFilterAutoConfigurationTests {
...@@ -175,6 +177,16 @@ public class MetricFilterAutoConfigurationTests { ...@@ -175,6 +177,16 @@ public class MetricFilterAutoConfigurationTests {
context.close(); context.close();
} }
@Test
public void skipsFilterIfPropertyDisabled() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "endpoints.metrics.enabled:false");
context.register(Config.class, MetricFilterAutoConfiguration.class);
context.refresh();
assertThat(context.getBeansOfType(Filter.class).size(), equalTo(0));
context.close();
}
@Test @Test
public void controllerMethodThatThrowsUnhandledException() throws Exception { public void controllerMethodThatThrowsUnhandledException() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment