alert rule have to be pending before alerting is for is specified

This commit is contained in:
bergquist 2018-11-15 15:37:46 +01:00
parent 7ba04466a2
commit caec36e7ec
2 changed files with 13 additions and 3 deletions

View File

@ -126,7 +126,7 @@ func (c *EvalContext) GetNewState() m.AlertStateType {
}
since := time.Now().Sub(c.Rule.LastStateChange)
if since > c.Rule.For {
if c.PrevAlertState == m.AlertStatePending && since > c.Rule.For {
return m.AlertStateAlerting
}

View File

@ -66,8 +66,8 @@ func TestGetStateFromEvalContext(t *testing.T) {
},
},
{
name: "ok -> alerting. since its been firing for more than FOR",
expected: models.AlertStateAlerting,
name: "ok -> pending. since it has to be pending longer than FOR and prev state is ok",
expected: models.AlertStatePending,
applyFn: func(ec *EvalContext) {
ec.PrevAlertState = models.AlertStateOK
ec.Firing = true
@ -75,6 +75,16 @@ func TestGetStateFromEvalContext(t *testing.T) {
ec.Rule.For = time.Minute * 2
},
},
{
name: "pending -> alerting. since its been firing for more than FOR and prev state is pending",
expected: models.AlertStateAlerting,
applyFn: func(ec *EvalContext) {
ec.PrevAlertState = models.AlertStatePending
ec.Firing = true
ec.Rule.LastStateChange = time.Now().Add(-(time.Hour * 5))
ec.Rule.For = time.Minute * 2
},
},
{
name: "alerting -> alerting. should not update regardless of FOR",
expected: models.AlertStateAlerting,