Improve handling of non-standard status codes in WebClient metrics
Fixes gh-17695
This commit is contained in:
parent
52050c173c
commit
608228d617
|
@ -80,7 +80,7 @@ public final class WebClientExchangeTags {
|
|||
* @return the status tag
|
||||
*/
|
||||
public static Tag status(ClientResponse response) {
|
||||
return Tag.of("status", String.valueOf(response.statusCode().value()));
|
||||
return Tag.of("status", String.valueOf(response.rawStatusCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -53,7 +53,7 @@ public class DefaultWebClientExchangeTagsProviderTests {
|
|||
this.request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.org/projects/spring-boot"))
|
||||
.attribute(URI_TEMPLATE_ATTRIBUTE, "https://example.org/projects/{project}").build();
|
||||
this.response = mock(ClientResponse.class);
|
||||
given(this.response.statusCode()).willReturn(HttpStatus.OK);
|
||||
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -71,7 +71,7 @@ public class MetricsWebClientFilterFunctionTests {
|
|||
public void filterShouldRecordTimer() {
|
||||
ClientRequest request = ClientRequest
|
||||
.create(HttpMethod.GET, URI.create("https://example.com/projects/spring-boot")).build();
|
||||
given(this.response.statusCode()).willReturn(HttpStatus.OK);
|
||||
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
|
||||
this.filterFunction.filter(request, this.exchange).block(Duration.ofSeconds(30));
|
||||
assertThat(this.registry.get("http.client.requests")
|
||||
.tags("method", "GET", "uri", "/projects/spring-boot", "status", "200").timer().count()).isEqualTo(1);
|
||||
|
@ -82,7 +82,7 @@ public class MetricsWebClientFilterFunctionTests {
|
|||
ClientRequest request = ClientRequest
|
||||
.create(HttpMethod.GET, URI.create("https://example.com/projects/spring-boot"))
|
||||
.attribute(URI_TEMPLATE_ATTRIBUTE, "/projects/{project}").build();
|
||||
given(this.response.statusCode()).willReturn(HttpStatus.OK);
|
||||
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
|
||||
this.filterFunction.filter(request, this.exchange).block(Duration.ofSeconds(30));
|
||||
assertThat(this.registry.get("http.client.requests")
|
||||
.tags("method", "GET", "uri", "/projects/{project}", "status", "200").timer().count()).isEqualTo(1);
|
||||
|
|
|
@ -51,7 +51,6 @@ public class WebClientExchangeTagsTests {
|
|||
this.request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.org/projects/spring-boot"))
|
||||
.attribute(URI_TEMPLATE_ATTRIBUTE, "https://example.org/projects/{project}").build();
|
||||
this.response = mock(ClientResponse.class);
|
||||
given(this.response.statusCode()).willReturn(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,6 +84,7 @@ public class WebClientExchangeTagsTests {
|
|||
|
||||
@Test
|
||||
public void status() {
|
||||
given(this.response.rawStatusCode()).willReturn(HttpStatus.OK.value());
|
||||
assertThat(WebClientExchangeTags.status(this.response)).isEqualTo(Tag.of("status", "200"));
|
||||
}
|
||||
|
||||
|
@ -99,4 +99,10 @@ public class WebClientExchangeTagsTests {
|
|||
.isEqualTo(Tag.of("status", "CLIENT_ERROR"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusWhenNonStandard() {
|
||||
given(this.response.rawStatusCode()).willReturn(490);
|
||||
assertThat(WebClientExchangeTags.status(this.response)).isEqualTo(Tag.of("status", "490"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue