Alerting: Limit and clean up old alert rules versions (#89754)

This commit is contained in:
Brandon
2024-10-04 14:31:21 -07:00
committed by GitHub
parent 4ec75bcc60
commit fbad76007d
5 changed files with 207 additions and 3 deletions

View File

@@ -121,6 +121,11 @@ type UnifiedAlertingSettings struct {
// Duration for which a resolved alert state transition will continue to be sent to the Alertmanager.
ResolvedAlertRetention time.Duration
// RuleVersionRecordLimit defines the limit of how many alert rule versions
// should be stored in the database for each alert_rule in an organization including the current one.
// 0 value means no limit
RuleVersionRecordLimit int
}
type RecordingRuleSettings struct {
@@ -455,6 +460,11 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
return err
}
uaCfg.RuleVersionRecordLimit = ua.Key("rule_version_record_limit").MustInt(0)
if uaCfg.RuleVersionRecordLimit < 0 {
return fmt.Errorf("setting 'rule_version_record_limit' is invalid, only 0 or a positive integer are allowed")
}
cfg.UnifiedAlerting = uaCfg
return nil
}