mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
[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:
parent
dadccdda06
commit
624fbf5dda
@ -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
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ type ListRuleGroupAlertRulesQuery struct {
|
||||
type ListOrgRuleGroupsQuery struct {
|
||||
OrgID int64
|
||||
|
||||
Result []string
|
||||
Result [][]string
|
||||
}
|
||||
|
||||
// Condition contains backend expressions and queries and the RefID
|
||||
|
@ -460,8 +460,8 @@ func (st DBstore) UpdateRuleGroup(cmd UpdateRuleGroupCmd) error {
|
||||
|
||||
func (st DBstore) GetOrgRuleGroups(query *ngmodels.ListOrgRuleGroupsQuery) error {
|
||||
return st.SQLStore.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
var ruleGroups []string
|
||||
q := "SELECT DISTINCT rule_group FROM alert_rule WHERE org_id = ?"
|
||||
var ruleGroups [][]string
|
||||
q := "SELECT DISTINCT rule_group, namespace_uid, (select title from dashboard where org_id = alert_rule.org_id and uid = alert_rule.namespace_uid) FROM alert_rule WHERE org_id = ?"
|
||||
if err := sess.SQL(q, query.OrgID).Find(&ruleGroups); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user