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

Fix duplicated (+incorrect) metrics when using multiproc environment #960

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RedKinda
Copy link

Currently, when using a multiproc environment, initializing metrics registers them as collectors. This means that in registry.py:96 they report their metrics, even though they were already reported in the mmapped environment. In practice this meant dumping metrics would report some metrics twice with the same identifiers, once for the aggregated multiproc collector and once for the Histogram or other metrics used by the local process handling that specific /metrics request.

This PR prevents Metric-s being registered into the registry as collectors by checking for presence of the two relevant env vars.

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.

Interesting, this is the reason why in examples we always create a new Collector registry that is not used for registering any metrics, e.g.

registry = CollectorRegistry()
multiprocess.MultiProcessCollector(registry)
data = generate_latest(registry)

as part of the handler.

I am trying to think if there are any valid use cases for having a second registry with a different set of metrics, but as you say, I think they will all show up in the multiprocess output so probably not.

@RedKinda
Copy link
Author

I was following the steps shown in the fastapi section https://github.com/prometheus/client_python/#fastapi--gunicorn which uses make_asgi_app

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