Alerting: Recover deleted alert rules (#101869)
* add column guid to alert rule table and rule_guid to rule version table + populate the new field with UUID * update storage and domain models * patch GUID * ignore GUID in fingerprint tests * get alert rule versions by GUID * update rule delete to reset uid in history instead of deleting rows * add test * Update delete rule to require UserUID, remove all versions and create "delete" version that holds information about who and when deleted the rule * update usages of the delete method * add list deleted rules to store * list api to support deleted query parameter * add list deleted rules to store ^ Conflicts: ^ pkg/services/ngalert/store/alert_rule_test.go * list api to support deleted query parameter * Restore deleted rules * fix recovering manually recording rules * update role control for the trash route * add alertingRuleRecoverDeleted feature toggle enabled by default * fix access control for trash menu item in the navtree * Add alertingRuleRecoverDeleted feature toggle, add Delete permanently alert rule menu option * hide remove permanently functionality in the UI until we have the api available for it * discard wrong changes after merging * Reverted changes in pkg/apis/dashboard_manifest.go after fixing conflicts * Reverted changes in go.work.sum after fixing conflicts * Reverted changes in pkg/apis/dashboard_manifest.go after fixing conflicts * Reverted changes in pkg/services/ngalert/models/alert_rule.go after fixing conflicts * Reverted changes in pkg/apis/dashboard_manifest.go after fixing conflicts * restore delete permanently and add the queryparam for it * update snapshots * fix translations * protect trash route by the feature toggles * use the new rulerRuleType for checks * revert ability to delete permanently and alert rule from the ui * remove unnecessary update after reverting * fix ff * add tracking * use recently deleted instead of trash * create isRecoverDeletedRulesEnabled for checking ffs * address pr feedback 1 * include alert rule uid in getRowId * use RulerGrafanaRulesConfigDTO for deleted rules response * use isLoading in the AlertingPageWrapper * fix wrong check for recording rules type * add test for restoring manually through the alert rule form * add test for restoring deleted rule * use importAlertingComponent * udpate mock * address pr feedback * update translations * address feedback * address feedback 2 * address feedback 3 * address feedback 4 * move transformation of the response to the endpoint * fix typo * refactor grafanaRuleDtoToFormValues * update translations * use guid for identifying rows * prettier * use ONLY the guid for identifying rows * Add provides/invalidates tags for deleted rules --------- Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com> Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
This commit is contained in:
co-authored by
Yuri Tseretyan
Tom Ratcliffe
parent
2489e423d0
commit
f9471ac10b
@@ -1806,6 +1806,16 @@ var (
|
||||
HideFromAdminPage: true,
|
||||
HideFromDocs: true,
|
||||
},
|
||||
{
|
||||
Name: "alertingRuleRecoverDeleted",
|
||||
Description: "Enables the UI functionality to recover and view deleted alert rules",
|
||||
FrontendOnly: true,
|
||||
Stage: FeatureStageGeneralAvailability,
|
||||
Owner: grafanaAlertingSquad,
|
||||
HideFromAdminPage: true,
|
||||
HideFromDocs: true,
|
||||
Expression: "true", // enabled by default
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -238,3 +238,4 @@ noBackdropBlur,experimental,@grafana/grafana-frontend-platform,false,false,true
|
||||
alertingMigrationUI,experimental,@grafana/alerting-squad,false,false,true
|
||||
unifiedStorageHistoryPruner,experimental,@grafana/search-and-storage,false,false,false
|
||||
unifiedStorageGrpcConnectionPool,experimental,@grafana/search-and-storage,false,false,false
|
||||
alertingRuleRecoverDeleted,GA,@grafana/alerting-squad,false,false,true
|
||||
|
||||
|
@@ -962,4 +962,8 @@ const (
|
||||
// FlagUnifiedStorageGrpcConnectionPool
|
||||
// Enables the unified storage grpc connection pool
|
||||
FlagUnifiedStorageGrpcConnectionPool = "unifiedStorageGrpcConnectionPool"
|
||||
|
||||
// FlagAlertingRuleRecoverDeleted
|
||||
// Enables the UI functionality to recover and view deleted alert rules
|
||||
FlagAlertingRuleRecoverDeleted = "alertingRuleRecoverDeleted"
|
||||
)
|
||||
|
||||
@@ -437,6 +437,25 @@
|
||||
"expression": "false"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"name": "alertingRuleRecoverDeleted",
|
||||
"resourceVersion": "1741351039908",
|
||||
"creationTimestamp": "2025-03-07T09:25:14Z",
|
||||
"annotations": {
|
||||
"grafana.app/updatedTimestamp": "2025-03-07 12:37:19.908258 +0000 UTC"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"description": "Enables the UI functionality to recover and view deleted alert rules",
|
||||
"stage": "GA",
|
||||
"codeowner": "@grafana/alerting-squad",
|
||||
"frontend": true,
|
||||
"hideFromAdminPage": true,
|
||||
"hideFromDocs": true,
|
||||
"expression": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"name": "alertingRuleVersionHistoryRestore",
|
||||
|
||||
@@ -489,6 +489,14 @@ func (s *ServiceImpl) buildAlertNavLinks(c *contextmodel.ReqContext) *navtree.Na
|
||||
})
|
||||
}
|
||||
}
|
||||
if c.SignedInUser.GetOrgRole() == org.RoleAdmin && s.features.IsEnabled(c.Req.Context(), featuremgmt.FlagAlertRuleRestore) && s.features.IsEnabled(c.Req.Context(), featuremgmt.FlagAlertingRuleRecoverDeleted) {
|
||||
alertChildNavs = append(alertChildNavs, &navtree.NavLink{
|
||||
Text: "Recently deleted",
|
||||
SubTitle: "Any items listed here for more than 30 days will be automatically deleted.",
|
||||
Id: "alerts/recently-deleted",
|
||||
Url: s.cfg.AppSubURL + "/alerting/recently-deleted",
|
||||
})
|
||||
}
|
||||
|
||||
if c.SignedInUser.GetOrgRole() == org.RoleAdmin {
|
||||
alertChildNavs = append(alertChildNavs, &navtree.NavLink{
|
||||
|
||||
Reference in New Issue
Block a user