Commit 9904e14f by Ben Patterson Committed by Sofia Papagiannaki

Alerting: Fix dates stored in local time when pausing alerts (#19525)

* Make tests more sensitive to timezone.

* Time stamps should use UTC for consistency.

* Test: Assert state is paused after pauseAllAlerts call.
parent 82ce5a19
......@@ -320,10 +320,10 @@ func PauseAlert(cmd *m.PauseAlertCommand) error {
buffer.WriteString(`UPDATE alert SET state = ?, new_state_date = ?`)
if cmd.Paused {
params = append(params, string(m.AlertStatePaused))
params = append(params, timeNow())
params = append(params, timeNow().UTC())
} else {
params = append(params, string(m.AlertStateUnknown))
params = append(params, timeNow())
params = append(params, timeNow().UTC())
}
buffer.WriteString(` WHERE id IN (?` + strings.Repeat(",?", len(cmd.AlertIds)-1) + `)`)
......@@ -351,7 +351,7 @@ func PauseAllAlerts(cmd *m.PauseAllAlertCommand) error {
newState = string(m.AlertStateUnknown)
}
res, err := sess.Exec(`UPDATE alert SET state = ?, new_state_date = ?`, newState, timeNow())
res, err := sess.Exec(`UPDATE alert SET state = ?, new_state_date = ?`, newState, timeNow().UTC())
if err != nil {
return err
}
......
......@@ -12,7 +12,8 @@ import (
func mockTimeNow() {
var timeSeed int64
timeNow = func() time.Time {
fakeNow := time.Unix(timeSeed, 0)
loc := time.FixedZone("MockZoneUTC-5", -5*60*60)
fakeNow := time.Unix(timeSeed, 0).In(loc)
timeSeed++
return fakeNow
}
......@@ -84,6 +85,12 @@ func TestAlertingDataAccess(t *testing.T) {
So(err, ShouldNotBeNil)
})
Convey("alert is paused", func() {
alert, _ = getAlertById(1)
currentState := alert.State
So(currentState, ShouldEqual, "paused")
})
Convey("pausing alerts should update their NewStateDate", func() {
alert, _ = getAlertById(1)
stateDateAfterPause := alert.NewStateDate
......
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