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

@ -78,7 +78,7 @@ type Alert struct {
Silenced bool
ExecutionError string
Frequency int64
DebounceDuration time.Duration
For time.Duration
EvalData *simplejson.Json
NewStateDate time.Time

View File

@ -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
}

View File

@ -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
},
},
{

View File

@ -114,12 +114,12 @@ 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"}
}
}
@ -132,7 +132,7 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
Handler: jsonAlert.Get("handler").MustInt64(),
Message: jsonAlert.Get("message").MustString(),
Frequency: frequency,
DebounceDuration: debounceDuration,
For: forValue,
}
for _, condition := range jsonAlert.Get("conditions").MustArray() {

View File

@ -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

View File

@ -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,
}))
}

View File

@ -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;

View File

@ -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.