Affects: 6.1

I think it would be better if RequestEntity was build with uriTemplate when available. I was playing around with Http Interface, RestTemplate and metrics and could see that the URI was not showing properly in the metric. ex:

http_client_requests_seconds_count{client_name="jsonplaceholder.typicode.com",error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="none",} 1.0

When building RequestEntity using uriTemplate it shows correctly. ex:

http_client_requests_seconds_count{client_name="jsonplaceholder.typicode.com",error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="/todos/{id}",} 1.0

It seems that it was planned using uriTemplate https://github.com/spring-projects/spring-framework/issues/30117#issuecomment-1468407023 I'll try to work on this 😀

Comment From: bclozel

@felzan sorry but I don't understand this issue. Can you show how you are using the http interface client, what you are getting as metrics and what you were expecting instead?

Comment From: felzan

Sure! From my understanding, this doc says that using RestTemplateBuilder I'll get ObservationRegistry on the RestTemplate and uri will be set as low cardinality key using the uriTemplate. But using RestTemplateAdapter when configuring Http Interface will build the RequestEntity using the expanded uri so no uriTemplate will be set. This will provoke uri to be none in the metrics.

This is how I'm configuring http interface

    @Bean
public JsonPlaceholderHttpClient jsonPlaceholderHttpClient(RestTemplateBuilder restTemplateBuilder) {
    RestTemplate restTemplate = restTemplateBuilder.build();
    restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory("https://jsonplaceholder.typicode.com"));
    RestTemplateAdapter adapter = RestTemplateAdapter.create(restTemplate);
    HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
    return factory.createClient(JsonPlaceholderHttpClient.class);
}
@HttpExchange(value = "todos")
public interface JsonPlaceholderHttpClient {

    @GetExchange(value = "{id}")
    Todo getTodoById(@PathVariable String id);
}

The metrics output from /actuator/metrics/http.client.requests shows uri as none

And if I set http interface using a custom adapter it works

@Bean
public JsonPlaceholderHttpClient jsonPlaceholderHttpClient(RestTemplateBuilder restTemplateBuilder) {
    RestTemplate restTemplate = restTemplateBuilder.build();
    restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory("https://jsonplaceholder.typicode.com"));
    CustomRestTemplateAdapter adapter = CustomRestTemplateAdapter.create(restTemplate);
    //CustomRestTemplateAdapter.newRequest -> RequestEntity.BodyBuilder builder = RequestEntity.method(httpMethod, values.getUriTemplate(), values.getUriVariables());
    HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
    return factory.createClient(JsonPlaceholderHttpClient.class);
}

Now the metrics output show uri as "/todos/{id}"

If you need further clarification let me know

Comment From: bclozel

Thanks @felzan for testing our milestones, this is really helpful!