Watch
0
0
Fork
You've already forked hyperhive
0

hive-c0re: hive warnings reach the operator as metrics and alerts, not a banner

The dashboard's top-of-page warning banner is gone. The warning registry
stays, because /health/ready, the swarm status view and the OTEL gauges
read it. What it feeds is now alerted on in Grafana:

- hyperhive.hive.warning{kind,level}: one series per raised warning, so an
  alert names the cause. Raising a warning also logs one `hive warning
  raised` line with the message.
- hyperhive.hive.nix_store.utilization: the used fraction of the nix
  store's filesystem, probed in the gauge callback.
- Alerts: hh-hive-degraded on the existing degraded gauge, hh-hive-warning
  per kind (disk excluded), hh-host-disk-high at 85% and
  hh-host-disk-critical at 95%.
- pending_logins is now a registry warning, refreshed from the container
  rescan, so it reaches the per-kind gauge.

Frontend: server_warnings leaves the state snapshot, and the dashboard,
flow and stats pages keep only the sticky chrome wrapper. The shared
hive-warn and WarnBanner components stay, since other views use them.

A module-eval case checks each alert's metric name against the exporter's
source, so a rename on either side fails the build.
This commit is contained in:
iris 2026-10-21 17:52:53 +02:00
commit 4dbcf6fa80

View file

