|
|
|
@ -2240,6 +2240,86 @@ func TestProcessEvalResults(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
desc: "classic condition, execution Error as Error (alerting -> query error -> alerting)", |
|
|
|
|
alertRule: &models.AlertRule{ |
|
|
|
|
OrgID: 1, |
|
|
|
|
Title: "test_title", |
|
|
|
|
UID: "test_alert_rule_uid", |
|
|
|
|
NamespaceUID: "test_namespace_uid", |
|
|
|
|
Annotations: map[string]string{}, |
|
|
|
|
Labels: map[string]string{"label": "test"}, |
|
|
|
|
Data: []models.AlertQuery{ |
|
|
|
|
{ |
|
|
|
|
RefID: "A", |
|
|
|
|
DatasourceUID: "test-datasource-uid", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
IntervalSeconds: 10, |
|
|
|
|
ExecErrState: models.ErrorErrState, |
|
|
|
|
}, |
|
|
|
|
expectedAnnotations: 2, |
|
|
|
|
evalResults: []eval.Results{ |
|
|
|
|
{ |
|
|
|
|
eval.Result{ |
|
|
|
|
Instance: data.Labels{}, |
|
|
|
|
State: eval.Alerting, |
|
|
|
|
EvaluatedAt: evaluationTime, |
|
|
|
|
EvaluationDuration: evaluationDuration, |
|
|
|
|
}, |
|
|
|
|
eval.Result{ |
|
|
|
|
Instance: data.Labels{}, |
|
|
|
|
State: eval.Error, |
|
|
|
|
Error: expr.MakeQueryError("A", "test-datasource-uid", errors.New("this is an error")), |
|
|
|
|
EvaluatedAt: evaluationTime.Add(10 * time.Second), |
|
|
|
|
EvaluationDuration: evaluationDuration, |
|
|
|
|
}, |
|
|
|
|
eval.Result{ |
|
|
|
|
Instance: data.Labels{}, |
|
|
|
|
State: eval.Alerting, |
|
|
|
|
EvaluatedAt: evaluationTime.Add(20 * time.Second), |
|
|
|
|
EvaluationDuration: evaluationDuration, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
expectedStates: map[string]*state.State{ |
|
|
|
|
`[["__alert_rule_namespace_uid__","test_namespace_uid"],["__alert_rule_uid__","test_alert_rule_uid"],["alertname","test_title"],["label","test"]]`: { |
|
|
|
|
AlertRuleUID: "test_alert_rule_uid", |
|
|
|
|
OrgID: 1, |
|
|
|
|
CacheID: `[["__alert_rule_namespace_uid__","test_namespace_uid"],["__alert_rule_uid__","test_alert_rule_uid"],["alertname","test_title"],["label","test"]]`, |
|
|
|
|
Labels: data.Labels{ |
|
|
|
|
"__alert_rule_namespace_uid__": "test_namespace_uid", |
|
|
|
|
"__alert_rule_uid__": "test_alert_rule_uid", |
|
|
|
|
"alertname": "test_title", |
|
|
|
|
"label": "test", |
|
|
|
|
}, |
|
|
|
|
Values: make(map[string]float64), |
|
|
|
|
State: eval.Alerting, |
|
|
|
|
Results: []state.Evaluation{ |
|
|
|
|
{ |
|
|
|
|
EvaluationTime: evaluationTime, |
|
|
|
|
EvaluationState: eval.Alerting, |
|
|
|
|
Values: make(map[string]*float64), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
EvaluationTime: evaluationTime.Add(10 * time.Second), |
|
|
|
|
EvaluationState: eval.Error, |
|
|
|
|
Values: make(map[string]*float64), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
EvaluationTime: evaluationTime.Add(20 * time.Second), |
|
|
|
|
EvaluationState: eval.Alerting, |
|
|
|
|
Values: make(map[string]*float64), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
StartsAt: evaluationTime.Add(20 * time.Second), |
|
|
|
|
EndsAt: evaluationTime.Add(110 * time.Second), |
|
|
|
|
LastEvaluationTime: evaluationTime.Add(20 * time.Second), |
|
|
|
|
EvaluationDuration: evaluationDuration, |
|
|
|
|
Annotations: map[string]string{}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, tc := range testCases { |
|
|
|
|