question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Same metric name, different set of label names

See original GitHub issue

We have a lot of Micrometer users requesting that we support registering metrics with the same name but a different set of labels (https://github.com/micrometer-metrics/micrometer/issues/877) for Prometheus. This repo, the official prometheus java client, does not allow this using the built-in types, as can be demonstrated by the following unit test:

@Test
void promClientSameMetricNameDifferentLabels() {
    CollectorRegistry registry = new CollectorRegistry();
    Counter counter = Counter.build().name("api_response").labelNames("outcome").help(" ")
            .register(registry);
    Counter counter2 = Counter.build().name("api_response").labelNames("outcome", "error").help(" ")
            .register(registry); // fails with "Collector already registered that provides name: api_response_total"
}

It is interesting to note, however, that the Prometheus server will scrape the following without any seeming issue.

# HELP responses
# TYPE app_responses_total counter
app_responses_total{uri="/", outcome="SUCCESS"} 10
app_responses_total{uri="/", outcome="FAILURE", error="INVALID_REQUEST"} 2
app_responses_total{uri="/", outcome="FAILURE", error="DATA_NOT_FOUND"} 3

We have a custom Collector implementation for converting from Micrometer metrics to Prometheus metrics. We have received a pull request in Micrometer with changes that would allow Micrometer to produce a scape endpoint like above, circumventing the exception the Prometheus java client would otherwise throw when registering a metric with a different set of labels. See https://github.com/micrometer-metrics/micrometer/pull/2653.

I am opening an issue here because I would rather we did not do something in Micrometer that is intentionally guarded against in the official java client for Prometheus. I am not sure of all the implications supporting something like this might have on consumers. Is preventing different labels still an intentional choice here and are there plans for this library to support that? Would you recommend we avoid allowing it as well in Micrometer? Why does the Prometheus server scrape such output without error if it is considered an error in the client? I appreciate any advice we can get on this from the Prometheus maintainers.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:10
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
nhartnercommented, Oct 12, 2021

This label restriction is some Prometheus dogma that needs to be reevaluated. Consider how many people are asking for a feature that they would find valuable and which technically is already possible. The main reason clients like the Java client don’t support it appears to be documentation dogma.

2reactions
stolsvikcommented, Oct 16, 2021

@brian-brazil Think of it this way, if you suddenly pull in a library that has a clashing metric name rather than having an obvious failure at startup indicating that the name clash needs fixing instead your graphs/alerts will silently break.

Well, the current alternative then is to not use the other library, isn’t it?

Currently, the “solution” for this problem in micrometer is to just ignore the second registration, which is unfortunate along multiple axes - but it is pretty much forced to do that to not break exactly that usage scenario.

In addition, if those two libraries do use the same name (which I actually would find strange, I myself always add some kind of “library-identifier” element to such metrics), it should still be possible to distinguish them by their differing use of labels. This must be a fact, as otherwise - if they used the same labels too - the java client would actually allow the registration.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prometheus - same metric with different labels is overridden ...
I was trying to workaround it and have concatenated each metrics name from label values to e.g. my_metric_aaa_111{labelA = "aaa", labelB = "111"} ......
Read more >
Metric and label naming - Prometheus.io
Use labels to differentiate the characteristics of the thing that is being measured: ... Do not put the label names in the metric...
Read more >
Expose same metric name and different label within one time
Currently, I want to expose 2 metric with same name but different labels at one time, which look like below: # HELP system_test_count...
Read more >
Prometheus Cheat Sheet - Basics (Metrics, Labels, Time ...
Luckily, Prometheus uses another approach - it can differentiate samples with the same metric name by labeling them. A label is a certain ......
Read more >
Metrics — CAF 0.18.4 documentation
CAF identifies metrics by prefix and name. Hence, families with the same prefix and name but different label names are prohibited.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found