client_python icon indicating copy to clipboard operation
client_python copied to clipboard

Fix duplicated (+incorrect) metrics when using multiproc environment

Open RedKinda opened this issue 1 year ago • 1 comments

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.

RedKinda avatar Sep 20 '23 23:09 RedKinda

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

RedKinda avatar Sep 24 '23 15:09 RedKinda