Federation dashboard (phase 1, step 7)
CI / validate-monitoring (push) Successful in 7s
CI / lint (push) Successful in 10s
CI / test (push) Successful in 1m5s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s

A fifth provisioned Grafana dashboard: fediverse lookups by kind and
result, sharing switched on/off, federation endpoint rates and p95
latency, and inbox deliveries. Dashboard tests now know federation's
own metrics, and a new test rejects PromQL string escapes Prometheus
can't parse (the endpoint filter first used \. and failed live).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
mattandClaude Opus 5.5 committed 2026-09-25 20:36:42 +01:00
1 parent f21ce173b8
commit 913ef67aca
2 files changed
+347 -3

No files matched your search

+20 -3
View File
@@ -7,6 +7,7 @@ import yaml
from prometheus_client.metrics import MetricWrapperBase
from scrobbler import metrics
from scrobbler.federation import metrics as federation_metrics
DEPLOY = Path(__file__).resolve().parents[1] / "deploy"
DASHBOARDS = sorted((DEPLOY / "grafana" / "dashboards").glob("*.json"))
@@ -16,7 +17,8 @@ METRIC_NAME = re.compile(r"\bscrobbler_[a-z0-9_]+")
def defined_series() -> set[str]:
"""Every series name the service can export."""
names = set(metrics.COLLECTED.values())
for value in vars(metrics).values():
modules = (metrics, federation_metrics)
for value in (v for module in modules for v in vars(module).values()):
if not isinstance(value, MetricWrapperBase):
continue
name, kind = value._name, value._type
@@ -41,8 +43,14 @@ def exprs(node):
yield from exprs(item)
def test_there_are_four_dashboards():
assert {p.stem for p in DASHBOARDS} == {"api-overview", "lastfm-api", "usage", "database"}
def test_the_expected_dashboards_exist():
assert {p.stem for p in DASHBOARDS} == {
"api-overview",
"lastfm-api",
"usage",
"database",
"federation",
}
def test_dashboard_uids_are_unique():
@@ -75,3 +83,12 @@ def test_alert_rules_only_use_defined_metrics():
for name in METRIC_NAME.findall(rule["expr"])
}
assert used <= defined_series(), f"undefined metrics: {sorted(used - defined_series())}"
@pytest.mark.parametrize("path", DASHBOARDS, ids=lambda p: p.stem)
def test_queries_have_no_invalid_string_escapes(path):
"""PromQL rejects escapes like \\. inside double-quoted strings (Grafana would show a
query error); use a character class such as [.] instead."""
invalid = re.compile(r'(?<!\\)\\[^\\"nrtabfvxuU0-7]')
for expr in exprs(json.loads(path.read_text())):
assert not invalid.search(expr), f"invalid escape in {path.name}: {expr}"