-
Notifications
You must be signed in to change notification settings - Fork 842
Comments
Allow adding arbitrary labels to metrics when generating output#740
Open
willnewton wants to merge 1 commit intoprometheus:master from
Open
Allow adding arbitrary labels to metrics when generating output #740willnewton wants to merge 1 commit intoprometheus:master from
willnewton wants to merge 1 commit intoprometheus:master from
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 alows passing a dictionary of labels and values to generate_latest which will then be applied to all generated metrics. Signed-off-by: Will Newton <will.newton@gmail.com>
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, thank you for the PR!
I am open to a feature that allows extra labels to be added to all metrics, but I am not sure this is the correct way to do it. What would you think of providing a new type of registry that wraps a CollectorRegistry that will add new labels to each metric?
def generate_latest(registry=REGISTRY):
def generate_latest(registry=REGISTRY, extra_labels={}):
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is to be accepted we would also want this in openmetrics/exposition.py.
Author
willnewton
commented
Dec 22, 2021
I opened a new PR #741 that adds a new collector type. It's a little more complex but conceptually cleaner that way I think.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 alows passing a dictionary of
labels and values to generate_latest which will then be applied
to all generated metrics.
Signed-off-by: Will Newton will.newton@gmail.com
Let me know if this approach looks viable to you, happy to rework it if you have suggestions for how to do it in a better way.