Commit caec36e7 by bergquist

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

parent 7ba04466
......@@ -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
}
......
......@@ -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
......@@ -76,6 +76,16 @@ func TestGetStateFromEvalContext(t *testing.T) {
},
},
{
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,
applyFn: func(ec *EvalContext) {
......
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