mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
alert rule have to be pending before alerting is for is specified
This commit is contained in:
parent
7ba04466a2
commit
caec36e7ec
@ -126,7 +126,7 @@ func (c *EvalContext) GetNewState() m.AlertStateType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
since := time.Now().Sub(c.Rule.LastStateChange)
|
since := time.Now().Sub(c.Rule.LastStateChange)
|
||||||
if since > c.Rule.For {
|
if c.PrevAlertState == m.AlertStatePending && since > c.Rule.For {
|
||||||
return m.AlertStateAlerting
|
return m.AlertStateAlerting
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ func TestGetStateFromEvalContext(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ok -> alerting. since its been firing for more than FOR",
|
name: "ok -> pending. since it has to be pending longer than FOR and prev state is ok",
|
||||||
expected: models.AlertStateAlerting,
|
expected: models.AlertStatePending,
|
||||||
applyFn: func(ec *EvalContext) {
|
applyFn: func(ec *EvalContext) {
|
||||||
ec.PrevAlertState = models.AlertStateOK
|
ec.PrevAlertState = models.AlertStateOK
|
||||||
ec.Firing = true
|
ec.Firing = true
|
||||||
@ -75,6 +75,16 @@ func TestGetStateFromEvalContext(t *testing.T) {
|
|||||||
ec.Rule.For = time.Minute * 2
|
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",
|
name: "alerting -> alerting. should not update regardless of FOR",
|
||||||
expected: models.AlertStateAlerting,
|
expected: models.AlertStateAlerting,
|
||||||
|
Loading…
Reference in New Issue
Block a user