File tree 2 files changed +27
-2
lines changed
spring-boot-project/spring-boot-actuator/src
main/java/org/springframework/boot/actuate/metrics/web/reactive/server
test/java/org/springframework/boot/actuate/metrics/web/reactive/server
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 20
20
21
21
import org .springframework .boot .actuate .metrics .http .Outcome ;
22
22
import org .springframework .http .HttpStatus ;
23
+ import org .springframework .http .server .reactive .AbstractServerHttpResponse ;
24
+ import org .springframework .http .server .reactive .ServerHttpResponse ;
23
25
import org .springframework .util .StringUtils ;
24
26
import org .springframework .web .reactive .HandlerMapping ;
25
27
import org .springframework .web .server .ServerWebExchange ;
@@ -133,9 +135,18 @@ public static Tag exception(Throwable exception) {
133
135
* @since 2.1.0
134
136
*/
135
137
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 ;
138
140
return outcome .asTag ();
139
141
}
140
142
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
+
141
152
}
Original file line number Diff line number Diff line change @@ -152,4 +152,18 @@ void outcomeTagIsServerErrorWhenResponseIs5xx() {
152
152
assertThat (tag .getValue ()).isEqualTo ("SERVER_ERROR" );
153
153
}
154
154
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
+
155
169
}
You can’t perform that action at this time.
0 commit comments