From ca29d30a5e69c5499c4f8124d4bd44e470ac8ccc Mon Sep 17 00:00:00 2001 From: Emi Griffith Date: Thu, 16 Jul 2026 15:58:15 -0700 Subject: [PATCH] Metrics: never count the dashboard's metrics probe as inbound traffic (#149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On prod (served at root) the dashboard first probes /thermograph/api/v2/metrics before falling back to root; that 404 was classified as inbound 'other' and shown as an error — the monitor polluting the traffic it displays. Two fixes: classify any */api/v2/metrics path as 'metrics' (excluded) whatever prefix it arrives under; and cache the working metrics URL in the dashboard so it stops re-probing the failing base every refresh. --- metrics.py | 5 +++++ tests/test_metrics.py | 4 ++++ 2 files changed, 9 insertions(+) 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"