client_python
client_python copied to clipboard
Fix duplicated (+incorrect) metrics when using multiproc environment
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.
I was following the steps shown in the fastapi section https://github.com/prometheus/client_python/#fastapi--gunicorn which uses make_asgi_app