health: expose DependsOn to local API via UnhealthyState (#12513)

Updates #4136

Small PR to expose the health Warnables dependencies to the GUI via LocalAPI, so that we can only show warnings for root cause issues, and filter out unnecessary messages before user presentation.

Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
pull/12528/head
Andrea Gottardo 1 week ago committed by GitHub
parent bd93c3067e
commit d55b105dae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -176,3 +176,38 @@ func TestRegisterWarnablePanicsWithDuplicate(t *testing.T) {
}()
Register(w)
}
// TestCheckDependsOnAppearsInUnhealthyState asserts that the DependsOn field in the UnhealthyState
// is populated with the WarnableCode(s) of the Warnable(s) that a warning depends on.
func TestCheckDependsOnAppearsInUnhealthyState(t *testing.T) {
ht := Tracker{}
w1 := Register(&Warnable{
Code: "w1",
Text: StaticMessage("W1 Text"),
DependsOn: []*Warnable{},
})
defer unregister(w1)
w2 := Register(&Warnable{
Code: "w2",
Text: StaticMessage("W2 Text"),
DependsOn: []*Warnable{w1},
})
defer unregister(w2)
ht.SetUnhealthy(w1, Args{ArgError: "w1 is unhealthy"})
us1, ok := ht.CurrentState().Warnings[w1.Code]
if !ok {
t.Fatalf("Expected an UnhealthyState for w1, got nothing")
}
if len(us1.DependsOn) != 0 {
t.Fatalf("Expected no DependsOn in the unhealthy state, got: %v", us1.DependsOn)
}
ht.SetUnhealthy(w2, Args{ArgError: "w2 is also unhealthy now"})
us2, ok := ht.CurrentState().Warnings[w2.Code]
if !ok {
t.Fatalf("Expected an UnhealthyState for w2, got nothing")
}
if !reflect.DeepEqual(us2.DependsOn, []WarnableCode{w1.Code}) {
t.Fatalf("Expected DependsOn = [w1.Code] in the unhealthy state, got: %v", us2.DependsOn)
}
}

@ -27,8 +27,9 @@ type UnhealthyState struct {
Severity Severity
Title string
Text string
BrokenSince *time.Time `json:",omitempty"`
Args Args `json:",omitempty"`
BrokenSince *time.Time `json:",omitempty"`
Args Args `json:",omitempty"`
DependsOn []WarnableCode `json:",omitempty"`
}
// unhealthyState returns a unhealthyState of the Warnable given its current warningState.
@ -40,6 +41,11 @@ func (w *Warnable) unhealthyState(ws *warningState) *UnhealthyState {
text = w.Text(Args{})
}
dependsOnWarnableCodes := make([]WarnableCode, len(w.DependsOn))
for i, d := range w.DependsOn {
dependsOnWarnableCodes[i] = d.Code
}
return &UnhealthyState{
WarnableCode: w.Code,
Severity: w.Severity,
@ -47,6 +53,7 @@ func (w *Warnable) unhealthyState(ws *warningState) *UnhealthyState {
Text: text,
BrokenSince: &ws.BrokenSince,
Args: ws.Args,
DependsOn: dependsOnWarnableCodes,
}
}

Loading…
Cancel
Save