Updated pattern to ignore /actuator (#1342)

Fixes #1338
This commit is contained in:
Tim Ysewyn
2019-04-25 16:32:42 +02:00
committed by Marcin Grzejszczak
parent 74e9988ee2
commit 42b3e4c6c8
2 changed files with 29 additions and 13 deletions

View File

@@ -51,6 +51,7 @@ import org.springframework.util.StringUtils;
* based web application.
*
* @author Marcin Grzejszczak
* @author Tim Ysewyn
* @since 1.0.0
*/
@Configuration
@@ -118,12 +119,12 @@ public class TraceWebAutoConfiguration {
return Optional.empty();
}
String basePath = webEndpointProperties.getBasePath();
String pattern = endpoints.stream().map(PathMappedEndpoint::getRootPath)
.map(path -> path + "|" + path + "/.*").collect(
Collectors.joining("|",
getPathPrefix(contextPath,
webEndpointProperties.getBasePath()) + "/(",
")"));
.map(path -> path + "|" + path + "/.*")
.collect(Collectors.joining("|",
getPathPrefix(contextPath, basePath),
getPathSuffix(contextPath, basePath)));
if (StringUtils.hasText(pattern)) {
return Optional.of(Pattern.compile(pattern));
}
@@ -138,6 +139,21 @@ public class TraceWebAutoConfiguration {
if (!actuatorBasePath.equals("/")) {
result += actuatorBasePath;
}
boolean ignoreBase = StringUtils.hasText(result) && !result.equals("/");
String suffix = "/(";
if (ignoreBase) {
suffix = "(/|" + suffix;
}
return result + suffix;
}
private static String getPathSuffix(String contextPath, String actuatorBasePath) {
String result = ")";
if (StringUtils.hasText(contextPath) ||
(StringUtils.hasText(actuatorBasePath)
&& !"/".equals(actuatorBasePath))) {
result += ")?";
}
return result;
}

View File

@@ -113,7 +113,7 @@ public class SkipPatternProviderConfigTest {
then(pattern).isNotEmpty();
then(pattern.get().pattern())
.isEqualTo("/actuator/(info|info/.*|health|health/.*)");
.isEqualTo("/actuator(/|/(info|info/.*|health|health/.*))?");
}
@Test
@@ -136,7 +136,7 @@ public class SkipPatternProviderConfigTest {
then(pattern).isNotEmpty();
then(pattern.get().pattern())
.isEqualTo("foo/actuator/(info|info/.*|health|health/.*)");
.isEqualTo("foo/actuator(/|/(info|info/.*|health|health/.*))?");
}
@Test
@@ -181,7 +181,7 @@ public class SkipPatternProviderConfigTest {
.skipPattern();
then(pattern).isNotEmpty();
then(pattern.get().pattern()).isEqualTo("foo/(info|info/.*|health|health/.*)");
then(pattern.get().pattern()).isEqualTo("foo(/|/(info|info/.*|health|health/.*))?");
}
@Test
@@ -214,7 +214,7 @@ public class SkipPatternProviderConfigTest {
then(patternSamePort).isNotEmpty();
then(patternSamePort.get().pattern())
.isEqualTo("foo/(info|info/.*|health|health/.*)");
.isEqualTo("foo(/|/(info|info/.*|health|health/.*))?");
}
@Test
@@ -238,7 +238,7 @@ public class SkipPatternProviderConfigTest {
then(patternDifferentPort).isNotEmpty();
then(patternDifferentPort.get().pattern())
.isEqualTo("/mgt/(info|info/.*|health|health/.*)");
.isEqualTo("/mgt(/|/(info|info/.*|health|health/.*))?");
Optional<Pattern> patternSamePort = new TraceWebAutoConfiguration.ActuatorSkipPatternProviderConfig()
.skipPatternForActuatorEndpointsSamePort(properties,
@@ -247,7 +247,7 @@ public class SkipPatternProviderConfigTest {
then(patternSamePort).isNotEmpty();
then(patternSamePort.get().pattern())
.isEqualTo("foo/mgt/(info|info/.*|health|health/.*)");
.isEqualTo("foo/mgt(/|/(info|info/.*|health|health/.*))?");
}
@Test
@@ -271,7 +271,7 @@ public class SkipPatternProviderConfigTest {
then(patternDifferentPort).isNotEmpty();
then(patternDifferentPort.get().pattern())
.isEqualTo("/actuator/(info|info/.*|health|health/.*)");
.isEqualTo("/actuator(/|/(info|info/.*|health|health/.*))?");
Optional<Pattern> patternSamePort = new TraceWebAutoConfiguration.ActuatorSkipPatternProviderConfig()
.skipPatternForActuatorEndpointsSamePort(properties,
@@ -280,7 +280,7 @@ public class SkipPatternProviderConfigTest {
then(patternSamePort).isNotEmpty();
then(patternSamePort.get().pattern())
.isEqualTo("/foo/actuator/(info|info/.*|health|health/.*)");
.isEqualTo("/foo/actuator(/|/(info|info/.*|health|health/.*))?");
}
@Test