mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Rename setting AlertForDuration to DefaultRuleEvaluationInterval (#45569)
* fix AlertForDuration to DefaultRuleEvaluationInterval Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
This commit is contained in:
parent
25f155a44d
commit
e44ea3d589
@ -84,7 +84,7 @@ func (ng *AlertNG) init() error {
|
||||
|
||||
store := &store.DBstore{
|
||||
BaseInterval: ng.Cfg.UnifiedAlerting.BaseInterval,
|
||||
DefaultInterval: ng.Cfg.UnifiedAlerting.DefaultAlertForDuration,
|
||||
DefaultInterval: ng.Cfg.UnifiedAlerting.DefaultRuleEvaluationInterval,
|
||||
SQLStore: ng.SQLStore,
|
||||
Logger: ng.Log,
|
||||
FolderService: ng.folderService,
|
||||
|
@ -52,8 +52,8 @@ const (
|
||||
// changing this value is discouraged because this could cause existing alert definition
|
||||
// with intervals that are not exactly divided by this number not to be evaluated
|
||||
SchedulerBaseInterval = 10 * time.Second
|
||||
// DefaultAlertForDuration indicates a default interval of for how long a rule should be evaluated to change state from Pending to Alerting
|
||||
DefaultAlertForDuration = 60 * 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
|
||||
)
|
||||
|
||||
type UnifiedAlertingSettings struct {
|
||||
@ -75,8 +75,8 @@ type UnifiedAlertingSettings struct {
|
||||
// BaseInterval interval of time the scheduler updates the rules and evaluates rules.
|
||||
// Only for internal use and not user configuration.
|
||||
BaseInterval time.Duration
|
||||
// DefaultAlertForDuration default time for how long an alert rule should be evaluated before change state.
|
||||
DefaultAlertForDuration time.Duration
|
||||
// DefaultRuleEvaluationInterval default interval between evaluations of a rule.
|
||||
DefaultRuleEvaluationInterval time.Duration
|
||||
}
|
||||
|
||||
// IsEnabled returns true if UnifiedAlertingSettings.Enabled is either nil or true.
|
||||
@ -239,9 +239,9 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
|
||||
}
|
||||
uaCfg.MinInterval = uaMinInterval
|
||||
|
||||
uaCfg.DefaultAlertForDuration = DefaultAlertForDuration
|
||||
if uaMinInterval > uaCfg.DefaultAlertForDuration {
|
||||
uaCfg.DefaultAlertForDuration = uaMinInterval
|
||||
uaCfg.DefaultRuleEvaluationInterval = DefaultRuleEvaluationInterval
|
||||
if uaMinInterval > uaCfg.DefaultRuleEvaluationInterval {
|
||||
uaCfg.DefaultRuleEvaluationInterval = uaMinInterval
|
||||
}
|
||||
|
||||
cfg.UnifiedAlerting = uaCfg
|
||||
|
@ -70,7 +70,7 @@ func TestUnifiedAlertingSettings(t *testing.T) {
|
||||
require.Equal(t, false, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||
require.Equal(t, 90*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
||||
require.Equal(t, DefaultAlertForDuration, cfg.UnifiedAlerting.DefaultAlertForDuration)
|
||||
require.Equal(t, DefaultRuleEvaluationInterval, cfg.UnifiedAlerting.DefaultRuleEvaluationInterval)
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -95,7 +95,7 @@ func TestUnifiedAlertingSettings(t *testing.T) {
|
||||
require.Equal(t, true, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||
require.Equal(t, 160*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
||||
require.Equal(t, 120*time.Second, cfg.UnifiedAlerting.DefaultAlertForDuration)
|
||||
require.Equal(t, 120*time.Second, cfg.UnifiedAlerting.DefaultRuleEvaluationInterval)
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -119,7 +119,7 @@ func TestUnifiedAlertingSettings(t *testing.T) {
|
||||
require.Equal(t, schedulereDefaultExecuteAlerts, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||
require.Equal(t, evaluatorDefaultEvaluationTimeout, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
||||
require.Equal(t, DefaultAlertForDuration, cfg.UnifiedAlerting.DefaultAlertForDuration)
|
||||
require.Equal(t, DefaultRuleEvaluationInterval, cfg.UnifiedAlerting.DefaultRuleEvaluationInterval)
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -143,7 +143,7 @@ func TestUnifiedAlertingSettings(t *testing.T) {
|
||||
require.Equal(t, false, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||
require.Equal(t, 160*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
||||
require.Equal(t, 120*time.Second, cfg.UnifiedAlerting.DefaultAlertForDuration)
|
||||
require.Equal(t, 120*time.Second, cfg.UnifiedAlerting.DefaultRuleEvaluationInterval)
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -227,10 +227,12 @@ func TestMinInterval(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "should adjust DefaultAlertForDuration to min interval if it is greater",
|
||||
minInterval: randPredicate(func(dur time.Duration) bool { return dur%SchedulerBaseInterval == 0 && dur > DefaultAlertForDuration }),
|
||||
desc: "should adjust DefaultRuleEvaluationInterval to min interval if it is greater",
|
||||
minInterval: randPredicate(func(dur time.Duration) bool {
|
||||
return dur%SchedulerBaseInterval == 0 && dur > DefaultRuleEvaluationInterval
|
||||
}),
|
||||
verifyCfg: func(t *testing.T, cfg *Cfg, err error) {
|
||||
require.Equal(t, cfg.UnifiedAlerting.MinInterval, cfg.UnifiedAlerting.DefaultAlertForDuration)
|
||||
require.Equal(t, cfg.UnifiedAlerting.MinInterval, cfg.UnifiedAlerting.DefaultRuleEvaluationInterval)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user