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