From f1fdb0d12eb8fe6c08db55aa74109e449ecd3a9b Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Thu, 3 Jul 2025 19:19:37 +0100 Subject: [PATCH] Parse notification history settings --- pkg/setting/setting_unified_alerting.go | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/setting/setting_unified_alerting.go b/pkg/setting/setting_unified_alerting.go index f78485d239e..c8d71f0e5d9 100644 --- a/pkg/setting/setting_unified_alerting.go +++ b/pkg/setting/setting_unified_alerting.go @@ -64,6 +64,7 @@ const ( // DefaultRuleEvaluationInterval indicates a default interval of for how long a rule should be evaluated to change state from Pending to Alerting DefaultRuleEvaluationInterval = SchedulerBaseInterval * 6 // == 60 seconds stateHistoryDefaultEnabled = true + notificationHistoryDefaultEnabled = false lokiDefaultMaxQueryLength = 721 * time.Hour // 30d1h, matches the default value in Loki defaultRecordingRequestTimeout = 10 * time.Second lokiDefaultMaxQuerySize = 65536 // 64kb @@ -122,6 +123,7 @@ type UnifiedAlertingSettings struct { ReservedLabels UnifiedAlertingReservedLabelSettings SkipClustering bool StateHistory UnifiedAlertingStateHistorySettings + NotificationHistory UnifiedAlertingNotificationHistorySettings RemoteAlertmanager RemoteAlertmanagerSettings RecordingRules RecordingRuleSettings PrometheusConversion UnifiedAlertingPrometheusConversionSettings @@ -202,6 +204,21 @@ type UnifiedAlertingStateHistorySettings struct { ExternalLabels map[string]string } +type UnifiedAlertingNotificationHistorySettings struct { + Enabled bool + LokiRemoteURL string + LokiReadURL string + LokiWriteURL string + LokiTenantID string + // LokiBasicAuthUsername and LokiBasicAuthPassword are used for basic auth + // if one of them is set. + LokiBasicAuthPassword string + LokiBasicAuthUsername string + LokiMaxQueryLength time.Duration + LokiMaxQuerySize int + ExternalLabels map[string]string +} + // IsEnabled returns true if UnifiedAlertingSettings.Enabled is either nil or true. // It hides the implementation details of the Enabled and simplifies its usage. func (u *UnifiedAlertingSettings) IsEnabled() bool { @@ -472,6 +489,22 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error { } uaCfg.StateHistory = uaCfgStateHistory + notificationHistory := iniFile.Section("unified_alerting.notification_history") + notificationHistoryLabels := iniFile.Section("unified_alerting.notification_history.external_labels") + uaCfgNotificationHistory := UnifiedAlertingNotificationHistorySettings{ + Enabled: notificationHistory.Key("enabled").MustBool(notificationHistoryDefaultEnabled), + LokiRemoteURL: notificationHistory.Key("loki_remote_url").MustString(""), + LokiReadURL: notificationHistory.Key("loki_remote_read_url").MustString(""), + LokiWriteURL: notificationHistory.Key("loki_remote_write_url").MustString(""), + LokiTenantID: notificationHistory.Key("loki_tenant_id").MustString(""), + LokiBasicAuthUsername: notificationHistory.Key("loki_basic_auth_username").MustString(""), + LokiBasicAuthPassword: notificationHistory.Key("loki_basic_auth_password").MustString(""), + LokiMaxQueryLength: notificationHistory.Key("loki_max_query_length").MustDuration(lokiDefaultMaxQueryLength), + LokiMaxQuerySize: notificationHistory.Key("loki_max_query_size").MustInt(lokiDefaultMaxQuerySize), + ExternalLabels: notificationHistoryLabels.KeysHash(), + } + uaCfg.NotificationHistory = uaCfgNotificationHistory + prometheusConversion := iniFile.Section("unified_alerting.prometheus_conversion") uaCfg.PrometheusConversion = UnifiedAlertingPrometheusConversionSettings{ RuleQueryOffset: prometheusConversion.Key("rule_query_offset").MustDuration(time.Minute),