Skip to content

Commit 7f0573d

Browse files
committed
Fallback on underlying server default when determining outcome tag
This commit also changed the default outcome to SUCCESS Fixes gh-19367
1 parent a017b89 commit 7f0573d

File tree

2 files changed

+21
-3
lines changed
  • spring-boot-project/spring-boot-actuator/src

2 files changed

+21
-3
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,17 @@ public static Tag exception(Throwable exception) {
136136
*/
137137
public static Tag outcome(ServerWebExchange exchange) {
138138
Integer statusCode = extractStatusCode(exchange);
139-
Outcome outcome = (statusCode != null) ? Outcome.forStatus(statusCode) : Outcome.UNKNOWN;
139+
Outcome outcome = (statusCode != null) ? Outcome.forStatus(statusCode) : Outcome.SUCCESS;
140140
return outcome.asTag();
141141
}
142142

143143
private static Integer extractStatusCode(ServerWebExchange exchange) {
144144
ServerHttpResponse response = exchange.getResponse();
145145
if (response instanceof AbstractServerHttpResponse) {
146-
return ((AbstractServerHttpResponse) response).getStatusCodeValue();
146+
Integer statusCode = ((AbstractServerHttpResponse) response).getStatusCodeValue();
147+
if (statusCode != null) {
148+
return statusCode;
149+
}
147150
}
148151
HttpStatus status = response.getStatusCode();
149152
return (status != null) ? status.value() : null;

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.jupiter.api.Test;
2222

2323
import org.springframework.http.HttpStatus;
24+
import org.springframework.http.server.reactive.AbstractServerHttpResponse;
2425
import org.springframework.http.server.reactive.ServerHttpRequest;
2526
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
2627
import org.springframework.mock.web.server.MockServerWebExchange;
@@ -37,6 +38,7 @@
3738
*
3839
* @author Brian Clozel
3940
* @author Michael McFadyen
41+
* @author Madhura Bhave
4042
*/
4143
class WebFluxTagsTests {
4244

@@ -114,7 +116,20 @@ void methodTagToleratesNonStandardHttpMethods() {
114116
void outcomeTagIsUnknownWhenResponseStatusIsNull() {
115117
this.exchange.getResponse().setStatusCode(null);
116118
Tag tag = WebFluxTags.outcome(this.exchange);
117-
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
119+
assertThat(tag.getValue()).isEqualTo("SUCCESS");
120+
}
121+
122+
@Test
123+
void outcomeTagIsSuccessWhenResponseStatusIsAvailableFromUnderlyingServer() {
124+
ServerWebExchange exchange = mock(ServerWebExchange.class);
125+
ServerHttpRequest request = mock(ServerHttpRequest.class);
126+
AbstractServerHttpResponse response = mock(AbstractServerHttpResponse.class);
127+
given(response.getStatusCode()).willReturn(HttpStatus.OK);
128+
given(response.getStatusCodeValue()).willReturn(null);
129+
given(exchange.getRequest()).willReturn(request);
130+
given(exchange.getResponse()).willReturn(response);
131+
Tag tag = WebFluxTags.outcome(exchange);
132+
assertThat(tag.getValue()).isEqualTo("SUCCESS");
118133
}
119134

120135
@Test

0 commit comments

Comments
 (0)