Search code examples
spring-boothttpclientprometheusspring-boot-actuator

Looking for a solution to fix http_client_requests_* missing issue


I am trying to enable Prometheus endpoint in my springboot project having below dependencies.

SpringBoot version:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.12-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

Dependencies:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

I am using restTemplate to make outbound call but when I check Prometheus endpoint, the data related with http_client_requests are missing Looking for a solution to fix http_client_requests_ missing issue.


Solution

  • I think you're missing this piece of code in a @Configuration file:

        @Bean
        public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
            return restTemplateBuilder.build();
        }
    

    Which will somewhere downstreams add a MetricsClientHttpRequestInterceptor that produces the actually metrics utilizing a Timer