pull/3630/head
Phillip Webb 9 years ago
parent 539b009d12
commit d2d71934b6

@ -115,12 +115,14 @@ public class ManagementServerProperties implements SecurityPrerequisite {
}
public void setContextPath(String contextPath) {
this.contextPath = cleanContextPath(contextPath);
}
private String cleanContextPath(String contextPath) {
if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) {
this.contextPath = contextPath.substring(0, contextPath.length() - 1);
}
else {
this.contextPath = contextPath;
return contextPath.substring(0, contextPath.length() - 1);
}
return contextPath;
}
public Security getSecurity() {

@ -46,7 +46,7 @@ import org.springframework.web.servlet.HandlerMapping;
@ConditionalOnClass({ Servlet.class, ServletRegistration.class,
OncePerRequestFilter.class, HandlerMapping.class })
@AutoConfigureAfter(MetricRepositoryAutoConfiguration.class)
@ConditionalOnProperty(name="endpoints.metrics.filter.enabled", matchIfMissing=true)
@ConditionalOnProperty(name = "endpoints.metrics.filter.enabled", matchIfMissing = true)
public class MetricFilterAutoConfiguration {
@Autowired
@ -59,4 +59,5 @@ public class MetricFilterAutoConfiguration {
public Filter metricFilter() {
return new MetricsFilter(this.counterService, this.gaugeService);
}
}

@ -30,6 +30,7 @@ import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatus.Series;
import org.springframework.util.StopWatch;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.servlet.HandlerMapping;
@ -96,10 +97,8 @@ final class MetricsFilter extends OncePerRequestFilter {
if (bestMatchingPattern != null) {
return fixSpecialCharacters(bestMatchingPattern.toString());
}
if (is4xxClientError(status)) {
return UNKNOWN_PATH_SUFFIX;
}
if (is3xxRedirection(status)) {
Series series = getSeries(status);
if (Series.CLIENT_ERROR.equals(series) || Series.REDIRECTION.equals(series)) {
return UNKNOWN_PATH_SUFFIX;
}
return path;
@ -120,22 +119,14 @@ final class MetricsFilter extends OncePerRequestFilter {
return result;
}
private boolean is4xxClientError(int status) {
private Series getSeries(int status) {
try {
return HttpStatus.valueOf(status).is4xxClientError();
return HttpStatus.valueOf(status).series();
}
catch (Exception ex) {
return false;
return null;
}
}
private boolean is3xxRedirection(int status) {
try {
return HttpStatus.valueOf(status).is3xxRedirection();
}
catch (Exception ex) {
return false;
}
}
private String getKey(String string) {

@ -16,19 +16,6 @@
package org.springframework.boot.actuate.autoconfigure;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.IOException;
import javax.servlet.Filter;
@ -60,6 +47,19 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.NestedServletException;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* Tests for {@link MetricFilterAutoConfiguration}.
*

Loading…
Cancel
Save