Coverage for /usr/local/lib/python3.10/site-packages/opal_server-0.0.0-py3.10.egg/opal_server/metrics_setup.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 11:54 +0000

1"""One place that decides how opal-server's DogStatsD client is configured. 

2 

3Both the worker app (``OpalServer._configure_monitoring``) and the gunicorn 

4MASTER (the pre-fork scope preload in ``scopes/task.py``, run from 

5``scripts/gunicorn_conf.py:when_ready`` before any worker exists) must call 

6this: the master emits git metrics during preload, and until 0.9.9-rc.3 it 

7never configured the client, so those metrics reached Datadog WITHOUT the 

8``permit.opal`` namespace (``opal_server.scopes.git_ops_in_flight`` next to the 

9workers' ``permit.opal.opal_server.scopes.git_ops_in_flight``) — invisible to 

10every dashboard and monitor written against the namespaced names. 

11""" 

12import os 

13 

14from opal_common.config import opal_common_config 

15from opal_common.monitoring import metrics 

16 

17STATSD_PORT = 8125 

18METRICS_NAMESPACE = "opal" 

19 

20 

21def configure_server_metrics() -> None: 

22 """Configure (or re-configure) the process-wide DogStatsD client the way 

23 opal-server expects it: fail-silent when metrics are disabled, namespace 

24 ``permit.opal`` and the agent host from ``DD_AGENT_HOST`` when enabled. 

25 Safe to call more than once (a forked worker configures again at app 

26 startup).""" 

27 metrics.configure_metrics( 

28 enable_metrics=opal_common_config.ENABLE_METRICS, 

29 statsd_host=os.environ.get("DD_AGENT_HOST", "localhost"), 

30 statsd_port=STATSD_PORT, 

31 namespace=METRICS_NAMESPACE, 

32 )