Alerting: Fix stale values associated with states that have gone to NoData, unify values calculation (#89807)

* Unify values

* Fix with latest changes on main

* Fix up NaN test

* Keep refIDs with -1 as value

* Test that refIDs are preserved on Normal to Error transition

* Alerting to err test too

* Add a blurb to docs about this behavior
This commit is contained in:
Alexander Weaver
2024-07-08 12:30:23 -05:00
committed by GitHub
parent f763f2085b
commit 3b6a8775bb
11 changed files with 209 additions and 82 deletions

View File

@@ -48,7 +48,7 @@ func Test_FormatValues(t *testing.T) {
name: "with no value, it renders the evaluation string",
alertState: &state.State{
LastEvaluationString: "[ var='A' metric='vector(10) + time() % 50' labels={} value=1.1 ]",
LatestResult: &state.Evaluation{Condition: "A", Values: map[string]*float64{}},
LatestResult: &state.Evaluation{Condition: "A", Values: map[string]float64{}},
},
expected: "[ var='A' metric='vector(10) + time() % 50' labels={} value=1.1 ]",
},
@@ -56,7 +56,7 @@ func Test_FormatValues(t *testing.T) {
name: "with one value, it renders the single value",
alertState: &state.State{
LastEvaluationString: "[ var='A' metric='vector(10) + time() % 50' labels={} value=1.1 ]",
LatestResult: &state.Evaluation{Condition: "A", Values: map[string]*float64{"A": &val1}},
LatestResult: &state.Evaluation{Condition: "A", Values: map[string]float64{"A": val1}},
},
expected: "1.1e+00",
},
@@ -64,7 +64,7 @@ func Test_FormatValues(t *testing.T) {
name: "with two values, it renders the value based on their refID and position",
alertState: &state.State{
LastEvaluationString: "[ var='B0' metric='vector(10) + time() % 50' labels={} value=1.1 ], [ var='B1' metric='vector(10) + time() % 50' labels={} value=1.4 ]",
LatestResult: &state.Evaluation{Condition: "B", Values: map[string]*float64{"B0": &val1, "B1": &val2}},
LatestResult: &state.Evaluation{Condition: "B", Values: map[string]float64{"B0": val1, "B1": val2}},
},
expected: "B0: 1.1e+00, B1: 1.4e+00",
},
@@ -72,7 +72,7 @@ func Test_FormatValues(t *testing.T) {
name: "with a high number of values, it renders the value based on their refID and position using a natural order",
alertState: &state.State{
LastEvaluationString: "[ var='B0' metric='vector(10) + time() % 50' labels={} value=1.1 ], [ var='B1' metric='vector(10) + time() % 50' labels={} value=1.4 ]",
LatestResult: &state.Evaluation{Condition: "B", Values: map[string]*float64{"B0": &val1, "B1": &val2, "B2": &val1, "B10": &val2, "B11": &val1}},
LatestResult: &state.Evaluation{Condition: "B", Values: map[string]float64{"B0": val1, "B1": val2, "B2": val1, "B10": val2, "B11": val1}},
},
expected: "B0: 1.1e+00, B10: 1.4e+00, B11: 1.1e+00, B1: 1.4e+00, B2: 1.1e+00",
},
@@ -240,11 +240,10 @@ func TestRouteGetAlertStatuses(t *testing.T) {
func withAlertingState() forEachState {
return func(s *state.State) *state.State {
s.State = eval.Alerting
value := float64(1.1)
s.LatestResult = &state.Evaluation{
EvaluationState: eval.Alerting,
EvaluationTime: timeNow(),
Values: map[string]*float64{"B": &value},
Values: map[string]float64{"B": float64(1.1)},
Condition: "B",
}
return s