Skip to content

Support OpenMetrics Unit #2482

@shakuzen

Description

@shakuzen

This is broken out from #2419 due to the issues with adding this support described below.

Since the 0.10.0 version of the prometheus java client, it supports the OpenMetrics model and scrape format. The model has explicit support for Units as opposed to only a metric name convention in the prior model. The Prometheus java client now enforces the naming convention (unit is last part of name) being honored in naming when a unit is set.

This is problematic for Micrometer Timer and DistributionSummary types which have a max that is a separate gauge metric in the Prometheus model. Setting a unit and changing nothing else results in an exception being thrown:

java.lang.IllegalArgumentException: Metric's unit is not the suffix of the metric name: my_timer_seconds_max

	at io.prometheus.client.Collector$MetricFamilySamples.<init>(Collector.java:45)
	at io.micrometer.prometheus.MicrometerCollector.describe(MicrometerCollector.java:98)
	at io.prometheus.client.CollectorRegistry.collectorNames(CollectorRegistry.java:98)
	at io.prometheus.client.CollectorRegistry.register(CollectorRegistry.java:50)
	at io.prometheus.client.Collector.register(Collector.java:175)
	at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$16(PrometheusMeterRegistry.java:446)
	at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1916)
	at io.micrometer.prometheus.PrometheusMeterRegistry.applyToCollector(PrometheusMeterRegistry.java:442)
	at io.micrometer.prometheus.PrometheusMeterRegistry.newTimer(PrometheusMeterRegistry.java:236)
	at io.micrometer.core.instrument.MeterRegistry.lambda$timer$2(MeterRegistry.java:310)
	at io.micrometer.core.instrument.MeterRegistry.getOrCreateMeter(MeterRegistry.java:614)
	at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:568)
	at io.micrometer.core.instrument.MeterRegistry.timer(MeterRegistry.java:308)
	at io.micrometer.core.instrument.Timer$Builder.register(Timer.java:400)

There is some history in #519 and prometheus/client_python#264. To abide by the naming convention, the max gauge would have to change to my_timer_max_seconds in this case, but that is a metric name change and therefore a breaking change to users. Really we want an additional suffix _max for the summary/histogram type that's treated like a gauge. The Prometheus server handles this without issue, but other Prometheus clients do not and so we changed away from this approach in #519 previously.

# TYPE my_timer_seconds summary
# UNIT my_timer_seconds seconds
# HELP my_timer_seconds  
my_timer_seconds_count 0.0
my_timer_seconds_sum 0.0
my_timer_seconds_max 0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions