[v11.0.x] Alerting: Do not store series values from past evaluations in state manager for no reason (#87845)
Alerting: Do not store series values from past evaluations in state manager for no reason (#87525)
Do not store previous execution results on states
(cherry picked from commit a6a9ab4008)
Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
This commit is contained in:
co-authored by
Alexander Weaver
parent
ae9743b722
commit
e5237e5ac2
@@ -47,9 +47,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 ]",
|
||||
Results: []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 ]",
|
||||
},
|
||||
@@ -57,9 +55,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 ]",
|
||||
Results: []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",
|
||||
},
|
||||
@@ -67,9 +63,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 ]",
|
||||
Results: []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",
|
||||
},
|
||||
@@ -77,9 +71,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 ]",
|
||||
Results: []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",
|
||||
},
|
||||
@@ -248,12 +240,12 @@ func withAlertingState() forEachState {
|
||||
return func(s *state.State) *state.State {
|
||||
s.State = eval.Alerting
|
||||
value := float64(1.1)
|
||||
s.Results = append(s.Results, state.Evaluation{
|
||||
s.LatestResult = &state.Evaluation{
|
||||
EvaluationState: eval.Alerting,
|
||||
EvaluationTime: timeNow(),
|
||||
Values: map[string]*float64{"B": &value},
|
||||
Condition: "B",
|
||||
})
|
||||
}
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,17 +83,10 @@ func (f *fakeAlertInstanceManager) GenerateAlertInstances(orgID int64, alertRule
|
||||
"instance_label": "test",
|
||||
},
|
||||
State: eval.Normal,
|
||||
Results: []state.Evaluation{
|
||||
{
|
||||
EvaluationTime: evaluationTime,
|
||||
EvaluationState: eval.Normal,
|
||||
Values: make(map[string]*float64),
|
||||
},
|
||||
{
|
||||
EvaluationTime: evaluationTime.Add(1 * time.Minute),
|
||||
EvaluationState: eval.Normal,
|
||||
Values: make(map[string]*float64),
|
||||
},
|
||||
LatestResult: &state.Evaluation{
|
||||
EvaluationTime: evaluationTime.Add(1 * time.Minute),
|
||||
EvaluationState: eval.Normal,
|
||||
Values: make(map[string]*float64),
|
||||
},
|
||||
LastEvaluationTime: evaluationTime.Add(1 * time.Minute),
|
||||
EvaluationDuration: evaluationDuration,
|
||||
|
||||
Reference in New Issue
Block a user