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