@ -5,14 +5,14 @@
//! gateway nginx writes, per-agent branch protection, …) historically
//! `warn!`'d to the journal and moved on, so a persistent failure was
//! invisible to the operator. [`SweepHealth`] routes that failure to the
//! dashboard banner instead — but *debounced*, per the routing guidance in
//! hive warning instead — but *debounced*, per the routing guidance in
//! the tracker issue:
//!
//! - a transient miss (container down mid-sweep, a network blip) shouldn't
//! flap a banner on the first failure → `threshold > 1` raises only after
//! flap a warning on the first failure → `threshold > 1` raises only after
//! that many **consecutive** misses;
//! - a won't-fix-itself failure (missing team, bad config, auth rejection)
//! should banner immediately → `threshold == 1`.
//! should warning immediately → `threshold == 1`.
//!
//! The warning clears the moment the sweep next succeeds. A sweep owns one
//! `SweepHealth`, calls [`record_ok`](SweepHealth::record_ok) on success and
@ -24,11 +24,11 @@ use std::time::{Duration, Instant};
use crate::warnings::{WarningGuard, set_warning};
/// Per-sweep failure context handed to the [`record_err`](SweepHealth::record_err)
/// message builder so the banner text can include how long the sweep has been
/// message builder so the warning text can include how long the sweep has been
/// failing and since when it last worked.
#[derive(Debug, Clone, Copy)]
pub struct SweepFailure {
/// Number of consecutive failures so far (≥ `threshold` when the banner
/// Number of consecutive failures so far (≥ `threshold` when the warning
/// is raised).
pub consecutive: u32,
/// Time since the last recorded success, if the sweep has ever succeeded
@ -36,7 +36,7 @@ pub struct SweepFailure {
pub since_last_ok: Option<Duration>,
}
/// A debounced link between one background sweep and the warning banner.
/// A debounced link between one background sweep and the warning warning.
/// Not `Sync`-shared: each sweep task owns its own instance (the underlying
/// registry is the shared, thread-safe part).
pub struct SweepHealth {
@ -50,8 +50,8 @@ pub struct SweepHealth {
impl SweepHealth {
/// Track sweep `kind` at severity `level` (`"warn"` / `"crit"`), raising
/// the banner after `threshold` consecutive failures. `threshold` is
/// floored at 1 (0 would banner before any failure).
/// the warning after `threshold` consecutive failures. `threshold` is
/// floored at 1 (0 would warning before any failure).
#[must_use]
pub fn new(kind: &'static str, level: &'static str, threshold: u32) -> Self {
Self {
@ -65,7 +65,7 @@ impl SweepHealth {
}
/// Record a successful sweep: reset the consecutive-miss counter and drop
/// the guard (clearing any banner entry).
/// the guard (clearing any warning entry).
pub fn record_ok(&mut self) {
self.misses = 0;
self.last_ok = Some(Instant::now());
@ -74,9 +74,9 @@ impl SweepHealth {
}
/// Record a failed sweep. Bumps the consecutive-miss counter; once it
/// reaches `threshold`, raises (or refreshes) the banner warning built by
/// reaches `threshold`, raises (or refreshes) the warning warning built by
/// `message`. Below the threshold this is a cheap no-op — `message` is
/// only invoked when the banner is actually shown, so callers can format
/// only invoked when the warning is actually shown, so callers can format
/// lazily.
pub fn record_err(&mut self, message: impl FnOnce(SweepFailure) -> String) {
self.misses = self.misses.saturating_add(1);
@ -96,7 +96,7 @@ impl SweepHealth {
}
/// Compact human-readable age (e.g. `"45s"`, `"12m"`, `"3h"`, `"2d"`) for a
/// banner "last succeeded N ago" suffix. Coarse on purpose — the banner wants
/// warning "last succeeded N ago" suffix. Coarse on purpose — the warning wants
/// a glanceable magnitude, not precision.
#[must_use]
pub fn fmt_age(d: Duration) -> String {
@ -117,7 +117,7 @@ mod tests {
use super::*;
use crate::warnings::snapshot;
fn banner(kind: &str) -> Option<String> {
fn warning(kind: &str) -> Option<String> {
snapshot()
.into_iter()
.find(|w| w.kind == kind)
@ -125,34 +125,34 @@ mod tests {
}
#[test]
fn below_threshold_does_not_banner() {
fn below_threshold_does_not_warn() {
let mut h = SweepHealth::new("sh_below", "warn", 3);
h.record_err(|_| "boom".to_owned());
h.record_err(|_| "boom".to_owned());
assert!(h.guard.is_none());
assert!(banner("sh_below").is_none());
assert!(warning("sh_below").is_none());
}
#[test]
fn raises_at_threshold_and_clears_on_ok() {
let mut h = SweepHealth::new("sh_raise", "warn", 2);
h.record_err(|c| format!("fail #{}", c.consecutive));
assert!(banner("sh_raise").is_none(), "one miss < threshold");
assert!(warning("sh_raise").is_none(), "one miss < threshold");
h.record_err(|c| format!("fail #{}", c.consecutive));
assert_eq!(banner("sh_raise").as_deref(), Some("fail #2"));
assert_eq!(warning("sh_raise").as_deref(), Some("fail #2"));
assert!(h.guard.is_some());
h.record_ok();
assert!(h.guard.is_none());
assert!(banner("sh_raise").is_none(), "success clears the banner");
assert!(warning("sh_raise").is_none(), "success clears the warning");
}
#[test]
fn threshold_one_banners_immediately() {
fn threshold_one_warns_immediately() {
let mut h = SweepHealth::new("sh_immediate", "crit", 1);
h.record_err(|_| "gone".to_owned());
assert_eq!(banner("sh_immediate").as_deref(), Some("gone"));
assert_eq!(warning("sh_immediate").as_deref(), Some("gone"));
h.record_ok();
assert!(banner("sh_immediate").is_none());
assert!(warning("sh_immediate").is_none());
}
#[test]
@ -161,9 +161,9 @@ mod tests {
h.record_err(|_| "x".to_owned()); // miss 1
h.record_ok(); // reset
h.record_err(|c| format!("c={}", c.consecutive)); // miss 1 again, < threshold
assert!(banner("sh_reset").is_none(), "counter reset after ok");
assert!(warning("sh_reset").is_none(), "counter reset after ok");
h.record_err(|c| format!("c={}", c.consecutive)); // miss 2 → raise
assert_eq!(banner("sh_reset").as_deref(), Some("c=2"));
assert_eq!(warning("sh_reset").as_deref(), Some("c=2"));
h.record_ok();
}
@ -171,9 +171,9 @@ mod tests {
fn refresh_updates_message_while_held() {
let mut h = SweepHealth::new("sh_refresh", "warn", 1);
h.record_err(|c| format!("miss {}", c.consecutive));
assert_eq!(banner("sh_refresh").as_deref(), Some("miss 1"));
assert_eq!(warning("sh_refresh").as_deref(), Some("miss 1"));
h.record_err(|c| format!("miss {}", c.consecutive));
assert_eq!(banner("sh_refresh").as_deref(), Some("miss 2"));
assert_eq!(warning("sh_refresh").as_deref(), Some("miss 2"));
h.record_ok();
}