Alerting: Add read-only GMA rules to the new list view (#98116)
* Reuse prom groups generator between GMA, external DS and list view * Improve generators, add initial support for GMA in grouped view components * Improve handling of GMA rules * Split componentes into files * Improve error handling, simplify groups grouping * Extract grafana rules component * Reset yarn.lock * Reset yarn.lock 2 * Update filters, adjust file names, add folder display name to GMA rules * Re-enable filtering for cloud rules * Rename AlertRuleLoader * Add missing translations, fix lint errors * Remove unused imports, update translations * Fix responses in BE tests * Update backend tests * Update integration test * Tidy up group page size constants * Add error throwing to getGroups endpoint to prevent grafana usage * Refactor FilterView to remove exhaustive check * Refactor common props for grafana rule rendering * Unify identifiers' discriminators, add comments, minor refactor * Update translations * Remove unnecessary prev page condition, add a few explanations --------- Co-authored-by: fayzal-g <fayzal.ghantiwala@grafana.com> Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
This commit is contained in:
co-authored by
fayzal-g
Tom Ratcliffe
parent
7f04f66137
commit
5aeaccadff
@@ -198,7 +198,6 @@ func (_m *FakeDashboardService) GetAllDashboards(ctx context.Context) ([]*Dashbo
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
|
||||
func (_m *FakeDashboardService) GetAllDashboardsByOrgId(ctx context.Context, orgID int64) ([]*Dashboard, error) {
|
||||
ret := _m.Called(ctx, orgID)
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ func (ss *FolderUnifiedStoreImpl) GetDescendants(ctx context.Context, orgID int6
|
||||
}
|
||||
|
||||
func getDescendants(nodes map[string]*folder.Folder, tree map[string]map[string]*folder.Folder, ancestor_uid string, descendantsMap map[string]*folder.Folder) {
|
||||
for uid, _ := range tree[ancestor_uid] {
|
||||
for uid := range tree[ancestor_uid] {
|
||||
descendantsMap[uid] = nodes[uid]
|
||||
getDescendants(nodes, tree, uid, descendantsMap)
|
||||
}
|
||||
|
||||
@@ -489,7 +489,8 @@ func toRuleGroup(log log.Logger, manager state.AlertInstanceManager, sr StatusRe
|
||||
newGroup := &apimodels.RuleGroup{
|
||||
Name: groupKey.RuleGroup,
|
||||
// file is what Prometheus uses for provisioning, we replace it with namespace which is the folder in Grafana.
|
||||
File: folderFullPath,
|
||||
File: folderFullPath,
|
||||
FolderUID: groupKey.NamespaceUID,
|
||||
}
|
||||
|
||||
rulesTotals := make(map[string]int64, len(rules))
|
||||
@@ -514,7 +515,9 @@ func toRuleGroup(log log.Logger, manager state.AlertInstanceManager, sr StatusRe
|
||||
}
|
||||
|
||||
newRule := apimodels.Rule{
|
||||
UID: rule.UID,
|
||||
Name: rule.Title,
|
||||
FolderUID: rule.NamespaceUID,
|
||||
Labels: apimodels.LabelsFromMap(rule.GetLabels(labelOptions...)),
|
||||
Health: status.Health,
|
||||
LastError: errorOrEmpty(status.LastError),
|
||||
|
||||
@@ -314,9 +314,12 @@ func TestRouteGetRuleStatuses(t *testing.T) {
|
||||
"groups": [{
|
||||
"name": "rule-group",
|
||||
"file": "%s",
|
||||
"folderUid": "namespaceUID",
|
||||
"rules": [{
|
||||
"state": "inactive",
|
||||
"name": "AlwaysFiring",
|
||||
"folderUid": "namespaceUID",
|
||||
"uid": "RuleUID",
|
||||
"query": "vector(1)",
|
||||
"alerts": [{
|
||||
"labels": {
|
||||
@@ -377,10 +380,13 @@ func TestRouteGetRuleStatuses(t *testing.T) {
|
||||
"groups": [{
|
||||
"name": "rule-group",
|
||||
"file": "%s",
|
||||
"folderUid": "namespaceUID",
|
||||
"rules": [{
|
||||
"state": "inactive",
|
||||
"name": "AlwaysFiring",
|
||||
"query": "vector(1)",
|
||||
"folderUid": "namespaceUID",
|
||||
"uid": "RuleUID",
|
||||
"alerts": [{
|
||||
"labels": {
|
||||
"job": "prometheus",
|
||||
@@ -439,10 +445,13 @@ func TestRouteGetRuleStatuses(t *testing.T) {
|
||||
"groups": [{
|
||||
"name": "rule-group",
|
||||
"file": "%s",
|
||||
"folderUid": "namespaceUID",
|
||||
"rules": [{
|
||||
"state": "inactive",
|
||||
"name": "AlwaysFiring",
|
||||
"query": "vector(1) | vector(1)",
|
||||
"folderUid": "namespaceUID",
|
||||
"uid": "RuleUID",
|
||||
"alerts": [{
|
||||
"labels": {
|
||||
"job": "prometheus"
|
||||
|
||||
@@ -89,6 +89,8 @@ type RuleGroup struct {
|
||||
Name string `json:"name"`
|
||||
// required: true
|
||||
File string `json:"file"`
|
||||
// required: true
|
||||
FolderUID string `json:"folderUid"`
|
||||
// In order to preserve rule ordering, while exposing type (alerting or recording)
|
||||
// specific properties, both alerting and recording rules are exposed in the
|
||||
// same array.
|
||||
@@ -165,9 +167,13 @@ type AlertingRule struct {
|
||||
// adapted from cortex
|
||||
// swagger:model
|
||||
type Rule struct {
|
||||
// required: true
|
||||
UID string `json:"uid"`
|
||||
// required: true
|
||||
Name string `json:"name"`
|
||||
// required: true
|
||||
FolderUID string `json:"folderUid"`
|
||||
// required: true
|
||||
Query string `json:"query"`
|
||||
Labels promlabels.Labels `json:"labels,omitempty"`
|
||||
// required: true
|
||||
|
||||
Reference in New Issue
Block a user