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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 90 deletions

View File

@ -281,7 +281,6 @@ type NoDataState string
const ( const (
Alerting NoDataState = "Alerting" Alerting NoDataState = "Alerting"
NoData NoDataState = "NoData" NoData NoDataState = "NoData"
KeepLastState NoDataState = "KeepLastState"
OK NoDataState = "OK" OK NoDataState = "OK"
) )
@ -290,7 +289,6 @@ type ExecutionErrorState string
const ( const (
AlertingErrState ExecutionErrorState = "Alerting" AlertingErrState ExecutionErrorState = "Alerting"
KeepLastStateErrState ExecutionErrorState = "KeepLastState"
) )
// swagger:model // swagger:model

View File

@ -28,7 +28,6 @@ func (noDataState NoDataState) String() string {
const ( const (
Alerting NoDataState = "Alerting" Alerting NoDataState = "Alerting"
NoData NoDataState = "NoData" NoData NoDataState = "NoData"
KeepLastState NoDataState = "KeepLastState"
OK NoDataState = "OK" OK NoDataState = "OK"
) )
@ -40,7 +39,6 @@ func (executionErrorState ExecutionErrorState) String() string {
const ( const (
AlertingErrState ExecutionErrorState = "Alerting" AlertingErrState ExecutionErrorState = "Alerting"
KeepLastStateErrState ExecutionErrorState = "KeepLastState"
) )
const ( const (

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{ alertRule: &models.AlertRule{
OrgID: 1, OrgID: 1,
Title: "test_title", Title: "test_title",
@ -662,7 +662,7 @@ func TestProcessEvalResults(t *testing.T) {
Labels: map[string]string{"label": "test"}, Labels: map[string]string{"label": "test"},
IntervalSeconds: 10, IntervalSeconds: 10,
For: 1 * time.Minute, For: 1 * time.Minute,
NoDataState: models.KeepLastState, ExecErrState: models.AlertingErrState,
}, },
evalResults: []eval.Results{ evalResults: []eval.Results{
{ {
@ -676,7 +676,7 @@ func TestProcessEvalResults(t *testing.T) {
{ {
eval.Result{ eval.Result{
Instance: data.Labels{"instance_label": "test"}, Instance: data.Labels{"instance_label": "test"},
State: eval.NoData, State: eval.Error,
EvaluatedAt: evaluationTime.Add(10 * time.Second), EvaluatedAt: evaluationTime.Add(10 * time.Second),
EvaluationDuration: evaluationDuration, EvaluationDuration: evaluationDuration,
}, },
@ -694,7 +694,7 @@ func TestProcessEvalResults(t *testing.T) {
"label": "test", "label": "test",
"instance_label": "test", "instance_label": "test",
}, },
State: eval.Normal, State: eval.Alerting,
Results: []state.Evaluation{ Results: []state.Evaluation{
{ {
EvaluationTime: evaluationTime, EvaluationTime: evaluationTime,
@ -702,69 +702,7 @@ func TestProcessEvalResults(t *testing.T) {
}, },
{ {
EvaluationTime: evaluationTime.Add(10 * time.Second), EvaluationTime: evaluationTime.Add(10 * time.Second),
EvaluationState: eval.NoData, EvaluationState: eval.Error,
},
},
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,
}, },
}, },
StartsAt: evaluationTime.Add(10 * time.Second), 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 { switch alertRule.ExecErrState {
case ngModels.AlertingErrState: case ngModels.AlertingErrState:
a.State = eval.Alerting a.State = eval.Alerting
case ngModels.KeepLastStateErrState:
} }
return a return a
} }
@ -107,7 +106,6 @@ func (a *State) resultNoData(alertRule *ngModels.AlertRule, result eval.Result)
a.State = eval.Alerting a.State = eval.Alerting
case ngModels.NoData: case ngModels.NoData:
a.State = eval.NoData a.State = eval.NoData
case ngModels.KeepLastState:
case ngModels.OK: case ngModels.OK:
a.State = eval.Normal a.State = eval.Normal
} }

View File

@ -189,7 +189,7 @@ func transNoData(s string) (string, error) {
case "alerting": case "alerting":
return "Alerting", nil return "Alerting", nil
case "keep_state": case "keep_state":
return "KeepLastState", nil return "Alerting", nil
} }
return "", fmt.Errorf("unrecognized No Data setting %v", s) return "", fmt.Errorf("unrecognized No Data setting %v", s)
} }
@ -198,8 +198,8 @@ func transExecErr(s string) (string, error) {
switch s { switch s {
case "", "alerting": case "", "alerting":
return "Alerting", nil return "Alerting", nil
case "KeepLastState": case "keep_state":
return "KeepLastState", nil return "Alerting", nil
} }
return "", fmt.Errorf("unrecognized Execution Error setting %v", s) return "", fmt.Errorf("unrecognized Execution Error setting %v", s)
} }

View File

@ -781,7 +781,7 @@ func TestAlertRuleCRUD(t *testing.T) {
}, },
}, },
NoDataState: apimodels.NoDataState(ngmodels.Alerting), NoDataState: apimodels.NoDataState(ngmodels.Alerting),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.KeepLastStateErrState), ExecErrState: apimodels.ExecutionErrorState(ngmodels.AlertingErrState),
}, },
}, },
}, },
@ -911,7 +911,7 @@ func TestAlertRuleCRUD(t *testing.T) {
"namespace_id":1, "namespace_id":1,
"rule_group":"arulegroup", "rule_group":"arulegroup",
"no_data_state":"Alerting", "no_data_state":"Alerting",
"exec_err_state":"KeepLastState" "exec_err_state":"Alerting"
} }
} }
] ]
@ -960,7 +960,7 @@ func TestAlertRuleCRUD(t *testing.T) {
}, },
}, },
NoDataState: apimodels.NoDataState(ngmodels.Alerting), NoDataState: apimodels.NoDataState(ngmodels.Alerting),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.KeepLastStateErrState), ExecErrState: apimodels.ExecutionErrorState(ngmodels.AlertingErrState),
}, },
}, },
}, },
@ -1044,7 +1044,7 @@ func TestAlertRuleCRUD(t *testing.T) {
}, },
}, },
NoDataState: apimodels.NoDataState(ngmodels.Alerting), NoDataState: apimodels.NoDataState(ngmodels.Alerting),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.KeepLastStateErrState), ExecErrState: apimodels.ExecutionErrorState(ngmodels.AlertingErrState),
}, },
}, },
}, },
@ -1135,7 +1135,7 @@ func TestAlertRuleCRUD(t *testing.T) {
"namespace_id":1, "namespace_id":1,
"rule_group":"arulegroup", "rule_group":"arulegroup",
"no_data_state":"Alerting", "no_data_state":"Alerting",
"exec_err_state":"KeepLastState" "exec_err_state":"Alerting"
} }
} }
] ]

View File

@ -119,7 +119,7 @@ func TestPrometheusRules(t *testing.T) {
}, },
}, },
NoDataState: apimodels.NoDataState(ngmodels.Alerting), NoDataState: apimodels.NoDataState(ngmodels.Alerting),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.KeepLastStateErrState), ExecErrState: apimodels.ExecutionErrorState(ngmodels.AlertingErrState),
}, },
}, },
}, },