[Alerting]: Fix empty rules evaluation statuses (#32997)

* [Alerting]: Fix empty rules evaluation statuses

`GetRuleGroupAlertRules()` requires an non empty namespaceUID

* Include the namespace into the response
This commit is contained in:
Sofia Papagiannaki
2021-04-14 17:49:26 +00:00
committed by GitHub
parent dadccdda06
commit 624fbf5dda
3 changed files with 13 additions and 7 deletions
+10 -4
View File
@@ -63,8 +63,12 @@ func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Res
return response.JSON(http.StatusInternalServerError, ruleResponse)
}
for _, groupId := range ruleGroupQuery.Result {
alertRuleQuery := ngmodels.ListRuleGroupAlertRulesQuery{OrgID: c.SignedInUser.OrgId, RuleGroup: groupId}
for _, r := range ruleGroupQuery.Result {
if len(r) < 3 {
continue
}
groupId, namespaceUID, namespace := r[0], r[1], r[2]
alertRuleQuery := ngmodels.ListRuleGroupAlertRulesQuery{OrgID: c.SignedInUser.OrgId, NamespaceUID: namespaceUID, RuleGroup: groupId}
if err := srv.store.GetRuleGroupAlertRules(&alertRuleQuery); err != nil {
ruleResponse.DiscoveryBase.Status = "error"
ruleResponse.DiscoveryBase.Error = fmt.Sprintf("failure getting rules for group %s: %s", groupId, err.Error())
@@ -73,8 +77,10 @@ func (srv PrometheusSrv) RouteGetRuleStatuses(c *models.ReqContext) response.Res
}
newGroup := &apimodels.RuleGroup{
Name: groupId,
File: "", // This doesn't make sense in our architecture but would be a good use case for provisioned alerts.
Name: groupId,
// This doesn't make sense in our architecture
// so we use this field for passing to the frontend the namaspace
File: namespace,
LastEvaluation: time.Time{},
EvaluationTime: 0, // TODO: see if we are able to pass this along with evaluation results
}