Alerting: Add scheduled clean-up of deleted rules (#101963)

* add scheduled clean up of deleted rules


---------

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
Yuri Tseretyan
2025-03-11 16:58:26 -04:00
committed by GitHub
parent 9870718c3a
commit 943b73a682
7 changed files with 190 additions and 3 deletions

View File

@ -129,6 +129,9 @@ type UnifiedAlertingSettings struct {
// should be stored in the database for each alert_rule in an organization including the current one.
// 0 value means no limit
RuleVersionRecordLimit int
// DeletedRuleRetention defines the maximum duration to retain deleted alerting rules before permanent removal.
DeletedRuleRetention time.Duration
}
type RecordingRuleSettings struct {
@ -477,6 +480,11 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
return fmt.Errorf("setting 'rule_version_record_limit' is invalid, only 0 or a positive integer are allowed")
}
uaCfg.DeletedRuleRetention = ua.Key("deleted_rule_retention").MustDuration(30 * 24 * time.Hour)
if uaCfg.DeletedRuleRetention < 0 {
return fmt.Errorf("setting 'deleted_rule_retention' is invalid, only 0 or a positive duration are allowed")
}
cfg.UnifiedAlerting = uaCfg
return nil
}