Fix URI tag on RestTemplate requests based on URIs
Move leading slash logic from `MetricsClientHttpRequestInterceptor` to `RestTemplateExchangeTags` so that URI based calls are also managed. Closes gh-12126
This commit is contained in:
committed by
Phillip Webb
parent
adf22d6e4a
commit
ec5ef0f246
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.actuate.metrics.web.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
@@ -99,4 +101,18 @@ public class MetricsRestTemplateCustomizerTests {
|
||||
this.mockServer.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void interceptRestTemplateWithUri() throws URISyntaxException {
|
||||
this.mockServer
|
||||
.expect(MockRestRequestMatchers.requestTo("http://localhost/test/123"))
|
||||
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
|
||||
.andRespond(MockRestResponseCreators.withSuccess("OK",
|
||||
MediaType.APPLICATION_JSON));
|
||||
String result = this.restTemplate
|
||||
.getForObject(new URI("http://localhost/test/123"), String.class);
|
||||
assertThat(result).isEqualTo("OK");
|
||||
this.registry.get("http.client.requests").tags("uri", "/test/123").timer();
|
||||
this.mockServer.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user