diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java index f01ac80675..764c069c34 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java @@ -136,14 +136,17 @@ public final class WebFluxTags { */ public static Tag outcome(ServerWebExchange exchange) { Integer statusCode = extractStatusCode(exchange); - Outcome outcome = (statusCode != null) ? Outcome.forStatus(statusCode) : Outcome.UNKNOWN; + Outcome outcome = (statusCode != null) ? Outcome.forStatus(statusCode) : Outcome.SUCCESS; return outcome.asTag(); } private static Integer extractStatusCode(ServerWebExchange exchange) { ServerHttpResponse response = exchange.getResponse(); if (response instanceof AbstractServerHttpResponse) { - return ((AbstractServerHttpResponse) response).getStatusCodeValue(); + Integer statusCode = ((AbstractServerHttpResponse) response).getStatusCodeValue(); + if (statusCode != null) { + return statusCode; + } } HttpStatus status = response.getStatusCode(); return (status != null) ? status.value() : null; diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java index b713485191..8cbf018b4d 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.AbstractServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.web.server.MockServerWebExchange; @@ -37,6 +38,7 @@ import static org.mockito.Mockito.mock; * * @author Brian Clozel * @author Michael McFadyen + * @author Madhura Bhave */ class WebFluxTagsTests { @@ -114,7 +116,20 @@ class WebFluxTagsTests { void outcomeTagIsUnknownWhenResponseStatusIsNull() { this.exchange.getResponse().setStatusCode(null); Tag tag = WebFluxTags.outcome(this.exchange); - assertThat(tag.getValue()).isEqualTo("UNKNOWN"); + assertThat(tag.getValue()).isEqualTo("SUCCESS"); + } + + @Test + void outcomeTagIsSuccessWhenResponseStatusIsAvailableFromUnderlyingServer() { + ServerWebExchange exchange = mock(ServerWebExchange.class); + ServerHttpRequest request = mock(ServerHttpRequest.class); + AbstractServerHttpResponse response = mock(AbstractServerHttpResponse.class); + given(response.getStatusCode()).willReturn(HttpStatus.OK); + given(response.getStatusCodeValue()).willReturn(null); + given(exchange.getRequest()).willReturn(request); + given(exchange.getResponse()).willReturn(response); + Tag tag = WebFluxTags.outcome(exchange); + assertThat(tag.getValue()).isEqualTo("SUCCESS"); } @Test