From 2d3a5754891ddc093524dc72138272a72160694f Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 2 Nov 2018 09:00:56 +0100 Subject: [PATCH] adds db migration for debounce_duration --- pkg/models/alert.go | 27 ++++++++++--------- pkg/services/alerting/rule.go | 2 +- pkg/services/sqlstore/migrations/alert_mig.go | 4 +++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/pkg/models/alert.go b/pkg/models/alert.go index ba1fc0779ba..e35ba106688 100644 --- a/pkg/models/alert.go +++ b/pkg/models/alert.go @@ -59,19 +59,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 - State AlertStateType - Handler int64 - Silenced bool - ExecutionError string - Frequency int64 + 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 EvalData *simplejson.Json NewStateDate time.Time diff --git a/pkg/services/alerting/rule.go b/pkg/services/alerting/rule.go index 3fb69b48f9f..c9fbddbf393 100644 --- a/pkg/services/alerting/rule.go +++ b/pkg/services/alerting/rule.go @@ -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 = time.Minute * 2 // hard coded for now + model.DebounceDuration = time.Duration(ruleDef.DebounceDuration) 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 198a47b50ff..f575fb3b02b 100644 --- a/pkg/services/sqlstore/migrations/alert_mig.go +++ b/pkg/services/sqlstore/migrations/alert_mig.go @@ -133,4 +133,8 @@ func addAlertMigrations(mg *Migrator) { mg.AddMigration("create alert_notification_state table v1", NewAddTableMigration(alert_notification_state)) 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, + })) }