Metrics: never count the dashboard's metrics probe as inbound traffic (#149)

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.
This commit is contained in:
Emi Griffith 2026-07-16 15:58:15 -07:00 committed by GitHub
parent 2b2d0431ba
commit ca29d30a5e
2 changed files with 9 additions and 0 deletions

View file

@ -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/"):

View file

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