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:
@@ -56,19 +56,20 @@ func NewHostStalenessChecker(s *store.Store, threshold time.Duration, onEvent Ev
|
||||
}
|
||||
sc.customerOf[row.HostID] = row.CustomerID
|
||||
age := time.Since(row.LastReportAt)
|
||||
// F2: seed only HEALTHY hosts. A host already stale/down at (re)start is left UNSEEDED so the
|
||||
// first Check() observes oldState=="" and emits once (a box that went silent while the hub was
|
||||
// down would otherwise stay silent). The dispatcher's 1h cooldown dedups the re-emit.
|
||||
switch {
|
||||
case age > sc.downAfter:
|
||||
sc.states[row.HostID] = "down"
|
||||
downCount++
|
||||
case age > sc.threshold:
|
||||
sc.states[row.HostID] = "stale"
|
||||
staleCount++
|
||||
default:
|
||||
sc.states[row.HostID] = "ok"
|
||||
okCount++
|
||||
}
|
||||
}
|
||||
logger.Printf("[INFO] Host staleness checker initialized: %d ok, %d stale, %d down", okCount, staleCount, downCount)
|
||||
logger.Printf("[INFO] Host staleness checker initialized: %d ok, %d stale, %d down (stale/down left unseeded → first Check emits)", okCount, staleCount, downCount)
|
||||
return sc
|
||||
}
|
||||
|
||||
@@ -105,7 +106,13 @@ func (sc *HostStalenessChecker) Check() {
|
||||
|
||||
oldState := sc.states[row.HostID]
|
||||
if oldState == "" {
|
||||
sc.states[row.HostID] = newState // first observation — no event
|
||||
// F2: first observation (incl. a hub restart). Healthy seeds silently; a host already
|
||||
// stale/down at first sight emits once (else a box that went silent while the hub was
|
||||
// down would never alert). The dispatcher's 1h cooldown dedups a re-emit on hub restart.
|
||||
sc.states[row.HostID] = newState
|
||||
if newState != "ok" {
|
||||
sc.emitTransition(row.HostID, row.CustomerID, "unknown", newState, age)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if oldState == newState {
|
||||
|
||||
Reference in New Issue
Block a user