From ccd89eee974d08f7f74f7859767e8f32a347e2a5 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 5 Nov 2018 11:05:30 +0100 Subject: [PATCH] renames `debouceduration` to `for` --- pkg/models/alert.go | 28 +++++++++---------- pkg/services/alerting/eval_context.go | 4 +-- pkg/services/alerting/eval_context_test.go | 8 +++--- pkg/services/alerting/extractor.go | 28 +++++++++---------- pkg/services/alerting/rule.go | 4 +-- pkg/services/sqlstore/migrations/alert_mig.go | 4 +-- public/app/features/alerting/AlertTabCtrl.ts | 2 +- .../features/alerting/partials/alert_tab.html | 12 ++++---- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/pkg/models/alert.go b/pkg/models/alert.go index 37f40134796..760e9eada48 100644 --- a/pkg/models/alert.go +++ b/pkg/models/alert.go @@ -65,20 +65,20 @@ func (s ExecutionErrorOption) ToAlertState() AlertStateType { } type Alert struct { - Id int64 - Version int64 - OrgId int64 - DashboardId int64 - PanelId int64 - Name string - Message string - Severity string //Unused - State AlertStateType - Handler int64 //Unused - Silenced bool - ExecutionError string - Frequency int64 - DebounceDuration time.Duration + Id int64 + Version int64 + OrgId int64 + DashboardId int64 + PanelId int64 + Name string + Message string + Severity string //Unused + State AlertStateType + Handler int64 //Unused + Silenced bool + ExecutionError string + Frequency int64 + For time.Duration EvalData *simplejson.Json NewStateDate time.Time diff --git a/pkg/services/alerting/eval_context.go b/pkg/services/alerting/eval_context.go index 8986af85406..208fe1d188b 100644 --- a/pkg/services/alerting/eval_context.go +++ b/pkg/services/alerting/eval_context.go @@ -132,9 +132,9 @@ func (c *EvalContext) GetNewState() m.AlertStateType { return c.Rule.ExecutionErrorState.ToAlertState() } - if c.Firing && c.Rule.DebounceDuration != 0 { + if c.Firing && c.Rule.For != 0 { since := time.Now().Sub(c.Rule.LastStateChange) - if since > c.Rule.DebounceDuration { + if since > c.Rule.For { return m.AlertStateAlerting } diff --git a/pkg/services/alerting/eval_context_test.go b/pkg/services/alerting/eval_context_test.go index 2abf581d830..cc0bed79d10 100644 --- a/pkg/services/alerting/eval_context_test.go +++ b/pkg/services/alerting/eval_context_test.go @@ -62,7 +62,7 @@ func TestGetStateFromEvalContext(t *testing.T) { ec.PrevAlertState = models.AlertStateOK ec.Firing = true ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 2) - ec.Rule.DebounceDuration = time.Minute * 5 + ec.Rule.For = time.Minute * 5 }, }, { @@ -72,7 +72,7 @@ func TestGetStateFromEvalContext(t *testing.T) { ec.PrevAlertState = models.AlertStateOK ec.Firing = true ec.Rule.LastStateChange = time.Now().Add(-(time.Hour * 5)) - ec.Rule.DebounceDuration = time.Minute * 2 + ec.Rule.For = time.Minute * 2 }, }, { @@ -82,7 +82,7 @@ func TestGetStateFromEvalContext(t *testing.T) { ec.PrevAlertState = models.AlertStateAlerting ec.Firing = true ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 5) - ec.Rule.DebounceDuration = time.Minute * 2 + ec.Rule.For = time.Minute * 2 }, }, { @@ -91,7 +91,7 @@ func TestGetStateFromEvalContext(t *testing.T) { applyFn: func(ec *EvalContext) { ec.PrevAlertState = models.AlertStateOK ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 5) - ec.Rule.DebounceDuration = time.Minute * 2 + ec.Rule.For = time.Minute * 2 }, }, { diff --git a/pkg/services/alerting/extractor.go b/pkg/services/alerting/extractor.go index 221d58feaf2..244dc0a0770 100644 --- a/pkg/services/alerting/extractor.go +++ b/pkg/services/alerting/extractor.go @@ -114,25 +114,25 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json, return nil, ValidationError{Reason: "Could not parse frequency"} } - rawDebouce := jsonAlert.Get("debounceDuration").MustString() - var debounceDuration time.Duration - if rawDebouce != "" { - debounceDuration, err = time.ParseDuration(rawDebouce) + rawFow := jsonAlert.Get("for").MustString() + var forValue time.Duration + if rawFow != "" { + forValue, err = time.ParseDuration(rawFow) if err != nil { - return nil, ValidationError{Reason: "Could not parse debounceDuration"} + return nil, ValidationError{Reason: "Could not parse for"} } } alert := &m.Alert{ - DashboardId: e.Dash.Id, - OrgId: e.OrgID, - PanelId: panelID, - Id: jsonAlert.Get("id").MustInt64(), - Name: jsonAlert.Get("name").MustString(), - Handler: jsonAlert.Get("handler").MustInt64(), - Message: jsonAlert.Get("message").MustString(), - Frequency: frequency, - DebounceDuration: debounceDuration, + DashboardId: e.Dash.Id, + OrgId: e.OrgID, + PanelId: panelID, + Id: jsonAlert.Get("id").MustInt64(), + Name: jsonAlert.Get("name").MustString(), + Handler: jsonAlert.Get("handler").MustInt64(), + Message: jsonAlert.Get("message").MustString(), + Frequency: frequency, + For: forValue, } for _, condition := range jsonAlert.Get("conditions").MustArray() { diff --git a/pkg/services/alerting/rule.go b/pkg/services/alerting/rule.go index ac1885fb380..d2a505145ac 100644 --- a/pkg/services/alerting/rule.go +++ b/pkg/services/alerting/rule.go @@ -20,7 +20,7 @@ type Rule struct { Name string Message string LastStateChange time.Time - DebounceDuration time.Duration + For time.Duration NoDataState m.NoDataOption ExecutionErrorState m.ExecutionErrorOption State m.AlertStateType @@ -104,7 +104,7 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) { model.Frequency = ruleDef.Frequency model.State = ruleDef.State model.LastStateChange = ruleDef.NewStateDate - model.DebounceDuration = ruleDef.DebounceDuration + model.For = ruleDef.For model.NoDataState = m.NoDataOption(ruleDef.Settings.Get("noDataState").MustString("no_data")) model.ExecutionErrorState = m.ExecutionErrorOption(ruleDef.Settings.Get("executionErrorState").MustString("alerting")) model.StateChanges = ruleDef.StateChanges diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go index f575fb3b02b..b5aeb26483c 100644 --- a/pkg/services/sqlstore/migrations/alert_mig.go +++ b/pkg/services/sqlstore/migrations/alert_mig.go @@ -134,7 +134,7 @@ func addAlertMigrations(mg *Migrator) { mg.AddMigration("add index alert_notification_state org_id & alert_id & notifier_id", NewAddIndexMigration(alert_notification_state, alert_notification_state.Indices[0])) - mg.AddMigration("Add decounce_duration to alert table", NewAddColumnMigration(alertV1, &Column{ - Name: "debounce_duration", Type: DB_BigInt, Nullable: true, + mg.AddMigration("Add for to alert table", NewAddColumnMigration(alertV1, &Column{ + Name: "for", Type: DB_BigInt, Nullable: true, })) } diff --git a/public/app/features/alerting/AlertTabCtrl.ts b/public/app/features/alerting/AlertTabCtrl.ts index 43752d0a8c9..758b3273d1a 100644 --- a/public/app/features/alerting/AlertTabCtrl.ts +++ b/public/app/features/alerting/AlertTabCtrl.ts @@ -169,7 +169,7 @@ export class AlertTabCtrl { alert.frequency = alert.frequency || '1m'; alert.handler = alert.handler || 1; alert.notifications = alert.notifications || []; - alert.debounceDuration = alert.debounceDuration || '5m'; + alert.for = alert.for || '5m'; const defaultName = this.panel.title + ' alert'; alert.name = alert.name || defaultName; diff --git a/public/app/features/alerting/partials/alert_tab.html b/public/app/features/alerting/partials/alert_tab.html index de5fc4df382..676a1d32937 100644 --- a/public/app/features/alerting/partials/alert_tab.html +++ b/public/app/features/alerting/partials/alert_tab.html @@ -28,16 +28,16 @@
Alert Config
Name - +
- Evaluate every - + Evaluate every +
-
- - +
+ + Configuring this value means that an alert rule have to be firing for atleast this duration before changing state. This should reduce false positive alerts and avoid flapping alerts.