Watch
0
0
Fork
You've already forked hyperhive
0

module-eval: grafana and swarm-otel cases follow the sender stamp

This commit is contained in:
atlas 2026-11-22 23:51:34 +01:00 • committed by mara
commit c529bab9ea
2 changed files with 70 additions and 16 deletions

View file

@ -663,10 +663,10 @@ let
) tables; ) tables;
} }
{ {
# The host board ships, and every query filters on both template # The host board ships, and every query filters on the host template
# variables: a panel missing one shows another hive's or host's numbers # variable: a panel missing it shows another host's numbers
# under this selection. # under this selection. No `hive` label exists to filter on.
name = "the host dashboard ships, and every panel query filters on hive and host"; name = "the host dashboard ships, and every panel query filters on host";
ok = ok =
let let
provider = lib.head grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana.provision.dashboards.settings.providers; provider = lib.head grafanaWithAuthelia.containers.swarm-grafana.config.services.grafana.provision.dashboards.settings.providers;
@ -676,9 +676,55 @@ let
in in
lib.elem "host.json" shipped lib.elem "host.json" shipped
&& lib.length exprs > 0 && lib.length exprs > 0
&& lib.all (e: lib.hasInfix "hive=~\"$hive\"" e && lib.hasInfix "\"host.name\"=~\"$host\"" e) exprs && lib.all (e: !(lib.hasInfix "hive=~" e) && lib.hasInfix "\"host.name\"=~\"$host\"" e) exprs
&& lib.any (e: lib.hasInfix "system.cpu.time" e) exprs; && lib.any (e: lib.hasInfix "system.cpu.time" e) exprs;
} }
{
# Each hive's collector gets its own absence rule, keyed on the client id
# the swarm collector stamps as `sender`, so a hive that sends nothing
# still has an instance to fire. The roster is read from the fixture, and
# the length clause keeps the `all` from holding over an empty one.
# 🔬 Invert-proof: key the rule on `hive`, or drop the client prefix.
name = "each hive's log-absence rule keys on the sender the swarm collector stamps";
ok =
let
h = grafanaHere.services.hyperhive;
groups =
grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups;
rules = lib.concatMap (g: g.rules) groups;
expr =
uid:
(lib.head (lib.findFirst (r: r.uid == uid) { data = [ { model.expr = ""; } ]; } rules).data)
.model.expr;
hives = lib.attrNames h.swarm.hives;
in
lib.length hives > 0
&& lib.all (
n: lib.hasInfix ''sender:="${h.swarm.authelia.hiveClientPrefix}${n}"'' (expr "hh-logs-absent-${n}")
) hives
&& !(lib.any (n: lib.hasInfix "hive:" (expr "hh-logs-absent-${n}")) hives);
}
{
# `hive` is no label of any stored series, so a dashboard that selects or
# groups by it shows nothing. The agents board is the presence control:
# it filters on `agent`, so a misspelt path cannot pass the absence arm.
name = "no shipped dashboard selects or groups by a hive label";
ok =
let
dir = ../host-modules/swarm-grafana/dashboards;
names = lib.attrNames (
lib.filterAttrs (n: t: t == "regular" && lib.hasSuffix ".json" n) (builtins.readDir dir)
);
text = n: builtins.readFile (dir + "/${n}");
# Not `lib.hasInfix`: it is a regex match, which overflows the stack on a whole board.
has = needle: s: builtins.replaceStrings [ needle ] [ "" ] s != s;
in
lib.length names > 20
&& has "agent=~\\\"$agent\\\"" (text "agents.json")
&& lib.all (
n: !(has "hive=~" (text n)) && !(has "by (hive" (text n)) && !(has ", hive)" (text n))
) names;
}
{ {
# The egress board ships, and its queries read the two squid log lines as # The egress board ships, and its queries read the two squid log lines as
# squid writes them: the would_deny line's field layout, and the default # squid writes them: the would_deny line's field layout, and the default
@ -860,7 +906,7 @@ let
rule != null rule != null
&& lib.hasInfix ''_SYSTEMD_UNIT:="hive-agent.service"'' expr && lib.hasInfix ''_SYSTEMD_UNIT:="hive-agent.service"'' expr
&& lib.hasInfix ''_msg:="turn failed"'' expr && lib.hasInfix ''_msg:="turn failed"'' expr
&& lib.hasInfix "stats by (hive, agent)" expr; && lib.hasInfix "stats by (agent)" expr;
} }
{ {
# A classifier run without a verdict is visible only as these log # A classifier run without a verdict is visible only as these log
@ -994,14 +1040,14 @@ let
&& lib.hasInfix "max by (account, window)" expr; && lib.hasInfix "max by (account, window)" expr;
} }
{ {
# The needs-login alert is one instance per (hive, agent), fires after # The needs-login alert is one instance per agent, fires after
# 5 minutes on the gauge hive-c0re exports, and `hh-hive-warning` drops # 5 minutes on the gauge hive-c0re exports, and `hh-hive-warning` drops
# `pending_logins` only for hives that export the gauge, so a login never # `pending_logins` only for hives that export the gauge, so a login never
# pages twice and a hive on an older hive-c0re still pages. The disk rule is # pages twice and a hive on an older hive-c0re still pages. The disk rule is
# the presence control: it goes through the same lookup. # the presence control: it goes through the same lookup.
# 🔬 Invert-proof: change `for`, `max by (hive, agent)` or the metric on # 🔬 Invert-proof: change `for`, `max by (agent)` or the metric on
# `hh-agent-needs-login`, exclude `pending_logins` from `hh-hive-warning` for every hive # `hh-agent-needs-login`, exclude `pending_logins` from `hh-hive-warning` for every hive
# instead of per hive (drop the `unless on (hive)` clause), or rename the gauge in `otel_metrics.rs`. # instead of per hive (drop the `unless on (sender)` clause), or rename the gauge in `otel_metrics.rs`.
name = "the needs-login alert is per agent, fires after 5 minutes and the hive warning rule skips pending_logins only for hives with the gauge"; name = "the needs-login alert is per agent, fires after 5 minutes and the hive warning rule skips pending_logins only for hives with the gauge";
ok = ok =
let let
@ -1018,19 +1064,19 @@ let
&& rule "hh-host-disk-high" != null && rule "hh-host-disk-high" != null
&& lib.hasInfix ''{__name__="hyperhive.agent.needs_login"}'' (expr "hh-agent-needs-login") && lib.hasInfix ''{__name__="hyperhive.agent.needs_login"}'' (expr "hh-agent-needs-login")
&& lib.hasInfix ''"hyperhive.agent.needs_login"'' source && lib.hasInfix ''"hyperhive.agent.needs_login"'' source
&& lib.hasInfix "max by (hive, agent)" (expr "hh-agent-needs-login") && lib.hasInfix "max by (agent)" (expr "hh-agent-needs-login")
&& lib.hasInfix ''{__name__="hyperhive.hive.warning", kind="pending_logins"} unless on (hive) group by (hive) ({__name__="hyperhive.agent.needs_login"})'' ( && lib.hasInfix ''{__name__="hyperhive.hive.warning", kind="pending_logins"} unless on (sender) group by (sender) ({__name__="hyperhive.agent.needs_login"})'' (
expr "hh-hive-warning" expr "hh-hive-warning"
) )
&& lib.hasInfix "disk_pressure" (expr "hh-hive-warning"); && lib.hasInfix "disk_pressure" (expr "hh-hive-warning");
} }
{ {
# The OOM-kill alert is one instance per (hive, agent), fires over three # The OOM-kill alert is one instance per agent, fires over three
# kills in the last hour with no `for`, and selects the counter name # kills in the last hour with no `for`, and selects the counter name
# `otel_metrics.rs` spells in Rust. The needs-login rule is the presence # `otel_metrics.rs` spells in Rust. The needs-login rule is the presence
# control: it goes through the same lookup, so a misspelled attribute path # control: it goes through the same lookup, so a misspelled attribute path
# fails both arms. # fails both arms.
# 🔬 Invert-proof: change `threshold = 3`, `for`, `[1h]` or `sum by (hive, agent)` # 🔬 Invert-proof: change `threshold = 3`, `for`, `[1h]` or `sum by (agent)`
# on `hh-agent-oom-kills`, or rename the counter in `otel_metrics.rs`. # on `hh-agent-oom-kills`, or rename the counter in `otel_metrics.rs`.
name = "the OOM-kill alert fires over three kills an hour per agent on the counter hive-c0re exports"; name = "the OOM-kill alert fires over three kills an hour per agent on the counter hive-c0re exports";
ok = ok =
@ -1051,7 +1097,7 @@ let
&& lib.hasInfix ''{__name__="hyperhive.container.memory.oom_kills"'' (query "hh-agent-oom-kills") && lib.hasInfix ''{__name__="hyperhive.container.memory.oom_kills"'' (query "hh-agent-oom-kills")
.model.expr .model.expr
&& lib.hasInfix "[1h]" (query "hh-agent-oom-kills").model.expr && lib.hasInfix "[1h]" (query "hh-agent-oom-kills").model.expr
&& lib.hasInfix "sum by (hive, agent)" (query "hh-agent-oom-kills").model.expr && lib.hasInfix "sum by (agent)" (query "hh-agent-oom-kills").model.expr
&& lib.hasInfix ''"hyperhive.container.memory.oom_kills"'' source && lib.hasInfix ''"hyperhive.container.memory.oom_kills"'' source
&& (query "hh-agent-oom-kills").model.instant && (query "hh-agent-oom-kills").model.instant
&& lib.hasInfix "{{ $labels.agent }}" oom.annotations.summary; && lib.hasInfix "{{ $labels.agent }}" oom.annotations.summary;

View file

@ -697,14 +697,22 @@ let
# names spelled here: an arm naming `h1` passes on a single-hive # names spelled here: an arm naming `h1` passes on a single-hive
# config however the mapping is written. The length clause is what # config however the mapping is written. The length clause is what
# makes the `all` mean anything — over an empty roster it holds # makes the `all` mean anything — over an empty roster it holds
# vacuously. # vacuously. The receiver arm covers the swarm tier's and each service
# forwarder's too, which the roster does not name; the swarm tier's own
# receiver is the presence control for it.
name = "every authenticated receiver, each hive's included, feeds the sender-stamping logs and metrics pipelines"; name = "every authenticated receiver, each hive's included, feeds the sender-stamping logs and metrics pipelines";
ok = ok =
let let
p = (otelSettings otelTwoHives).service.pipelines; s = otelSettings otelTwoHives;
p = s.service.pipelines;
hives = lib.attrNames otelTwoHives.services.hyperhive.swarm.hives; hives = lib.attrNames otelTwoHives.services.hyperhive.swarm.hives;
otlp = lib.filter (lib.hasPrefix "otlp/") (lib.attrNames s.receivers);
in in
lib.length hives == 2 lib.length hives == 2
&& lib.elem "otlp/swarm" otlp
&& lib.all (
r: lib.elem r p."logs/authenticated".receivers && lib.elem r p."metrics/authenticated".receivers
) otlp
&& lib.all ( && lib.all (
h: h:
lib.elem "otlp/${h}" p."logs/authenticated".receivers lib.elem "otlp/${h}" p."logs/authenticated".receivers