diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java index 477d7b422760..89c6d1ba3f6c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcTags.java @@ -175,22 +175,21 @@ public static Tag exception(Throwable exception) { */ public static Tag outcome(HttpServletResponse response) { if (response != null) { - HttpStatus status = extractStatus(response); - if (status != null) { - if (status.is1xxInformational()) { + HttpStatus.Series series = HttpStatus.Series.resolve(response.getStatus()); + if (series != null) { + switch (series) { + case INFORMATIONAL: return OUTCOME_INFORMATIONAL; - } - if (status.is2xxSuccessful()) { + case SUCCESSFUL: return OUTCOME_SUCCESS; - } - if (status.is3xxRedirection()) { + case REDIRECTION: return OUTCOME_REDIRECTION; - } - if (status.is4xxClientError()) { + case CLIENT_ERROR: return OUTCOME_CLIENT_ERROR; + case SERVER_ERROR: + return OUTCOME_SERVER_ERROR; } } - return OUTCOME_SERVER_ERROR; } return OUTCOME_UNKNOWN; } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java index 4125ca31c8ac..55e27a6b913d 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/WebMvcTagsTests.java @@ -136,6 +136,13 @@ void outcomeTagIsClientErrorWhenResponseIs4xx() { assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR"); } + @Test + void outcomeTagIsClientErrorWhenResponseIsNonStandardInClientSeries() { + this.response.setStatus(490); + Tag tag = WebMvcTags.outcome(this.response); + assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR"); + } + @Test void outcomeTagIsServerErrorWhenResponseIs5xx() { this.response.setStatus(500); @@ -143,4 +150,11 @@ void outcomeTagIsServerErrorWhenResponseIs5xx() { assertThat(tag.getValue()).isEqualTo("SERVER_ERROR"); } + @Test + void outcomeTagIsUnknownWhenResponseStatusIsInUnknownSeries() { + this.response.setStatus(701); + Tag tag = WebMvcTags.outcome(this.response); + assertThat(tag.getValue()).isEqualTo("UNKNOWN"); + } + }