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")