Commit ccd89eee by bergquist

renames `debouceduration` to `for`

parent d25284a3
......@@ -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
......
......@@ -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
}
......
......@@ -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
},
},
{
......
......@@ -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() {
......
......@@ -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
......
......@@ -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,
}))
}
......@@ -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;
......
......@@ -28,16 +28,16 @@
<h5 class="section-heading">Alert Config</h5>
<div class="gf-form">
<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 class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-8">Evaluate every</span>
<input class="gf-form-input max-width-5" type="text" ng-model="ctrl.alert.frequency">
<span class="gf-form-label width-9">Evaluate every</span>
<input class="gf-form-input max-width-6" type="text" ng-model="ctrl.alert.frequency">
</div>
<div class="gf-form max-width-15">
<label class="gf-form-label width-10">Debounce duration</label>
<input type="text" class="gf-form-input max-width-5" ng-model="ctrl.alert.debounceDuration" spellcheck='false' placeholder="5m">
<div class="gf-form max-width-11">
<label class="gf-form-label width-5">For</label>
<input type="text" class="gf-form-input max-width-6" ng-model="ctrl.alert.for" spellcheck='false' placeholder="5m">
<info-popover mode="right-absolute">
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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment