Alerting: Add rule_query_offset setting for Prometheus rule conversion (#102500)
Adds a new configuration option to specify a time offset for rule evaluation, which gets applied and saved during the Prometheus -> Grafana conversion. For example: [unified_alerting.prometheus_conversion] rule_query_offset = 1m Changing this option affects only the rules imported after the change. If query_offset is set at the group level, it takes precedence over this setting. Default is set to 1m.
This commit is contained in:
@@ -112,6 +112,7 @@ type UnifiedAlertingSettings struct {
|
||||
StateHistory UnifiedAlertingStateHistorySettings
|
||||
RemoteAlertmanager RemoteAlertmanagerSettings
|
||||
RecordingRules RecordingRuleSettings
|
||||
PrometheusConversion UnifiedAlertingPrometheusConversionSettings
|
||||
|
||||
// MaxStateSaveConcurrency controls the number of goroutines (per rule) that can save alert state in parallel.
|
||||
MaxStateSaveConcurrency int
|
||||
@@ -165,6 +166,12 @@ type UnifiedAlertingReservedLabelSettings struct {
|
||||
DisabledLabels map[string]struct{}
|
||||
}
|
||||
|
||||
// UnifiedAlertingPrometheusConversionSettings contains configuration for converting Prometheus rules to Grafana format
|
||||
type UnifiedAlertingPrometheusConversionSettings struct {
|
||||
// RuleQueryOffset defines a time offset to apply to rule queries during conversion from Prometheus to Grafana format
|
||||
RuleQueryOffset time.Duration
|
||||
}
|
||||
|
||||
type UnifiedAlertingStateHistorySettings struct {
|
||||
Enabled bool
|
||||
Backend string
|
||||
@@ -437,6 +444,11 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
|
||||
}
|
||||
uaCfg.StateHistory = uaCfgStateHistory
|
||||
|
||||
prometheusConversion := iniFile.Section("unified_alerting.prometheus_conversion")
|
||||
uaCfg.PrometheusConversion = UnifiedAlertingPrometheusConversionSettings{
|
||||
RuleQueryOffset: prometheusConversion.Key("rule_query_offset").MustDuration(time.Minute),
|
||||
}
|
||||
|
||||
rr := iniFile.Section("recording_rules")
|
||||
uaCfgRecordingRules := RecordingRuleSettings{
|
||||
Enabled: rr.Key("enabled").MustBool(false),
|
||||
|
||||
Reference in New Issue
Block a user