diff --git a/feature/exitnodehealth/responsiveness_test.go b/feature/exitnodehealth/responsiveness_test.go index 2848f5141..3e8ca9375 100644 --- a/feature/exitnodehealth/responsiveness_test.go +++ b/feature/exitnodehealth/responsiveness_test.go @@ -169,6 +169,8 @@ func TestExitNodeResponsivenessLifecycle(t *testing.T) { e.evaluateResponsiveness(now) e.mu.Unlock() } + // End the warm-up period, during which warnings are hidden. + b.HealthTracker().SetIPNState(ipn.Running.String(), true) w := b.HealthTracker().CurrentState().Warnings[exitNodeUnresponsiveWarnable.Code] want := "The selected exit node \"my-gateway\" has not responded since " + start.WallTime().UTC().Format(time.RFC3339) + ". Internet connectivity may be affected." if w.Text != want { diff --git a/health/health.go b/health/health.go index e2c6e1c8a..30eb31271 100644 --- a/health/health.go +++ b/health/health.go @@ -269,10 +269,9 @@ type Warnable struct { // the Args of the unhappy state, just like we do in the Text function. Severity Severity // DependsOn is a set of Warnables that this Warnable depends on and need to be healthy - // before this Warnable is relevant. The GUI can use this information to ignore - // this Warnable if one of its dependencies is unhealthy. - // That is, if any of these Warnables are unhealthy, then this Warnable is not relevant - // and should be considered healthy to bother the user about. + // before this Warnable is relevant. If any of these Warnables are unhealthy, the [Tracker] + // treats this Warnable as healthy and omits it from [State] and [Tracker.Strings], + // so clients do not need to check the dependencies themselves. DependsOn []*Warnable // MapDebugFlag is a MapRequest.DebugFlag that is sent to control when this Warnable is unhealthy diff --git a/health/health_test.go b/health/health_test.go index b1bd4b0e3..e027f891c 100644 --- a/health/health_test.go +++ b/health/health_test.go @@ -449,6 +449,44 @@ func TestCheckDependsOnAppearsInUnhealthyState(t *testing.T) { } } +// TestWarmingUpHidesOtherWarnables asserts that unhealthy Warnables are omitted from +// [Tracker.CurrentState] and [Tracker.Strings] while the backend is warming up. +func TestWarmingUpHidesOtherWarnables(t *testing.T) { + ht := NewTracker(eventbustest.NewBus(t)) + w := Register(&Warnable{ + Code: "w", + Text: StaticMessage("W Text"), + }) + defer unregister(w) + + ht.SetIPNState("Starting", true) + ht.SetUnhealthy(w, nil) + + warnings := ht.CurrentState().Warnings + if _, ok := warnings[warmingUpWarnable.Code]; !ok { + t.Fatalf("warming-up warnable is not unhealthy; want unhealthy") + } + if _, ok := warnings[w.Code]; ok { + t.Errorf("w is unhealthy while warming up; want it hidden") + } + if got := ht.Strings(); slices.Contains(got, "W Text") { + t.Errorf("Strings() = %q while warming up; want w hidden", got) + } + + ht.SetIPNState("Running", true) + + warnings = ht.CurrentState().Warnings + if _, ok := warnings[warmingUpWarnable.Code]; ok { + t.Errorf("warming-up warnable is unhealthy in Running state; want healthy") + } + if _, ok := warnings[w.Code]; !ok { + t.Errorf("w is not unhealthy after warming up; want unhealthy") + } + if got := ht.Strings(); !slices.Contains(got, "W Text") { + t.Errorf("Strings() = %q after warming up; want w included", got) + } +} + func TestShowUpdateWarnable(t *testing.T) { tests := []struct { desc string @@ -1003,7 +1041,7 @@ func TestCurrentStateETagWarnable(t *testing.T) { newTracker := func(clock tstime.Clock) *Tracker { ht := NewTracker(eventbustest.NewBus(t)) ht.testClock = clock - ht.SetIPNState("NeedsLogin", true) + ht.SetIPNState("Running", true) ht.GotStreamedMapResponse() return ht } diff --git a/health/state.go b/health/state.go index 61d36797c..689876697 100644 --- a/health/state.go +++ b/health/state.go @@ -98,9 +98,8 @@ func (w *Warnable) unhealthyState(ws *warningState) *UnhealthyState { } if w != warmingUpWarnable { - // Here we tell the frontend that all Warnables depend on warmingUpWarnable. GUIs will silence all warnings until all - // their dependencies are healthy. This is a special case to prevent the GUI from showing a bunch of warnings when - // the backend is still warming up. + // All Warnables implicitly depend on warmingUpWarnable, so that we don't show a bunch of warnings + // while the backend is still warming up. See [Tracker.isEffectivelyHealthyLocked]. dependsOnWarnableCodes = append(dependsOnWarnableCodes, warmingUpWarnable.Code) } @@ -190,6 +189,10 @@ func (t *Tracker) isEffectivelyHealthyLocked(w *Warnable) bool { // Warnable not found in the tracker. So healthy. return true } + if w != warmingUpWarnable && t.warnableVal[warmingUpWarnable] != nil { + // Every Warnable implicitly depends on warmingUpWarnable. + return true + } for _, d := range w.DependsOn { if !t.isEffectivelyHealthyLocked(d) { // If one of our deps is unhealthy, we're healthy. diff --git a/health/warnings.go b/health/warnings.go index 416cb8ab0..bb6e7a242 100644 --- a/health/warnings.go +++ b/health/warnings.go @@ -288,8 +288,7 @@ var applyDiskConfigWarnable = condRegister(func() *Warnable { const warmingUpWarnableDuration = 5 * time.Second // warmingUpWarnable is a Warnable that is reported by the backend when it is starting up, for a maximum time of -// warmingUpWarnableDuration. The GUIs use the presence of this Warnable to prevent showing any other warnings until -// the backend is fully started. +// warmingUpWarnableDuration. While it is unhealthy, the [Tracker] treats all other Warnables as healthy. var warmingUpWarnable = condRegister(func() *Warnable { return &Warnable{ Code: tsconst.HealthWarnableWarmingUp,