Files
matsandClaude Sonnet 5.5 7fd6a7e7a5 Add a Grafana dashboard for the resolver's metrics
With traffic charts gone from the console, deploy/grafana/fancy-dns.json is
where they live: queries by outcome, transport and client group, latency
quantiles, RCODEs, cache hits/misses/stale, the upstream round trips saved by
coalescing and early refresh, upstream health and latency, blocklist and zone
sizes, and (in a Loki row) the blocked/failed-query access log. A node variable
spreads or narrows every panel, and the per-node panel shows whether load is
even across pods.

A test reads the dashboard and fails if a panel queries a metric the resolver
does not export, so a rename cannot silently empty a panel.

The ingress no longer needs the SSE buffering/timeout annotations, and the
statefulset comments no longer describe a query log on the volume.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-16 09:57:38 +02:00

48 lines
1.3 KiB
Go

package metrics
import (
"os"
"regexp"
"strings"
"testing"
"github.com/prometheus/client_golang/prometheus"
)
// TestGrafanaDashboardOnlyUsesMetricsThatExist keeps deploy/grafana/fancy-dns.json
// from drifting away from the collectors: a renamed metric would otherwise
// leave a panel empty and nothing would say why.
func TestGrafanaDashboardOnlyUsesMetricsThatExist(t *testing.T) {
initCollectors()
descs := make(chan *prometheus.Desc, 256)
go func() { Registry.Describe(descs); close(descs) }()
known := map[string]bool{}
nameRe := regexp.MustCompile(`fqName: "([a-z0-9_]+)"`)
for d := range descs {
if m := nameRe.FindStringSubmatch(d.String()); m != nil {
known[m[1]] = true
}
}
if !known["fancydns_queries_total"] {
t.Fatalf("collector names were not read; got %v", known)
}
raw, err := os.ReadFile("../../deploy/grafana/fancy-dns.json")
if err != nil {
t.Fatal(err)
}
used := regexp.MustCompile(`fancydns_[a-z0-9_]+`).FindAllString(string(raw), -1)
if len(used) == 0 {
t.Fatal("the dashboard references no fancydns metrics")
}
for _, name := range used {
base := name
for _, suffix := range []string{"_bucket", "_count", "_sum"} {
base = strings.TrimSuffix(base, suffix)
}
if !known[base] {
t.Errorf("the dashboard queries %s, which the resolver does not export", name)
}
}
}