hub: F2 — alert on host already degraded/stale at (re)start (seed only healthy) v0.21.0

Constructors seed only healthy hosts; an already-degraded/stale host is left unseeded so the first
Check() emits once (cooldown dedups on hub restart). Born-degraded red-proof + staleness test updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pg8ANF97SEeKYSN5Jxw3qJ
This commit is contained in:
2026-06-29 21:46:25 +02:00
parent a297639c58
commit 12f038618e
5 changed files with 79 additions and 16 deletions
+12 -7
View File
@@ -42,20 +42,25 @@ func TestHostStalenessChecker(t *testing.T) {
events = append(events, eventType)
}
// Seed already-stale (40m) → state stale, but NO event on init.
// F2: already-stale (40m) at construction → left UNSEEDED (not seeded "stale"), NO event on init.
backdate(t, db, "h1", 40)
sc := NewHostStalenessChecker(st, 30*time.Minute, onEvent, log.New(io.Discard, "", 0))
if len(events) != 0 {
t.Fatalf("seed must not emit events, got %v", events)
t.Fatalf("construction must not emit, got %v", events)
}
if sc.GetState("h1") != "stale" {
t.Fatalf("seeded state = %q, want stale", sc.GetState("h1"))
if sc.GetState("h1") != "unknown" {
t.Fatalf("born-stale must be left unseeded, GetState = %q want unknown", sc.GetState("h1"))
}
// Same age → no transition.
// F2: the FIRST Check on a born-stale host emits host_stale once (persistent-down alerting).
sc.Check()
if len(events) != 0 {
t.Fatalf("no transition expected, got %v", events)
if len(events) != 1 || last(events) != "host_stale" {
t.Fatalf("born-stale first Check → one host_stale, got %v", events)
}
// Steady stale → no duplicate.
sc.Check()
if len(events) != 1 {
t.Fatalf("steady stale must not re-emit, got %v", events)
}
// Fresh report → host_recovered.