Skip to content

Rest Template : URI Template not honored causing cardinality explosion in prometheus metrics #22307

Closed
@manoja1

Description

@manoja1

I am using Spring boot 2.2.4 with RestTemplate with templatized URI, please see below

private QueryResponse<MetricData<VectorValue>> executeQueryInternal(
            String tenant,
            String pattern,
            Optional<ZonedDateTime> dateTime) {
        String url = host + INSTANT_QUERY_END_POINT + "?query={pattern}&timeout={timeout}";
        List<Object> parameters = new LinkedList<>();
        parameters.add(pattern);
        parameters.add(timeoutDuration);
        if (dateTime.isPresent()) {
            parameters.add(dateTime.get().toEpochSecond());
            url += "&time={dateTime}";
            log.debug("Executing query: {} for pattern: {}, dateTime: {}", url, pattern, dateTime.get().toEpochSecond());
        } else {
            log.debug("Executing query: {} for pattern: {}", url, pattern);
        }
        return restTemplate.exchange(url,
                HttpMethod.GET,
                requestHeaders(tenant),
                new ParameterizedTypeReference<QueryResponse<MetricData<VectorValue>>>() {},
                parameters.toArray(new Object[0]))
                .getBody();
    }

But my micrometer Prometheus Metrics is capturing the full URL, not the template URL causing a cardinality explosion

http_client_requests_seconds_count{clientName="prom.co",method="GET",outcome="SUCCESS",status="200",uri="/api/v1/query?query=sum%20by%20%28topic%2C%20namespace%29%20%28kafka_topic_partitions%29&timeout=30s",} 2.0
http_client_requests_seconds_sum{clientName="prom.co",method="GET",outcome="SUCCESS",status="200",uri="/api/v1/query?query=sum%20by%20%28topic%2C%20namespace%29%20%28kafka_topic_partitions%29&timeout=30s",} 0.11827849 

The micrometer team advised to provide a custom @Bean RestTemplateExchangeTagsProvider and also advised to file an issue with SpringBoot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions