mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Allow state history to be disabled through configuration (#61006)
* Add configuration option for if state history should be enabled * Inject no-op when history is disabled
This commit is contained in:
@@ -60,6 +60,7 @@ const (
|
||||
SchedulerBaseInterval = 10 * time.Second
|
||||
// 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
|
||||
)
|
||||
|
||||
type UnifiedAlertingSettings struct {
|
||||
@@ -85,6 +86,7 @@ type UnifiedAlertingSettings struct {
|
||||
DefaultRuleEvaluationInterval time.Duration
|
||||
Screenshots UnifiedAlertingScreenshotSettings
|
||||
ReservedLabels UnifiedAlertingReservedLabelSettings
|
||||
StateHistory UnifiedAlertingStateHistorySettings
|
||||
}
|
||||
|
||||
type UnifiedAlertingScreenshotSettings struct {
|
||||
@@ -98,6 +100,10 @@ type UnifiedAlertingReservedLabelSettings struct {
|
||||
DisabledLabels map[string]struct{}
|
||||
}
|
||||
|
||||
type UnifiedAlertingStateHistorySettings struct {
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
// 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 {
|
||||
@@ -304,6 +310,12 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
|
||||
}
|
||||
uaCfg.ReservedLabels = uaCfgReservedLabels
|
||||
|
||||
stateHistory := iniFile.Section("unified_alerting.state_history")
|
||||
uaCfgStateHistory := UnifiedAlertingStateHistorySettings{
|
||||
Enabled: stateHistory.Key("enabled").MustBool(stateHistoryDefaultEnabled),
|
||||
}
|
||||
uaCfg.StateHistory = uaCfgStateHistory
|
||||
|
||||
cfg.UnifiedAlerting = uaCfg
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user