Skip to content

Commit

Permalink
Fix zeroed EndsAt timestamp
Browse files Browse the repository at this point in the history
This commit fixes a bug where firing alerts had zeroed EndsAt
timestamps in notifications. This bug was introduced in another
PR (#1686) to fix issues where alerts are resolved during a flush.

(Commit message from George Robinson)

Update the acceptance tests as the webhook now has a non-zero EndsAt
timestamp for firing alerts. The models.GettableAlert doesn't havea
`status` field which means the current test is unable to differentiate
between firing and resolved alerts.

Signed-off-by: Holger Hans Peter Freyther <[email protected]>
  • Loading branch information
zecke committed May 5, 2024
1 parent b145828 commit 933c3af
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 87 deletions.
2 changes: 1 addition & 1 deletion test/cli/acceptance/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ receivers:

alert1 := Alert("alertname", "test1").Active(1, 2)
am.AddAlertsAt(false, 0, alert1)
co.Want(Between(1, 2), Alert("alertname", "test1").Active(1))
co.Want(Between(1, 2), Alert("alertname", "test1").Active(1, 2))

at.Run()

Expand Down
18 changes: 13 additions & 5 deletions test/with_api_v2/acceptance/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestClusterDeduplication(t *testing.T) {
t.Parallel()

conf := `
global:
resolve_timeout: %v
route:
receiver: "default"
group_by: []
Expand All @@ -47,11 +49,11 @@ receivers:
co := at.Collector("webhook")
wh := a.NewWebhook(t, co)

amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 3)
amc := at.AlertmanagerCluster(fmt.Sprintf(conf, resolveTimeout, wh.Address()), 3)

amc.Push(a.At(1), a.Alert("alertname", "test1"))

co.Want(a.Between(2, 3), a.Alert("alertname", "test1").Active(1))
co.Want(a.Between(2, 3), a.Alert("alertname", "test1").Active(1, 1+resolveTimeout.Seconds()))

at.Run()

Expand All @@ -64,6 +66,8 @@ func TestClusterVSInstance(t *testing.T) {
t.Parallel()

conf := `
global:
resolve_timeout: %v
route:
receiver: "default"
group_by: [ "alertname" ]
Expand Down Expand Up @@ -98,16 +102,16 @@ receivers:
collectors = append(collectors, tc.Collector("webhook"))
webhook := a.NewWebhook(t, collectors[i])

amClusters = append(amClusters, tc.AlertmanagerCluster(fmt.Sprintf(conf, webhook.Address()), clusterSizes[i]))
amClusters = append(amClusters, tc.AlertmanagerCluster(fmt.Sprintf(conf, resolveTimeout, webhook.Address()), clusterSizes[i]))

wg.Add(1)
}

for _, alertTime := range []float64{0, 2, 4, 6, 8} {
for _, alertTime := range []float64{1, 2, 4, 6, 8} {
for i, amc := range amClusters {
alert := a.Alert("alertname", fmt.Sprintf("test1-%v", alertTime))
amc.Push(a.At(alertTime), alert)
collectors[i].Want(a.Between(alertTime, alertTime+5), alert.Active(alertTime))
collectors[i].Want(a.Between(alertTime, alertTime+5), alert.Active(alertTime, alertTime+resolveTimeout.Seconds()))
}
}

Expand All @@ -124,4 +128,8 @@ receivers:
if err != nil {
t.Fatal(err)
}

for _, co := range collectors {
t.Log(co.Check())
}
}
28 changes: 16 additions & 12 deletions test/with_api_v2/acceptance/inhibit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestInhibiting(t *testing.T) {
// gets resolved.

conf := `
global:
resolve_timeout: %v
route:
receiver: "default"
group_by: []
Expand Down Expand Up @@ -58,7 +60,7 @@ inhibit_rules:
co := at.Collector("webhook")
wh := NewWebhook(t, co)

amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
amc := at.AlertmanagerCluster(fmt.Sprintf(conf, resolveTimeout, wh.Address()), 1)

amc.Push(At(1), Alert("alertname", "test1", "job", "testjob", "zone", "aa"))
amc.Push(At(1), Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa"))
Expand All @@ -73,21 +75,21 @@ inhibit_rules:
amc.Push(At(3.6), Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(2.2, 3.6))

co.Want(Between(2, 2.5),
Alert("alertname", "test1", "job", "testjob", "zone", "aa").Active(1),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa").Active(1),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab").Active(1),
Alert("alertname", "test1", "job", "testjob", "zone", "aa").Active(1, 1+resolveTimeout.Seconds()),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa").Active(1, 1+resolveTimeout.Seconds()),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab").Active(1, 1+resolveTimeout.Seconds()),
)

co.Want(Between(3, 3.5),
Alert("alertname", "test1", "job", "testjob", "zone", "aa").Active(1),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab").Active(1),
Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(2.2),
Alert("alertname", "test1", "job", "testjob", "zone", "aa").Active(1, 1+resolveTimeout.Seconds()),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab").Active(1, 1+resolveTimeout.Seconds()),
Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(2.2, 2.2+resolveTimeout.Seconds()),
)

co.Want(Between(4, 4.5),
Alert("alertname", "test1", "job", "testjob", "zone", "aa").Active(1),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa").Active(1),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab").Active(1),
Alert("alertname", "test1", "job", "testjob", "zone", "aa").Active(1, 1+resolveTimeout.Seconds()),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa").Active(1, 1+resolveTimeout.Seconds()),
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab").Active(1, 1+resolveTimeout.Seconds()),
Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(2.2, 3.6),
)

Expand All @@ -104,6 +106,8 @@ func TestAlwaysInhibiting(t *testing.T) {
// alerts.

conf := `
global:
resolve_timeout: %v
route:
receiver: "default"
group_by: []
Expand Down Expand Up @@ -133,7 +137,7 @@ inhibit_rules:
co := at.Collector("webhook")
wh := NewWebhook(t, co)

amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
amc := at.AlertmanagerCluster(fmt.Sprintf(conf, resolveTimeout, wh.Address()), 1)

amc.Push(At(1), Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa"))
amc.Push(At(1), Alert("alertname", "JobDown", "job", "testjob", "zone", "aa"))
Expand All @@ -142,7 +146,7 @@ inhibit_rules:
amc.Push(At(2.6), Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa").Active(1, 2.6))

co.Want(Between(2, 2.5),
Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(1),
Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(1, 1+resolveTimeout.Seconds()),
)

co.Want(Between(3, 3.5),
Expand Down
Loading

0 comments on commit 933c3af

Please sign in to comment.