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

@ -279,18 +279,16 @@ func (n *GettableExtendedRuleNode) validate() error {
type NoDataState string
const (
Alerting NoDataState = "Alerting"
NoData NoDataState = "NoData"
KeepLastState NoDataState = "KeepLastState"
OK NoDataState = "OK"
Alerting NoDataState = "Alerting"
NoData NoDataState = "NoData"
OK NoDataState = "OK"
)
// swagger:enum ExecutionErrorState
type ExecutionErrorState string
const (
AlertingErrState ExecutionErrorState = "Alerting"
KeepLastStateErrState ExecutionErrorState = "KeepLastState"
AlertingErrState ExecutionErrorState = "Alerting"
)
// swagger:model

View File

@ -26,10 +26,9 @@ func (noDataState NoDataState) String() string {
}
const (
Alerting NoDataState = "Alerting"
NoData NoDataState = "NoData"
KeepLastState NoDataState = "KeepLastState"
OK NoDataState = "OK"
Alerting NoDataState = "Alerting"
NoData NoDataState = "NoData"
OK NoDataState = "OK"
)
type ExecutionErrorState string
@ -39,8 +38,7 @@ func (executionErrorState ExecutionErrorState) String() string {
}
const (
AlertingErrState ExecutionErrorState = "Alerting"
KeepLastStateErrState ExecutionErrorState = "KeepLastState"
AlertingErrState ExecutionErrorState = "Alerting"
)
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{
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
}

View File

@ -189,7 +189,7 @@ func transNoData(s string) (string, error) {
case "alerting":
return "Alerting", nil
case "keep_state":
return "KeepLastState", nil
return "Alerting", nil
}
return "", fmt.Errorf("unrecognized No Data setting %v", s)
}
@ -198,8 +198,8 @@ func transExecErr(s string) (string, error) {
switch s {
case "", "alerting":
return "Alerting", nil
case "KeepLastState":
return "KeepLastState", nil
case "keep_state":
return "Alerting", nil
}
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),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.KeepLastStateErrState),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.AlertingErrState),
},
},
},
@ -911,7 +911,7 @@ func TestAlertRuleCRUD(t *testing.T) {
"namespace_id":1,
"rule_group":"arulegroup",
"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),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.KeepLastStateErrState),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.AlertingErrState),
},
},
},
@ -1044,7 +1044,7 @@ func TestAlertRuleCRUD(t *testing.T) {
},
},
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,
"rule_group":"arulegroup",
"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),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.KeepLastStateErrState),
ExecErrState: apimodels.ExecutionErrorState(ngmodels.AlertingErrState),
},
},
},