Allow adding arbitrary labels to metrics when generating output#741
Allow adding arbitrary labels to metrics when generating output#741willnewton wants to merge 2 commits intoprometheus:masterfrom
Conversation
It's useful to be able to apply a label across all metrics, for example when using a multi-processing framework to apply a label for worker ID to all metrics (including from builtin collector types). This change adds a new Registry type that applies a dictionary of labels when metrics are collected. Signed-off-by: Will Newton <will.newton@gmail.com>
Signed-off-by: Will Newton <will.newton@gmail.com>
csmarchbanks
left a comment
There was a problem hiding this comment.
Hmm, so this is a bit backwards of what I was imagining, I apologize for not being clear in the other comment/misunderstanding your goal. The use case I would support is what is described in client_golang/prometheus#WrapRegistererWith. This allows systems such as distinct workers to register the same set of metrics with a distinct label, but would not apply to every metric being exported. For more details on why we don't encourage labels on every metric see https://prometheus.io/docs/instrumenting/writing_exporters/#target-labels-not-static-scraped-labels.
Does that make sense/would it help your use case?
| samples with additional labels given in the dictionary. | ||
|
|
||
| Intended usage is: | ||
| generate_latest(REGISTRY.labelled_registry(['a_timeseries'])) |
There was a problem hiding this comment.
This example is incorrect as it should be passing a dict of constant labels.
|
@csmarchbanks I'm a little confused by your comment, since the Python client doesn't seem to have the concept of a |
|
I can imagine a few implementations that would be acceptable, but my guess is that we will have a new class that inherits from to add all of the labeled metrics to the default registry or any other registry. Does that make sense? I might even be ok with just adding a const_labels variable when initializing a CollectorRegistry, but not sure if that would be best compared to a new class. |
It's useful to be able to apply a label across all metrics, for
example when using a multi-processing framework to apply a
label for worker ID to all metrics (including from builtin
collector types). This change adds a new Registry type that
applies a dictionary of labels when metrics are collected.
Signed-off-by: Will Newton will.newton@gmail.com