From 928fe568dd76df839101aaa0c653bb144343e32c Mon Sep 17 00:00:00 2001 From: iris Date: Wed, 25 Nov 2026 00:58:23 +0100 Subject: [PATCH] grafana: make the hive degraded alert name the critical warning The alert read the per-hive degraded gauge, so it could not say which warning raised it and sent the operator to a second alert. It now reads the critical warning series, one instance per kind, and the summary names the kind. The docs and the module-eval check follow. The message text is not in the alert, only in the hive-c0re log. --- .../scheduler/observability.md | 2 +- nix/host-modules/swarm-grafana.nix | 14 ++++++----- nix/module-eval/grafana.nix | 23 ++++++++++++++++++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/docs/4-implementation/scheduler/observability.md b/docs/4-implementation/scheduler/observability.md index 7123f4087..6a9eb7ca2 100644 --- a/docs/4-implementation/scheduler/observability.md +++ b/docs/4-implementation/scheduler/observability.md @@ -567,7 +567,7 @@ The swarm Grafana (`nix/host-modules/swarm-grafana.nix`) alerts on these: | Alert | Fires when | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `hh-hive-degraded` | `hyperhive.hive.degraded` is `1` for 2 minutes | +| `hh-hive-degraded` | any `hyperhive.hive.warning` series at level `crit` exists for 2 minutes, one alert per `kind` | | `hh-hive-warning` | any `hyperhive.hive.warning` series other than `disk_pressure` exists (`pending_logins` only for a hive that doesn't export `hyperhive.agent.needs_login`) for 2 minutes | | `hh-agent-needs-login` | `hyperhive.agent.needs_login` is `1` for an agent for 5 minutes, one alert per agent | | `hh-agent-oom-kills` | `hyperhive.container.memory.oom_kills` grew by more than 3 in the last hour for an agent, one alert per agent, no delay | diff --git a/nix/host-modules/swarm-grafana.nix b/nix/host-modules/swarm-grafana.nix index 797315c74..6b3774634 100644 --- a/nix/host-modules/swarm-grafana.nix +++ b/nix/host-modules/swarm-grafana.nix @@ -1754,18 +1754,20 @@ in for = "0s"; summary = "{{ $labels._HOSTNAME }} detected agent {{ $labels.F_AGENT }}'s container crash (not an operator-initiated stop)"; }) - # hive-c0re's own readiness verdict (`hyperhive.hive.degraded` - # in otel_metrics.rs), the same one `/health/ready` gives: - # `1` while any `crit`-level warning is raised. The - # per-kind rule below says which one. `for` rides out a + # hive-c0re's readiness verdict, the one `/health/ready` + # gives: degraded while any `crit`-level warning is raised. + # Read from the per-warning series (`hyperhive.hive.warning`) + # rather than the `hyperhive.hive.degraded` gauge, so each + # critical `kind` is its own instance and the alert names + # the warning that triggered it. `for` rides out a # restart-time blip. (metricThresholdRule { uid = "hh-hive-degraded"; title = "hive degraded"; - expr = ''max by (sender) ({__name__="hyperhive.hive.degraded"})''; + expr = ''max by (sender, kind) ({__name__="hyperhive.hive.warning", level="crit"})''; threshold = 0; for = "2m"; - summary = "{{ $labels.sender }} reports itself degraded: a critical warning is raised; the `hh-hive-warning` alert names it"; + summary = "{{ $labels.sender }} is degraded by the critical warning {{ $labels.kind }}; the message is the `hive warning raised` line in the hive-c0re log"; }) # One series per raised warning (`hyperhive.hive.warning`), # so each `kind` is its own alert instance. The text is the diff --git a/nix/module-eval/grafana.nix b/nix/module-eval/grafana.nix index 452a4d529..5dfde06e8 100644 --- a/nix/module-eval/grafana.nix +++ b/nix/module-eval/grafana.nix @@ -964,7 +964,7 @@ let rules = lib.concatMap (g: g.rules) groups; source = builtins.readFile ../../hive-c0re/src/stats/otel_metrics.rs; expected = { - "hh-hive-degraded" = "hyperhive.hive.degraded"; + "hh-hive-degraded" = "hyperhive.hive.warning"; "hh-hive-warning" = "hyperhive.hive.warning"; "hh-host-disk-high" = "hyperhive.hive.nix_store.utilization"; "hh-host-disk-critical" = "hyperhive.hive.nix_store.utilization"; @@ -983,6 +983,27 @@ let in lib.all (uid: check uid expected.${uid}) (builtins.attrNames expected); } + { + # The degraded alert is one instance per critical warning, so its + # summary can name the `kind` that triggered it: it reads the + # per-warning series restricted to `crit`, grouped by `kind`, and the + # summary spells the label. + # 🔬 Invert-proof: drop `kind` from `max by`, the `level="crit"` + # selector, or the `$labels.kind` in the summary of `hh-hive-degraded`. + name = "the hive degraded alert names the critical warning that triggered it"; + ok = + let + groups = + grafanaHere.containers.swarm-grafana.config.services.grafana.provision.alerting.rules.settings.groups; + rules = lib.concatMap (g: g.rules) groups; + rule = lib.findFirst (r: r.uid == "hh-hive-degraded") null rules; + expr = (lib.head rule.data).model.expr; + in + rule != null + && lib.hasInfix "max by (sender, kind)" expr + && lib.hasInfix ''level="crit"'' expr + && lib.hasInfix "labels.kind" rule.annotations.summary; + } { # The cert-lifetime alert fires at a lifetime fraction over 0.8 and # selects the two gauge names `swarm-secret-client` spells in Rust; a