Commit b15e427a authored by Andy Wilkinson's avatar Andy Wilkinson

Improve handling of non-standard status codes in WebFluxTags

Closes gh-18267
parent 6534047f
...@@ -20,6 +20,8 @@ import io.micrometer.core.instrument.Tag; ...@@ -20,6 +20,8 @@ import io.micrometer.core.instrument.Tag;
import org.springframework.boot.actuate.metrics.http.Outcome; import org.springframework.boot.actuate.metrics.http.Outcome;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
...@@ -133,9 +135,18 @@ public final class WebFluxTags { ...@@ -133,9 +135,18 @@ public final class WebFluxTags {
* @since 2.1.0 * @since 2.1.0
*/ */
public static Tag outcome(ServerWebExchange exchange) { public static Tag outcome(ServerWebExchange exchange) {
HttpStatus status = exchange.getResponse().getStatusCode(); Integer statusCode = extractStatusCode(exchange);
Outcome outcome = (status != null) ? Outcome.forStatus(status.value()) : Outcome.UNKNOWN; Outcome outcome = (statusCode != null) ? Outcome.forStatus(statusCode) : Outcome.UNKNOWN;
return outcome.asTag(); return outcome.asTag();
} }
private static Integer extractStatusCode(ServerWebExchange exchange) {
ServerHttpResponse response = exchange.getResponse();
if (response instanceof AbstractServerHttpResponse) {
return ((AbstractServerHttpResponse) response).getStatusCodeValue();
}
HttpStatus status = response.getStatusCode();
return (status != null) ? status.value() : null;
}
} }
...@@ -152,4 +152,18 @@ class WebFluxTagsTests { ...@@ -152,4 +152,18 @@ class WebFluxTagsTests {
assertThat(tag.getValue()).isEqualTo("SERVER_ERROR"); assertThat(tag.getValue()).isEqualTo("SERVER_ERROR");
} }
@Test
void outcomeTagIsClientErrorWhenResponseIsNonStandardInClientSeries() {
this.exchange.getResponse().setStatusCodeValue(490);
Tag tag = WebFluxTags.outcome(this.exchange);
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}
@Test
void outcomeTagIsUnknownWhenResponseStatusIsInUnknownSeries() {
this.exchange.getResponse().setStatusCodeValue(701);
Tag tag = WebFluxTags.outcome(this.exchange);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment