Alerting: Handle NoData and Error evaluation results (#33194)

* set processing time

* merge labels and set on response

* use state cache for adding alerts to rules

* minor cleanup

* add support for NoData and Error results

* rename test

* bring in changes from other PRs tha have been merged

* pr feedback

* add integration test

* close state tracker cleanup on context.Done

* fixup test

* not those annotations
This commit is contained in:
David Parrott
2021-04-23 11:47:52 -07:00
committed by GitHub
parent 948cba199b
commit ca79206498
6 changed files with 1044 additions and 280 deletions

View File

@@ -51,7 +51,9 @@ func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Res
DiscoveryBase: apimodels.DiscoveryBase{
Status: "success",
},
Data: apimodels.RuleDiscovery{},
Data: apimodels.RuleDiscovery{
RuleGroups: []*apimodels.RuleGroup{},
},
}
ruleGroupQuery := ngmodels.ListOrgRuleGroupsQuery{
@@ -99,7 +101,7 @@ func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Res
newRule := apimodels.Rule{
Name: rule.Title,
Labels: rule.Labels,
Health: "ok", // TODO: update this in the future when error and noData states are being evaluated and set
Health: "ok",
Type: apiv1.RuleTypeAlerting,
LastEvaluation: time.Time{},
}
@@ -131,9 +133,9 @@ func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Res
case eval.Alerting:
alertingRule.State = "firing"
case eval.Error:
// handle Error case based on configuration in alertRule
newRule.Health = "error"
case eval.NoData:
// handle NoData case based on configuration in alertRule
newRule.Health = "nodata"
}
alertingRule.Alerts = append(alertingRule.Alerts, alert)
}