diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md index 2732c86fad..04519c1e2d 100644 --- a/docs/release-control/v6/internal/subsystems/monitoring.md +++ b/docs/release-control/v6/internal/subsystems/monitoring.md @@ -9996,8 +9996,12 @@ scheduler, and an agent-only install has an empty queue. `ApplyHostReportWithStatus`, `ApplyDockerReport` and `ApplyKubernetesReport` record each apply's start and, on an error-free return, its completion in `agentReportApplyProgress`, under a lock never held during the apply. An apply -running for `agentReportApplyStallAfter` (three minutes) is wedged; when no -apply has completed since the most recently wedged one started, +running for `agentReportApplyStallAfter` (three minutes) is wedged. An apply +completion at or after the newest wedged start suppresses the stall only if +that completion is less than three minutes old. This is where the rules differ: +unlike a scheduled poll, +report intake has no next scheduled run to wait for, so one older completion +must not hide an apply that is still stuck. When there is an intake stall, `deadManMonitoringProgress` reports the earliest of the loop marker, the poll stall time and the intake stall time. A rejected report is not progress, an apply that panics still leaves the in-flight set, and no apply in flight is diff --git a/internal/monitoring/agent_report_apply_progress.go b/internal/monitoring/agent_report_apply_progress.go index 597641337c..3f02334902 100644 --- a/internal/monitoring/agent_report_apply_progress.go +++ b/internal/monitoring/agent_report_apply_progress.go @@ -51,13 +51,13 @@ func (p *agentReportApplyProgress) end(id uint64, at time.Time, completed bool) } } -// stall reports whether agent intake has stopped, using the same rule as the -// poll-claim check: an apply running for at least after is wedged, and intake -// is stalled when some apply is wedged and none has completed since the most -// recently wedged one started. Another agent's report completing since then -// keeps intake healthy, so one stuck report does not flap the watchdog while -// others still land. No applies in flight is never a stall. The returned time -// is the latest evidence that intake was moving. +// stall reports whether agent intake has stopped. An apply running for at +// least after is wedged. A successful completion since the newest wedged +// apply started shows that intake is still moving, but only for after. +// Unlike scheduled polling, intake has no next scheduled run to wait for. +// Without an expiry, a single completion can mask a wedge forever. No +// applies in flight is never a stall. The returned time is the latest +// evidence that intake was moving. func (p *agentReportApplyProgress) stall(now time.Time, after time.Duration) (time.Time, bool) { p.mu.Lock() defer p.mu.Unlock() @@ -75,7 +75,7 @@ func (p *agentReportApplyProgress) stall(now time.Time, after time.Duration) (ti if !wedged { return time.Time{}, false } - if !p.returnedAt.IsZero() && !p.returnedAt.Before(newestWedged) { + if !p.returnedAt.IsZero() && !p.returnedAt.Before(newestWedged) && now.Sub(p.returnedAt) < after { return time.Time{}, false } if p.returnedAt.After(oldest) { diff --git a/internal/monitoring/agent_report_apply_progress_test.go b/internal/monitoring/agent_report_apply_progress_test.go index 9b11f63f23..9a577ffbdb 100644 --- a/internal/monitoring/agent_report_apply_progress_test.go +++ b/internal/monitoring/agent_report_apply_progress_test.go @@ -80,6 +80,33 @@ func TestAgentReportApplyProgressStall(t *testing.T) { } }) + t.Run("a sibling completion expires while an apply is still stuck", func(t *testing.T) { + var p agentReportApplyProgress + hung := p.begin(now.Add(-2 * after)) + other := p.begin(now.Add(-time.Second)) + p.end(other, now, true) + + if _, stalled := p.stall(now.Add(after-time.Nanosecond), after); stalled { + t.Fatal("a recent successful apply should keep intake healthy") + } + rejected := p.begin(now.Add(after - time.Second)) + p.end(rejected, now.Add(after), false) + at, stalled := p.stall(now.Add(after), after) + if !stalled || !at.Equal(now) { + t.Fatalf("after successful completion expires: stall = %v at %v, want true at %v", stalled, at, now) + } + + other = p.begin(now.Add(after)) + p.end(other, now.Add(after+time.Second), true) + if _, stalled := p.stall(now.Add(after+time.Second), after); stalled { + t.Fatal("a new successful apply did not restore healthy intake") + } + p.end(hung, now.Add(2*after), false) + if _, stalled := p.stall(now.Add(3*after), after); stalled { + t.Fatal("an idle intake should not be reported as wedged") + } + }) + t.Run("failed return does not clear a stall", func(t *testing.T) { var p agentReportApplyProgress p.begin(now.Add(-after - time.Hour)) diff --git a/internal/monitoring/monitor_alerts.go b/internal/monitoring/monitor_alerts.go index efaa1c8d80..fea277a281 100644 --- a/internal/monitoring/monitor_alerts.go +++ b/internal/monitoring/monitor_alerts.go @@ -129,7 +129,7 @@ const deadManPollStallGrace = 2 * time.Minute // monitor loop's own ticker proves the loop is scheduling, but not that polls // return or that agent reports are applied: when every claimed poll has been // out past its timeout and none has come back, or agent report applies are -// wedged and none has completed since, report the earliest such progress +// wedged without a recent completion, report the earliest such progress // instead so the watchdog signals a stall rather than a healthy heartbeat. func (m *Monitor) deadManMonitoringProgress() time.Time { if m == nil {