Alerting: Keep last state on no data (#6354)
* feat(alerting): add support to keep last state on no data closes #6332 * refactoring(alerting PR #6354): added new option type for NoData option so AlertStateType does not have to contain invalid state, #6354
This commit is contained in:
committed by
Torkel Ödegaard
parent
4999fff29b
commit
bc90e6ce46
@@ -1,57 +1,29 @@
|
||||
package alerting
|
||||
|
||||
// import (
|
||||
// "context"
|
||||
// "testing"
|
||||
// "time"
|
||||
//
|
||||
// "github.com/grafana/grafana/pkg/bus"
|
||||
// m "github.com/grafana/grafana/pkg/models"
|
||||
// "github.com/grafana/grafana/pkg/services/alerting/alertstates"
|
||||
//
|
||||
// "github.com/grafana/grafana/pkg/models"
|
||||
// . "github.com/smartystreets/goconvey/convey"
|
||||
// )
|
||||
//
|
||||
// func TestAlertResultHandler(t *testing.T) {
|
||||
// Convey("Test result Handler", t, func() {
|
||||
// resultHandler := ResultHandlerImpl{}
|
||||
// mockResult := &AlertResultContext{
|
||||
// Triggered: false,
|
||||
// Rule: &AlertRule{
|
||||
// Id: 1,
|
||||
// OrgId 1,
|
||||
// },
|
||||
// }
|
||||
// mockAlertState := &m.AlertState{}
|
||||
// bus.ClearBusHandlers()
|
||||
// bus.AddHandler("test", func(query *m.GetLastAlertStateQuery) error {
|
||||
// query.Result = mockAlertState
|
||||
// return nil
|
||||
// })
|
||||
//
|
||||
// handler := NewResultHandler()
|
||||
// evalContext := NewEvalContext(context.TODO(), &Rule{})
|
||||
//
|
||||
// Convey("Should update", func() {
|
||||
//
|
||||
// Convey("when no earlier alert state", func() {
|
||||
// mockAlertState = nil
|
||||
// So(resultHandler.shouldUpdateState(mockResult), ShouldBeTrue)
|
||||
// })
|
||||
// oldState := models.AlertStateOK
|
||||
//
|
||||
// Convey("alert state have changed", func() {
|
||||
// mockAlertState = &m.AlertState{
|
||||
// State: alertstates.Critical,
|
||||
// }
|
||||
// mockResult.Triggered = false
|
||||
// So(resultHandler.shouldUpdateState(mockResult), ShouldBeTrue)
|
||||
// })
|
||||
// evalContext.Rule.State = models.AlertStateAlerting
|
||||
// evalContext.Rule.NoDataState = models.NoDataKeepState
|
||||
// evalContext.NoDataFound = true
|
||||
//
|
||||
// Convey("last alert state was 15min ago", func() {
|
||||
// now := time.Now()
|
||||
// mockAlertState = &m.AlertState{
|
||||
// State: alertstates.Critical,
|
||||
// Created: now.Add(time.Minute * -30),
|
||||
// }
|
||||
// mockResult.Triggered = true
|
||||
// mockResult.StartTime = time.Now()
|
||||
// So(resultHandler.shouldUpdateState(mockResult), ShouldBeTrue)
|
||||
// So(handler.shouldUpdateAlertState(evalContext, oldState), ShouldBeFalse)
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
||||
Reference in New Issue
Block a user