renames debouceduration to for

This commit is contained in:
bergquist
2018-11-05 11:05:30 +01:00
parent d25284a364
commit ccd89eee97
8 changed files with 45 additions and 45 deletions

View File

@ -65,20 +65,20 @@ func (s ExecutionErrorOption) ToAlertState() AlertStateType {
} }
type Alert struct { type Alert struct {
Id int64 Id int64
Version int64 Version int64
OrgId int64 OrgId int64
DashboardId int64 DashboardId int64
PanelId int64 PanelId int64
Name string Name string
Message string Message string
Severity string //Unused Severity string //Unused
State AlertStateType State AlertStateType
Handler int64 //Unused Handler int64 //Unused
Silenced bool Silenced bool
ExecutionError string ExecutionError string
Frequency int64 Frequency int64
DebounceDuration time.Duration For time.Duration
EvalData *simplejson.Json EvalData *simplejson.Json
NewStateDate time.Time NewStateDate time.Time

View File

@ -132,9 +132,9 @@ func (c *EvalContext) GetNewState() m.AlertStateType {
return c.Rule.ExecutionErrorState.ToAlertState() 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) since := time.Now().Sub(c.Rule.LastStateChange)
if since > c.Rule.DebounceDuration { if since > c.Rule.For {
return m.AlertStateAlerting return m.AlertStateAlerting
} }

View File

@ -62,7 +62,7 @@ func TestGetStateFromEvalContext(t *testing.T) {
ec.PrevAlertState = models.AlertStateOK ec.PrevAlertState = models.AlertStateOK
ec.Firing = true ec.Firing = true
ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 2) 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.PrevAlertState = models.AlertStateOK
ec.Firing = true ec.Firing = true
ec.Rule.LastStateChange = time.Now().Add(-(time.Hour * 5)) 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.PrevAlertState = models.AlertStateAlerting
ec.Firing = true ec.Firing = true
ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 5) 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) { applyFn: func(ec *EvalContext) {
ec.PrevAlertState = models.AlertStateOK ec.PrevAlertState = models.AlertStateOK
ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 5) ec.Rule.LastStateChange = time.Now().Add(-time.Minute * 5)
ec.Rule.DebounceDuration = time.Minute * 2 ec.Rule.For = time.Minute * 2
}, },
}, },
{ {

View File

@ -114,25 +114,25 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
return nil, ValidationError{Reason: "Could not parse frequency"} return nil, ValidationError{Reason: "Could not parse frequency"}
} }
rawDebouce := jsonAlert.Get("debounceDuration").MustString() rawFow := jsonAlert.Get("for").MustString()
var debounceDuration time.Duration var forValue time.Duration
if rawDebouce != "" { if rawFow != "" {
debounceDuration, err = time.ParseDuration(rawDebouce) forValue, err = time.ParseDuration(rawFow)
if err != nil { if err != nil {
return nil, ValidationError{Reason: "Could not parse debounceDuration"} return nil, ValidationError{Reason: "Could not parse for"}
} }
} }
alert := &m.Alert{ alert := &m.Alert{
DashboardId: e.Dash.Id, DashboardId: e.Dash.Id,
OrgId: e.OrgID, OrgId: e.OrgID,
PanelId: panelID, PanelId: panelID,
Id: jsonAlert.Get("id").MustInt64(), Id: jsonAlert.Get("id").MustInt64(),
Name: jsonAlert.Get("name").MustString(), Name: jsonAlert.Get("name").MustString(),
Handler: jsonAlert.Get("handler").MustInt64(), Handler: jsonAlert.Get("handler").MustInt64(),
Message: jsonAlert.Get("message").MustString(), Message: jsonAlert.Get("message").MustString(),
Frequency: frequency, Frequency: frequency,
DebounceDuration: debounceDuration, For: forValue,
} }
for _, condition := range jsonAlert.Get("conditions").MustArray() { for _, condition := range jsonAlert.Get("conditions").MustArray() {

View File

@ -20,7 +20,7 @@ type Rule struct {
Name string Name string
Message string Message string
LastStateChange time.Time LastStateChange time.Time
DebounceDuration time.Duration For time.Duration
NoDataState m.NoDataOption NoDataState m.NoDataOption
ExecutionErrorState m.ExecutionErrorOption ExecutionErrorState m.ExecutionErrorOption
State m.AlertStateType State m.AlertStateType
@ -104,7 +104,7 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
model.Frequency = ruleDef.Frequency model.Frequency = ruleDef.Frequency
model.State = ruleDef.State model.State = ruleDef.State
model.LastStateChange = ruleDef.NewStateDate model.LastStateChange = ruleDef.NewStateDate
model.DebounceDuration = ruleDef.DebounceDuration model.For = ruleDef.For
model.NoDataState = m.NoDataOption(ruleDef.Settings.Get("noDataState").MustString("no_data")) model.NoDataState = m.NoDataOption(ruleDef.Settings.Get("noDataState").MustString("no_data"))
model.ExecutionErrorState = m.ExecutionErrorOption(ruleDef.Settings.Get("executionErrorState").MustString("alerting")) model.ExecutionErrorState = m.ExecutionErrorOption(ruleDef.Settings.Get("executionErrorState").MustString("alerting"))
model.StateChanges = ruleDef.StateChanges model.StateChanges = ruleDef.StateChanges

View File

@ -134,7 +134,7 @@ func addAlertMigrations(mg *Migrator) {
mg.AddMigration("add index alert_notification_state org_id & alert_id & notifier_id", mg.AddMigration("add index alert_notification_state org_id & alert_id & notifier_id",
NewAddIndexMigration(alert_notification_state, alert_notification_state.Indices[0])) NewAddIndexMigration(alert_notification_state, alert_notification_state.Indices[0]))
mg.AddMigration("Add decounce_duration to alert table", NewAddColumnMigration(alertV1, &Column{ mg.AddMigration("Add for to alert table", NewAddColumnMigration(alertV1, &Column{
Name: "debounce_duration", Type: DB_BigInt, Nullable: true, Name: "for", Type: DB_BigInt, Nullable: true,
})) }))
} }

View File

@ -169,7 +169,7 @@ export class AlertTabCtrl {
alert.frequency = alert.frequency || '1m'; alert.frequency = alert.frequency || '1m';
alert.handler = alert.handler || 1; alert.handler = alert.handler || 1;
alert.notifications = alert.notifications || []; alert.notifications = alert.notifications || [];
alert.debounceDuration = alert.debounceDuration || '5m'; alert.for = alert.for || '5m';
const defaultName = this.panel.title + ' alert'; const defaultName = this.panel.title + ' alert';
alert.name = alert.name || defaultName; alert.name = alert.name || defaultName;

View File

@ -28,16 +28,16 @@
<h5 class="section-heading">Alert Config</h5> <h5 class="section-heading">Alert Config</h5>
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-6">Name</span> <span class="gf-form-label width-6">Name</span>
<input type="text" class="gf-form-input width-22" ng-model="ctrl.alert.name"> <input type="text" class="gf-form-input width-20" ng-model="ctrl.alert.name">
</div> </div>
<div class="gf-form-inline"> <div class="gf-form-inline">
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-8">Evaluate every</span> <span class="gf-form-label width-9">Evaluate every</span>
<input class="gf-form-input max-width-5" type="text" ng-model="ctrl.alert.frequency"> <input class="gf-form-input max-width-6" type="text" ng-model="ctrl.alert.frequency">
</div> </div>
<div class="gf-form max-width-15"> <div class="gf-form max-width-11">
<label class="gf-form-label width-10">Debounce duration</label> <label class="gf-form-label width-5">For</label>
<input type="text" class="gf-form-input max-width-5" ng-model="ctrl.alert.debounceDuration" spellcheck='false' placeholder="5m"> <input type="text" class="gf-form-input max-width-6" ng-model="ctrl.alert.for" spellcheck='false' placeholder="5m">
<info-popover mode="right-absolute"> <info-popover mode="right-absolute">
Configuring this value means that an alert rule have to be firing for atleast this duration before changing state. 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. This should reduce false positive alerts and avoid flapping alerts.