Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding arbitrary labels to metrics when generating output #740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

willnewton
Copy link

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 [email protected]

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.

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 <[email protected]>
Copy link
Member

@csmarchbanks csmarchbanks left a 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?

@@ -135,15 +135,16 @@ def start_wsgi_server(port, addr='', registry=REGISTRY):
start_http_server = start_wsgi_server


def generate_latest(registry=REGISTRY):
def generate_latest(registry=REGISTRY, extra_labels={}):
Copy link
Member

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.

@willnewton
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants