diff --git a/metrics.py b/metrics.py index 5429dc8..f772c19 100644 --- a/metrics.py +++ b/metrics.py @@ -98,6 +98,11 @@ def classify_inbound(path: str, base: str = "") -> str: the app's mount prefix (e.g. ``/thermograph`` or ``""``). """ p = path or "/" + # The dashboard polls the metrics endpoint; never count it as traffic, whatever base + # prefix it arrives under — e.g. a `/thermograph/api/v2/metrics` probe against a + # root-served prod app would otherwise land in "other" and show as an inbound error. + if p.rstrip("/").endswith("/api/v2/metrics"): + return "metrics" if base and p.startswith(base): p = p[len(base):] or "/" if p.startswith("/api/"): diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 1f81909..e15aad3 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -34,6 +34,10 @@ def test_classify_inbound_categories(): assert c("/thermograph/api/v2/notifications", "/thermograph") == "accounts" assert c("/thermograph/api/v2/push/subscribe", "/thermograph") == "accounts" assert c("/thermograph/api/v2/metrics", "/thermograph") == "metrics" + # The metrics endpoint is never counted, even under an unexpected prefix — e.g. the + # dashboard probing /thermograph/... against a root-served (base="") prod app. + assert c("/thermograph/api/v2/metrics", "") == "metrics" + assert c("/api/v2/metrics", "") == "metrics" # pages, static, seo assert c("/thermograph/", "/thermograph") == "page" assert c("/thermograph/calendar", "/thermograph") == "page"