spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.81k stars 40.6k forks source link

Meter created by @Timed does not appear in /actuator/prometheus #41697

Closed space88man closed 2 months ago

space88man commented 2 months ago

I am annotating a public method (non-controller) with @Timed and I can see that it is created in PrometheusMeterRegistry and appears in /actuator/metrics ­— after being called at least once.

Setting a breakpoint at PrometheusMeterRegistry::newTimer does show that the metric is being created in a huge TimedAspect call stack. I have management.observations.annotations.enabled=true set.

However the endpoint /actuator/prometheus depends on a PrometheusRegistry field (and PrometheusMeterRegistry shares the same object as a field registry). However this field doen't seem to get updated during newTimer so /actuator/prometheus doesn't change.

When scraping /actuator/prometheus the new Timer does not appear.

OTOH in JMX, I do see the new Timer created with a very long name (it includes the class, exception, and extraTags).

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>
    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-jmx</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
management.endpoints.jmx.exposure.include=health,info,env,beans,caches,prometheus,metrics
management.endpoints.web.exposure.include=health,info,env,beans,caches,prometheus,metrics
management.prometheus.metrics.export.enabled=true
management.jmx.metrics.export.enabled=true
management.observations.annotations.enabled=true
spring.jmx.enabled=true
mhalbritter commented 2 months ago

Hey, thanks for the report. If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

space88man commented 2 months ago

Update: the name had been used in a different method with a different set of tags; I see that the Prometheus registry doesn't allow this. Sorry for the noise.

mhalbritter commented 2 months ago

No harm done, thanks for chiming back in.