From 4ccbbaef205646b99232d64df1fe6a3fb5b1a921 Mon Sep 17 00:00:00 2001 From: Ben Ridley Date: Tue, 13 Jul 2021 10:27:13 +1000 Subject: [PATCH 1/4] Ensure time interval comparisons are in UTC Signed-off-by: Ben Ridley --- notify/notify.go | 2 +- notify/notify_test.go | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/notify/notify.go b/notify/notify.go index e1cd5f8075..0ac23def34 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -807,7 +807,7 @@ Loop: return ctx, alerts, errors.Errorf("mute time %s doesn't exist in config", mtName) } for _, ti := range mt { - if ti.ContainsTime(now) { + if ti.ContainsTime(now.UTC()) { muted = true break Loop } diff --git a/notify/notify_test.go b/notify/notify_test.go index d714a0e404..e94f44a6aa 100644 --- a/notify/notify_test.go +++ b/notify/notify_test.go @@ -742,28 +742,40 @@ func TestTimeMuteStage(t *testing.T) { }{ { // Friday during business hours - fireTime: "01 Jan 21 09:00 GMT", + fireTime: "01 Jan 21 09:00 +0000", labels: model.LabelSet{"foo": "bar"}, shouldMute: false, }, { // Tuesday before 5pm - fireTime: "01 Dec 20 16:59 GMT", + fireTime: "01 Dec 20 16:59 +0000", labels: model.LabelSet{"dont": "mute"}, shouldMute: false, }, { // Saturday - fireTime: "17 Oct 20 10:00 GMT", + fireTime: "17 Oct 20 10:00 +0000", labels: model.LabelSet{"mute": "me"}, shouldMute: true, }, { // Wednesday before 9am - fireTime: "14 Oct 20 05:00 GMT", + fireTime: "14 Oct 20 05:00 +0000", labels: model.LabelSet{"mute": "me"}, shouldMute: true, }, + { + // Ensure comparisons are UTC only. 12:00 KST should be muted (03:00 UTC) + fireTime: "14 Oct 20 12:00 +0900", + labels: model.LabelSet{"kst": "mute"}, + shouldMute: true, + }, + { + // Ensure comparisons are UTC only. 22:00 KST should not be muted (13:00 UTC) + fireTime: "14 Oct 20 22:00 +0900", + labels: model.LabelSet{"kmt": "dont_mute"}, + shouldMute: false, + }, } var intervals []timeinterval.TimeInterval err := yaml.Unmarshal([]byte(muteIn), &intervals) @@ -776,7 +788,7 @@ func TestTimeMuteStage(t *testing.T) { outAlerts := []*types.Alert{} nonMuteCount := 0 for _, tc := range cases { - now, err := time.Parse(time.RFC822, tc.fireTime) + now, err := time.Parse(time.RFC822Z, tc.fireTime) if err != nil { t.Fatalf("Couldn't parse fire time %s %s", tc.fireTime, err) } From c70481f71f4be24d100094d4fb4b9b8828470595 Mon Sep 17 00:00:00 2001 From: Ben Ridley Date: Tue, 13 Jul 2021 10:32:18 +1000 Subject: [PATCH 2/4] Fix minor timezone typo to help debugging. Signed-off-by: Ben Ridley --- notify/notify_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify/notify_test.go b/notify/notify_test.go index e94f44a6aa..f90acfb745 100644 --- a/notify/notify_test.go +++ b/notify/notify_test.go @@ -773,7 +773,7 @@ func TestTimeMuteStage(t *testing.T) { { // Ensure comparisons are UTC only. 22:00 KST should not be muted (13:00 UTC) fireTime: "14 Oct 20 22:00 +0900", - labels: model.LabelSet{"kmt": "dont_mute"}, + labels: model.LabelSet{"kst": "dont_mute"}, shouldMute: false, }, } From 01287a4b6d9c4843a5099fb5e7cd2b9f2722109e Mon Sep 17 00:00:00 2001 From: Ben Ridley Date: Tue, 13 Jul 2021 13:48:16 +1000 Subject: [PATCH 3/4] Fix test case not being included in mute count Signed-off-by: Ben Ridley --- notify/notify_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notify/notify_test.go b/notify/notify_test.go index f90acfb745..0835cf56df 100644 --- a/notify/notify_test.go +++ b/notify/notify_test.go @@ -767,13 +767,13 @@ func TestTimeMuteStage(t *testing.T) { { // Ensure comparisons are UTC only. 12:00 KST should be muted (03:00 UTC) fireTime: "14 Oct 20 12:00 +0900", - labels: model.LabelSet{"kst": "mute"}, + labels: model.LabelSet{"mute": "kst"}, shouldMute: true, }, { // Ensure comparisons are UTC only. 22:00 KST should not be muted (13:00 UTC) fireTime: "14 Oct 20 22:00 +0900", - labels: model.LabelSet{"kst": "dont_mute"}, + labels: model.LabelSet{"kmt": "dont_mute"}, shouldMute: false, }, } From a1136942bb0d9ddf36c41a21f6a53484cf04be63 Mon Sep 17 00:00:00 2001 From: Ben Ridley Date: Tue, 13 Jul 2021 13:49:30 +1000 Subject: [PATCH 4/4] Fix typo in label to help debugging (again) Signed-off-by: Ben Ridley --- notify/notify_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify/notify_test.go b/notify/notify_test.go index 0835cf56df..3f6885fd02 100644 --- a/notify/notify_test.go +++ b/notify/notify_test.go @@ -773,7 +773,7 @@ func TestTimeMuteStage(t *testing.T) { { // Ensure comparisons are UTC only. 22:00 KST should not be muted (13:00 UTC) fireTime: "14 Oct 20 22:00 +0900", - labels: model.LabelSet{"kmt": "dont_mute"}, + labels: model.LabelSet{"kst": "dont_mute"}, shouldMute: false, }, }