What changes when you run `prometheus_client` under gunicorn with multiple workers?
AdvancedConceptTesting, services & metrics
Answer
Each gunicorn worker is a separate process with its own in-memory metrics, so a scrape hits one random worker and you see inconsistent, jumping counters. Use multiprocess mode: set PROMETHEUS_MULTIPROC_DIR to an empty directory before workers start, build the /metrics response with a CollectorRegistry plus multiprocess.MultiProcessCollector(registry), call multiprocess.mark_process_dead(worker.pid) in gunicorn's child_exit hook, and set multiprocess_mode on Gauges (for example "livesum" or "max"). Clear the directory on each start.
More on Testing, services & metrics
Why should automation scripts have tests at all?BeginnerHow does pytest discover and run tests?BeginnerWhy does pytest use plain `assert` instead of `assertEqual`?BeginnerWhat are pytest fixtures, and what scopes exist?IntermediateWhat built-in fixtures do you use most?IntermediateHow does `@pytest.mark.parametrize` work?Beginner