Merge pull request #8650 from ColinHarrington:disable-actuator-trace-filter
* pr/8650: Polish "Add the ability to disable the trace filter" Add the ability to disable the trace filter
This commit is contained in:
commit
7905874f9d
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
|
@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|||
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.ErrorAttributes;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -40,10 +41,11 @@ import org.springframework.web.servlet.DispatcherServlet;
|
|||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, ServletRegistration.class })
|
||||
@AutoConfigureAfter(TraceRepositoryAutoConfiguration.class)
|
||||
@ConditionalOnProperty(prefix = "endpoints.trace.filter", name = "enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(TraceProperties.class)
|
||||
@Configuration
|
||||
public class TraceWebFilterAutoConfiguration {
|
||||
|
||||
private final TraceRepository traceRepository;
|
||||
|
|
|
@ -80,6 +80,12 @@
|
|||
"type": "java.lang.String",
|
||||
"description": "Endpoint URL path."
|
||||
},
|
||||
{
|
||||
"name": "endpoints.trace.filter.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Enable the trace servlet filter.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "info",
|
||||
"type": "java.util.Map<java.lang.String,java.lang.Object>",
|
||||
|
|
|
@ -18,12 +18,14 @@ package org.springframework.boot.actuate.autoconfigure;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.trace.TraceProperties;
|
||||
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;
|
||||
|
@ -34,28 +36,54 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* Tests for {@link TraceWebFilterAutoConfiguration}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class TraceWebFilterAutoConfigurationTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureFilter() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
TraceRepositoryAutoConfiguration.class,
|
||||
TraceWebFilterAutoConfiguration.class);
|
||||
assertThat(context.getBean(WebRequestTraceFilter.class)).isNotNull();
|
||||
context.close();
|
||||
load();
|
||||
assertThat(this.context.getBean(WebRequestTraceFilter.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overrideTraceFilter() throws Exception {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
CustomTraceFilterConfig.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
TraceRepositoryAutoConfiguration.class,
|
||||
TraceWebFilterAutoConfiguration.class);
|
||||
WebRequestTraceFilter filter = context.getBean(WebRequestTraceFilter.class);
|
||||
load(CustomTraceFilterConfig.class);
|
||||
WebRequestTraceFilter filter = this.context.getBean(WebRequestTraceFilter.class);
|
||||
assertThat(filter).isInstanceOf(TestWebRequestTraceFilter.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skipsFilterIfPropertyDisabled() throws Exception {
|
||||
load("endpoints.trace.filter.enabled:false");
|
||||
assertThat(this.context.getBeansOfType(WebRequestTraceFilter.class).size())
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
private void load(String... environment) {
|
||||
load(null, environment);
|
||||
}
|
||||
|
||||
private void load(Class<?> config, String... environment) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
||||
if (config != null) {
|
||||
ctx.register(config);
|
||||
}
|
||||
ctx.register(PropertyPlaceholderAutoConfiguration.class,
|
||||
TraceRepositoryAutoConfiguration.class,
|
||||
TraceWebFilterAutoConfiguration.class);
|
||||
ctx.refresh();
|
||||
this.context = ctx;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -1058,6 +1058,7 @@ content into your application; rather pick only the properties that you need.
|
|||
endpoints.shutdown.path= # Endpoint path.
|
||||
endpoints.shutdown.sensitive= # Mark if the endpoint exposes sensitive information.
|
||||
endpoints.trace.enabled= # Enable the endpoint.
|
||||
endpoints.trace.filter.enabled=true # Enable the trace servlet filter.
|
||||
endpoints.trace.id= # Endpoint identifier.
|
||||
endpoints.trace.path= # Endpoint path.
|
||||
endpoints.trace.sensitive= # Mark if the endpoint exposes sensitive information.
|
||||
|
|
Loading…
Reference in New Issue