diff --git a/pkg/services/ngalert/api/api_prometheus.go b/pkg/services/ngalert/api/api_prometheus.go index 79f7099bdbc..066273a38fa 100644 --- a/pkg/services/ngalert/api/api_prometheus.go +++ b/pkg/services/ngalert/api/api_prometheus.go @@ -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 } diff --git a/pkg/services/ngalert/models/alert_rule.go b/pkg/services/ngalert/models/alert_rule.go index 135c1ceb6d3..b931d4631a1 100644 --- a/pkg/services/ngalert/models/alert_rule.go +++ b/pkg/services/ngalert/models/alert_rule.go @@ -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 diff --git a/pkg/services/ngalert/store/alert_rule.go b/pkg/services/ngalert/store/alert_rule.go index 890fa878402..ae69cb8b8b1 100644 --- a/pkg/services/ngalert/store/alert_rule.go +++ b/pkg/services/ngalert/store/alert_rule.go @@ -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 }