Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug where duplicate keys are registered in client metrics (#5466)
Motivation: An `IllegalArgumentException` is raised when `ConnectionPoolListener.metricCollecting()` is used to monitor connection pools. The changes in #5288 caused the problem. The different types (`Gauge`, `Counter`) of meters are registered with the same name. Unfortunately, it wasn't caught by unit tests because the restriction only exists in `PrometheusMeterRegistry`. `SimpleMeterRegistry` was used to verify the code. ```java java.lang.IllegalArgumentException: Failed to register Collector of type MicrometerCollector: armeria_client_connections is already in use by another Collector of type MicrometerCollector at io.prometheus.client.CollectorRegistry.register(CollectorRegistry.java:57) at io.prometheus.client.Collector.register(Collector.java:307) at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$17(PrometheusMeterRegistry.java:557) at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1947) at io.micrometer.prometheus.PrometheusMeterRegistry.applyToCollector(PrometheusMeterRegistry.java:552) at io.micrometer.prometheus.PrometheusMeterRegistry.newGauge(PrometheusMeterRegistry.java:327) ... at io.micrometer.core.instrument.MeterRegistry.gauge(MeterRegistry.java:311) at io.micrometer.core.instrument.Gauge$Builder.register(Gauge.java:195) at com.linecorp.armeria.client.ConnectionPoolMetrics$Meters.<init>(ConnectionPoolMetrics.java:118) at com.linecorp.armeria.client.ConnectionPoolMetrics.lambda$increaseConnOpened$0(ConnectionPoolMetrics.java:61) ``` Modifications: - Infix `active` to the meter name and remove `status=active` tag. - `<prefix>.active.connections` now becomes the meter name for active connections. - `.connections` suffix is added to connection pool metrics. Result: - You no longer see `IllegalArgumentException` when using `ConnectionPoolListener.metricCollecting()`. - Breaking) `.connections` suffix is now automatically added to connection pool metrics. If you use a custom `MeterIdPrefix` with `ConnectionPoolListener.metricCollecting(MeterRegistry,MeterIdPrefix)`, the meter name will change.
- Loading branch information