Alerting: Remove back end logic for supporting KeepLastState (#34242)

* Removed back end logic for supporting KeepLastState

* Map keep_state correctly in migrations
This commit is contained in:
David Parrott
2021-05-18 10:55:43 -07:00
committed by GitHub
parent 0683692509
commit bbb7bbf891
7 changed files with 22 additions and 90 deletions

View File

@@ -652,7 +652,7 @@ func TestProcessEvalResults(t *testing.T) {
},
},
{
desc: "normal -> normal when result is NoData and NoDataState is KeepLastState",
desc: "normal -> alerting when result is Error and ExecErrState is Alerting",
alertRule: &models.AlertRule{
OrgID: 1,
Title: "test_title",
@@ -662,7 +662,7 @@ func TestProcessEvalResults(t *testing.T) {
Labels: map[string]string{"label": "test"},
IntervalSeconds: 10,
For: 1 * time.Minute,
NoDataState: models.KeepLastState,
ExecErrState: models.AlertingErrState,
},
evalResults: []eval.Results{
{
@@ -676,7 +676,7 @@ func TestProcessEvalResults(t *testing.T) {
{
eval.Result{
Instance: data.Labels{"instance_label": "test"},
State: eval.NoData,
State: eval.Error,
EvaluatedAt: evaluationTime.Add(10 * time.Second),
EvaluationDuration: evaluationDuration,
},
@@ -694,7 +694,7 @@ func TestProcessEvalResults(t *testing.T) {
"label": "test",
"instance_label": "test",
},
State: eval.Normal,
State: eval.Alerting,
Results: []state.Evaluation{
{
EvaluationTime: evaluationTime,
@@ -702,69 +702,7 @@ func TestProcessEvalResults(t *testing.T) {
},
{
EvaluationTime: evaluationTime.Add(10 * time.Second),
EvaluationState: eval.NoData,
},
},
StartsAt: evaluationTime.Add(10 * time.Second),
EndsAt: evaluationTime.Add(10 * time.Second).Add(1 * time.Minute),
LastEvaluationTime: evaluationTime.Add(10 * time.Second),
EvaluationDuration: evaluationDuration,
Annotations: map[string]string{"annotation": "test"},
},
},
},
{
desc: "normal -> normal when result is NoData and NoDataState is KeepLastState",
alertRule: &models.AlertRule{
OrgID: 1,
Title: "test_title",
UID: "test_alert_rule_uid_2",
NamespaceUID: "test_namespace_uid",
Annotations: map[string]string{"annotation": "test"},
Labels: map[string]string{"label": "test"},
IntervalSeconds: 10,
For: 1 * time.Minute,
NoDataState: models.KeepLastState,
},
evalResults: []eval.Results{
{
eval.Result{
Instance: data.Labels{"instance_label": "test"},
State: eval.Normal,
EvaluatedAt: evaluationTime,
EvaluationDuration: evaluationDuration,
},
},
{
eval.Result{
Instance: data.Labels{"instance_label": "test"},
State: eval.NoData,
EvaluatedAt: evaluationTime.Add(10 * time.Second),
EvaluationDuration: evaluationDuration,
},
},
},
expectedStates: map[string]*state.State{
`[["__alert_rule_namespace_uid__","test_namespace_uid"],["__alert_rule_uid__","test_alert_rule_uid_2"],["alertname","test_title"],["instance_label","test"],["label","test"]]`: {
AlertRuleUID: "test_alert_rule_uid_2",
OrgID: 1,
CacheId: `[["__alert_rule_namespace_uid__","test_namespace_uid"],["__alert_rule_uid__","test_alert_rule_uid_2"],["alertname","test_title"],["instance_label","test"],["label","test"]]`,
Labels: data.Labels{
"__alert_rule_namespace_uid__": "test_namespace_uid",
"__alert_rule_uid__": "test_alert_rule_uid_2",
"alertname": "test_title",
"label": "test",
"instance_label": "test",
},
State: eval.Normal,
Results: []state.Evaluation{
{
EvaluationTime: evaluationTime,
EvaluationState: eval.Normal,
},
{
EvaluationTime: evaluationTime.Add(10 * time.Second),
EvaluationState: eval.NoData,
EvaluationState: eval.Error,
},
},
StartsAt: evaluationTime.Add(10 * time.Second),

View File

@@ -87,7 +87,6 @@ func (a *State) resultError(alertRule *ngModels.AlertRule, result eval.Result) *
switch alertRule.ExecErrState {
case ngModels.AlertingErrState:
a.State = eval.Alerting
case ngModels.KeepLastStateErrState:
}
return a
}
@@ -107,7 +106,6 @@ func (a *State) resultNoData(alertRule *ngModels.AlertRule, result eval.Result)
a.State = eval.Alerting
case ngModels.NoData:
a.State = eval.NoData
case ngModels.KeepLastState:
case ngModels.OK:
a.State = eval.Normal
}