Skip to content

Commit b15e427

Browse files
committed
Improve handling of non-standard status codes in WebFluxTags
Closes gh-18267
1 parent 6534047 commit b15e427

File tree

2 files changed

+27
-2
lines changed
  • spring-boot-project/spring-boot-actuator/src

2 files changed

+27
-2
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTags.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import org.springframework.boot.actuate.metrics.http.Outcome;
2222
import org.springframework.http.HttpStatus;
23+
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
24+
import org.springframework.http.server.reactive.ServerHttpResponse;
2325
import org.springframework.util.StringUtils;
2426
import org.springframework.web.reactive.HandlerMapping;
2527
import org.springframework.web.server.ServerWebExchange;
@@ -133,9 +135,18 @@ public static Tag exception(Throwable exception) {
133135
* @since 2.1.0
134136
*/
135137
public static Tag outcome(ServerWebExchange exchange) {
136-
HttpStatus status = exchange.getResponse().getStatusCode();
137-
Outcome outcome = (status != null) ? Outcome.forStatus(status.value()) : Outcome.UNKNOWN;
138+
Integer statusCode = extractStatusCode(exchange);
139+
Outcome outcome = (statusCode != null) ? Outcome.forStatus(statusCode) : Outcome.UNKNOWN;
138140
return outcome.asTag();
139141
}
140142

143+
private static Integer extractStatusCode(ServerWebExchange exchange) {
144+
ServerHttpResponse response = exchange.getResponse();
145+
if (response instanceof AbstractServerHttpResponse) {
146+
return ((AbstractServerHttpResponse) response).getStatusCodeValue();
147+
}
148+
HttpStatus status = response.getStatusCode();
149+
return (status != null) ? status.value() : null;
150+
}
151+
141152
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/server/WebFluxTagsTests.java

+14
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,18 @@ void outcomeTagIsServerErrorWhenResponseIs5xx() {
152152
assertThat(tag.getValue()).isEqualTo("SERVER_ERROR");
153153
}
154154

155+
@Test
156+
void outcomeTagIsClientErrorWhenResponseIsNonStandardInClientSeries() {
157+
this.exchange.getResponse().setStatusCodeValue(490);
158+
Tag tag = WebFluxTags.outcome(this.exchange);
159+
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
160+
}
161+
162+
@Test
163+
void outcomeTagIsUnknownWhenResponseStatusIsInUnknownSeries() {
164+
this.exchange.getResponse().setStatusCodeValue(701);
165+
Tag tag = WebFluxTags.outcome(this.exchange);
166+
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
167+
}
168+
155169
}

0 commit comments

Comments
 (0)