Search code examples
javaspringprometheusspring-boot-actuator

Error from promtheus in java (spring acuator)


I enabled and configured Spring Actuator with Prometheus endpoint in my spring boot application. But I receive an error, that Prometheus requires that all meters with the same name have the same set of tag keys. But unfortunately Spring Actuator won't do that for jvm_gc_pause_seconds.

I'm using:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.1.RELEASE</version>
</parent>

with

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

....

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
    <version>1.5.1</version>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
    <version>1.5.1</version>
</dependency>

This is my error message:

java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named 'jvm_gc_pause_seconds'  │
│     at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$17(PrometheusMeterRegistry.java:429)                                                                       │
│     at java.base/java.util.concurrent.ConcurrentHashMap.compute(Unknown Source)                                                                                                            │
│     at io.micrometer.prometheus.PrometheusMeterRegistry.applyToCollector(PrometheusMeterRegistry.java:413)                                                                                 │
│     at io.micrometer.prometheus.PrometheusMeterRegistry.newTimer(PrometheusMeterRegistry.java:196)                                                                                         │
│     at io.micrometer.core.instrument.MeterRegistry.lambda$timer$2(MeterRegistry.java:308)                                                                                                  │
│     at io.micrometer.core.instrument.MeterRegistry.getOrCreateMeter(MeterRegistry.java:612)                                                                                                │
│     at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:566)                                                                                        │
│     at io.micrometer.core.instrument.MeterRegistry.timer(MeterRegistry.java:306)                                                                                                           │
│     at io.micrometer.core.instrument.Timer$Builder.register(Timer.java:539)                                                                                                                │
│     at io.micrometer.core.instrument.binder.jvm.JvmGcMetrics.lambda$bindTo$1(JvmGcMetrics.java:151)                                                                                        │
│     at java.management/sun.management.NotificationEmitterSupport.sendNotification(Unknown Source)                                                                                          │
│     at jdk.management/com.sun.management.internal.GarbageCollectorExtImpl.createGCNotification(Unknown Source)

Any idea?! I don't have this error when I remove the Prometheus endpoint configuration (micrometer-registry-prometheus dependency).


Solution

  • I solved my problem by updating micrometer-registry-prometheus from 1.5.1 to 1.5.4

    With this update the error message was more speakable:

    Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named 'jvm_gc_pause_seconds' containing tag keys [username, endpoint]. The meter you are attempting to register has keys [username, endpoint, service].
    

    So I found the problem. I added a common tag to all metrics. After removing the common tag, the error was solved.