diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricsFilter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricsFilter.java index 7aaf62e375..8d448cd99c 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricsFilter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricsFilter.java @@ -145,7 +145,8 @@ final class MetricsFilter extends OncePerRequestFilter { return fixSpecialCharacters(bestMatchingPattern.toString()); } Series series = getSeries(status); - if (Series.CLIENT_ERROR.equals(series) || Series.REDIRECTION.equals(series)) { + if (Series.CLIENT_ERROR.equals(series) || Series.SERVER_ERROR.equals(series) + || Series.REDIRECTION.equals(series)) { return UNKNOWN_PATH_SUFFIX; } return path; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java index 7ff1b01c68..4e5820f58d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfigurationTests.java @@ -78,7 +78,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * * @author Phillip Webb * @author Andy Wilkinson - * @@author Stephane Nicoll + * @author Stephane Nicoll */ public class MetricFilterAutoConfigurationTests { @@ -277,6 +277,24 @@ public class MetricFilterAutoConfigurationTests { } } + @Test + public void records5xxxHttpInteractionsAsSingleMetric() throws Exception { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( + Config.class, MetricFilterAutoConfiguration.class, + ServiceUnavailableFilter.class); + MetricsFilter filter = context.getBean(MetricsFilter.class); + MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()) + .addFilter(filter) + .addFilter(context.getBean(ServiceUnavailableFilter.class)).build(); + mvc.perform(get("/unknownPath/1")).andExpect(status().isServiceUnavailable()); + mvc.perform(get("/unknownPath/2")).andExpect(status().isServiceUnavailable()); + verify(context.getBean(CounterService.class), times(2)) + .increment("status.503.unmapped"); + verify(context.getBean(GaugeService.class), times(2)) + .submit(eq("response.unmapped"), anyDouble()); + context.close(); + } + @Configuration public static class Config { @@ -376,4 +394,18 @@ public class MetricFilterAutoConfigurationTests { } + @Component + @Order(0) + public static class ServiceUnavailableFilter extends OncePerRequestFilter { + + @Override + protected void doFilterInternal(HttpServletRequest request, + HttpServletResponse response, FilterChain chain) + throws ServletException, IOException { + + response.sendError(HttpStatus.SERVICE_UNAVAILABLE.value()); + } + + } + }