Browse Source

Align WebClient uri metric tag with RestTemplate

Prior to this commit, the `WebClientExchangeTags`, when given a request
without a string template, would only get the request path to create the
"uri" tag for metrics. This is inconsistent with the
`RestTemplateExchangeTags`, which are taking the full request URI minus
the protocol+host+port.

This commit aligns the `WebClientExchangeTags` behavior in this case.

Closes gh-22832
pull/23246/head
Brian Clozel 5 years ago
parent
commit
d2e67ab84d
  1. 2
      spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java
  2. 8
      spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java

2
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java

@ -66,7 +66,7 @@ public final class WebClientExchangeTags { @@ -66,7 +66,7 @@ public final class WebClientExchangeTags {
* @return the uri tag
*/
public static Tag uri(ClientRequest request) {
String uri = (String) request.attribute(URI_TEMPLATE_ATTRIBUTE).orElseGet(() -> request.url().getPath());
String uri = (String) request.attribute(URI_TEMPLATE_ATTRIBUTE).orElseGet(() -> request.url().toString());
return Tag.of("uri", extractPath(uri));
}

8
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java

@ -78,6 +78,14 @@ class WebClientExchangeTagsTests { @@ -78,6 +78,14 @@ class WebClientExchangeTagsTests {
assertThat(WebClientExchangeTags.uri(this.request)).isEqualTo(Tag.of("uri", "/projects/spring-boot"));
}
@Test
void uriWhenTemplateIsMissingShouldReturnPathWithQueryParams() {
this.request = ClientRequest
.create(HttpMethod.GET, URI.create("https://example.org/projects/spring-boot?section=docs")).build();
assertThat(WebClientExchangeTags.uri(this.request))
.isEqualTo(Tag.of("uri", "/projects/spring-boot?section=docs"));
}
@Test
void clientName() {
assertThat(WebClientExchangeTags.clientName(this.request)).isEqualTo(Tag.of("clientName", "example.org"));

Loading…
Cancel
Save