6

We are using Spring Boot 2.1.4 and the micrometer-registry-prometheus dependency to capture metrics.

We have a case where a Spring Boot service uses a RestTemplate to call out to another service. The metrics being generated by this call contain the actual values in the URI instead of the templated values.

For example, in the /actuator/prometheus endpoint, I see entries like this:

http_client_requests_seconds_count{clientName="someClient",method="GET",status="200",uri="/person/lookup?firstName=Tony&lastName=Soprano",} 1.0

Based on the documentation, I would expect to see the variable names rather than the values, like this:

http_client_requests_seconds_count{clientName="someClient",method="GET",status="200",uri="/person/lookup?firstName={firstName}&lastName={lastName}",} 1.0

Is there a way to get the default http.client.requests metric values to use the templated values for the URI tag?

The Spring documentation at https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-metrics-http-clients says this about the uri tag:

Request’s URI template prior to variable substitution, if possible (for example, /api/person/{id})

How do we make it possible for the variable substitution to take place?

David D
  • 177
  • 2
  • 9
  • AFAIK, it is intended to have separate log for each call with used values. But, monitoring tools such as Grafana helps to show the results in generic way. IMHO, if it is logged without values, it'll be difficult to figure out the metric results. – Rauf Aghayev Nov 19 '19 at 21:24
  • 3
    @RaufAgayev if we are calling {id} 1000 times, effectively it creates 1000 entries for metrics and results in performance issue – SUMIT Jan 28 '20 at 14:54

1 Answers1

12

I assume you are using the RestTemplateBuilder to build your RestTemplate as otherwise you wouldn't be getting the metrics registered.

Are you actually passing a templated url into RestTemplates exchange methods and pass along the params for subsbitution? Works-for-me on 2.1.4.RELEASE and 2.2.1.RELEASE.

    template.getForObject("http://localhost:" + this.serverPort + "/hello/{id}",
            String.class, Collections.singletonMap("id", "loop"));

Results in:

http_client_requests_seconds_count{application="micrometered2",clientName="localhost",method="GET",outcome="SUCCESS",status="200",uri="/hello/{id}",} 23.0
mweirauch
  • 1,958
  • 11
  • 17