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{
|
store := &store.DBstore{
|
||||||
BaseInterval: ng.Cfg.UnifiedAlerting.BaseInterval,
|
BaseInterval: ng.Cfg.UnifiedAlerting.BaseInterval,
|
||||||
DefaultInterval: ng.Cfg.UnifiedAlerting.DefaultAlertForDuration,
|
DefaultInterval: ng.Cfg.UnifiedAlerting.DefaultRuleEvaluationInterval,
|
||||||
SQLStore: ng.SQLStore,
|
SQLStore: ng.SQLStore,
|
||||||
Logger: ng.Log,
|
Logger: ng.Log,
|
||||||
FolderService: ng.folderService,
|
FolderService: ng.folderService,
|
||||||
|
@ -52,8 +52,8 @@ const (
|
|||||||
// changing this value is discouraged because this could cause existing alert definition
|
// 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
|
// with intervals that are not exactly divided by this number not to be evaluated
|
||||||
SchedulerBaseInterval = 10 * time.Second
|
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
|
// DefaultRuleEvaluationInterval 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 = SchedulerBaseInterval * 6 // == 60 seconds
|
||||||
)
|
)
|
||||||
|
|
||||||
type UnifiedAlertingSettings struct {
|
type UnifiedAlertingSettings struct {
|
||||||
@ -75,8 +75,8 @@ type UnifiedAlertingSettings struct {
|
|||||||
// BaseInterval interval of time the scheduler updates the rules and evaluates rules.
|
// BaseInterval interval of time the scheduler updates the rules and evaluates rules.
|
||||||
// Only for internal use and not user configuration.
|
// Only for internal use and not user configuration.
|
||||||
BaseInterval time.Duration
|
BaseInterval time.Duration
|
||||||
// DefaultAlertForDuration default time for how long an alert rule should be evaluated before change state.
|
// DefaultRuleEvaluationInterval default interval between evaluations of a rule.
|
||||||
DefaultAlertForDuration time.Duration
|
DefaultRuleEvaluationInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEnabled returns true if UnifiedAlertingSettings.Enabled is either nil or true.
|
// 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.MinInterval = uaMinInterval
|
||||||
|
|
||||||
uaCfg.DefaultAlertForDuration = DefaultAlertForDuration
|
uaCfg.DefaultRuleEvaluationInterval = DefaultRuleEvaluationInterval
|
||||||
if uaMinInterval > uaCfg.DefaultAlertForDuration {
|
if uaMinInterval > uaCfg.DefaultRuleEvaluationInterval {
|
||||||
uaCfg.DefaultAlertForDuration = uaMinInterval
|
uaCfg.DefaultRuleEvaluationInterval = uaMinInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.UnifiedAlerting = uaCfg
|
cfg.UnifiedAlerting = uaCfg
|
||||||
|
@ -70,7 +70,7 @@ func TestUnifiedAlertingSettings(t *testing.T) {
|
|||||||
require.Equal(t, false, cfg.UnifiedAlerting.ExecuteAlerts)
|
require.Equal(t, false, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||||
require.Equal(t, 90*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
require.Equal(t, 90*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
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, true, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||||
require.Equal(t, 160*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
require.Equal(t, 160*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
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, schedulereDefaultExecuteAlerts, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||||
require.Equal(t, evaluatorDefaultEvaluationTimeout, cfg.UnifiedAlerting.EvaluationTimeout)
|
require.Equal(t, evaluatorDefaultEvaluationTimeout, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
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, false, cfg.UnifiedAlerting.ExecuteAlerts)
|
||||||
require.Equal(t, 160*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
require.Equal(t, 160*time.Second, cfg.UnifiedAlerting.EvaluationTimeout)
|
||||||
require.Equal(t, SchedulerBaseInterval, cfg.UnifiedAlerting.BaseInterval)
|
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",
|
desc: "should adjust DefaultRuleEvaluationInterval to min interval if it is greater",
|
||||||
minInterval: randPredicate(func(dur time.Duration) bool { return dur%SchedulerBaseInterval == 0 && dur > DefaultAlertForDuration }),
|
minInterval: randPredicate(func(dur time.Duration) bool {
|
||||||
|
return dur%SchedulerBaseInterval == 0 && dur > DefaultRuleEvaluationInterval
|
||||||
|
}),
|
||||||
verifyCfg: func(t *testing.T, cfg *Cfg, err error) {
|
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