From 19f49652581a12fad9e4246d38b4fd285769c601 Mon Sep 17 00:00:00 2001 From: Emi Griffith Date: Thu, 16 Jul 2026 14:28:04 -0700 Subject: [PATCH] Metrics: don't count the dashboard's own /api/v2/metrics polling (#135) The ops dashboard polls the metrics endpoint every few seconds; counting those hits just shows the monitor watching itself and inflates the inbound totals. Skip the 'metrics' category in record_inbound (so it's excluded from inbound_total too), and hide it in the dashboard's inbound list defensively. --- metrics.py | 4 ++++ tests/test_metrics.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/metrics.py b/metrics.py index 82d241f..87cab8b 100644 --- a/metrics.py +++ b/metrics.py @@ -97,6 +97,10 @@ def classify_inbound(path: str, base: str = "") -> str: def record_inbound(category: str, status) -> None: """Count one inbound request in ``category``, bucketed by status class.""" + # The metrics endpoint is polled by the dashboard itself — counting it would just + # show the monitor watching itself, so it's excluded from traffic entirely. + if category == "metrics": + return try: bucket = _status_bucket(status) with _lock: diff --git a/tests/test_metrics.py b/tests/test_metrics.py index c7fd244..0035835 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -60,6 +60,17 @@ def test_record_inbound_buckets_by_status(): assert snap["inbound_total"] == 4 +def test_metrics_endpoint_polling_is_not_counted(): + # The dashboard polls the metrics endpoint; that self-traffic must be excluded. + m = _fresh() + m.record_inbound("metrics", 200) + m.record_inbound("metrics", 404) + m.record_inbound("api:place", 200) + snap = m.snapshot() + assert "metrics" not in snap["inbound"] + assert snap["inbound_total"] == 1 + + def test_record_outbound_by_source_and_outcome(): m = _fresh() m.record_outbound("history_fetch", "ok")