mirror of
https://github.com/prometheus/alertmanager
synced 2025-02-26 15:50:46 +00:00
Add first inhibition acceptance test.
This commit is contained in:
parent
0c96c80cd6
commit
247cf8e3cd
@ -101,7 +101,7 @@ func NewInhibitRule(cr *config.InhibitRule) *InhibitRule {
|
||||
targetm = append(targetm, m)
|
||||
}
|
||||
|
||||
equal := make(map[model.LabelName]struct{})
|
||||
equal := map[model.LabelName]struct{}{}
|
||||
for _, ln := range cr.Equal {
|
||||
equal[ln] = struct{}{}
|
||||
}
|
||||
|
@ -172,3 +172,61 @@ notification_configs:
|
||||
|
||||
at.Run()
|
||||
}
|
||||
|
||||
func TestInhibiting(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
conf := `
|
||||
routes:
|
||||
- send_to: "default"
|
||||
group_wait: 1s
|
||||
group_interval: 1s
|
||||
|
||||
notification_configs:
|
||||
- name: "default"
|
||||
send_resolved: true
|
||||
repeat_interval: 1s
|
||||
webhook_configs:
|
||||
- url: 'http://%s'
|
||||
|
||||
inhibit_rules:
|
||||
- source_match:
|
||||
alertname: JobDown
|
||||
target_match:
|
||||
alertname: InstanceDown
|
||||
equal:
|
||||
- job
|
||||
- zone
|
||||
`
|
||||
|
||||
at := NewAcceptanceTest(t, &AcceptanceOpts{
|
||||
Tolerance: 150 * time.Millisecond,
|
||||
})
|
||||
|
||||
co := at.Collector("webhook")
|
||||
wh := NewWebhook(co)
|
||||
|
||||
am := at.Alertmanager(fmt.Sprintf(conf, wh.Address()))
|
||||
|
||||
am.Push(At(1), Alert("alertname", "test1", "job", "testjob", "zone", "aa"))
|
||||
am.Push(At(1), Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa"))
|
||||
am.Push(At(1), Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab"))
|
||||
|
||||
// This JobDown in zone aa should inhibit InstanceDown in zone aa in the
|
||||
// second batch of notifications.
|
||||
am.Push(At(2.2), Alert("alertname", "JobDown", "job", "testjob", "zone", "aa"))
|
||||
|
||||
co.Want(Between(2, 2.5),
|
||||
Alert("alertname", "test1", "job", "testjob", "zone", "aa"),
|
||||
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa"),
|
||||
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab"),
|
||||
)
|
||||
|
||||
co.Want(Between(3, 3.5),
|
||||
Alert("alertname", "test1", "job", "testjob", "zone", "aa"),
|
||||
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab"),
|
||||
Alert("alertname", "JobDown", "job", "testjob", "zone", "aa"),
|
||||
)
|
||||
|
||||
at.Run()
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ func batchesEqual(as, bs model.Alerts, opts *AcceptanceOpts) bool {
|
||||
|
||||
for i, a := range as {
|
||||
if !equalAlerts(a, bs[i], opts) {
|
||||
fmt.Println(a, bs[i])
|
||||
fmt.Printf("%s != %s\n", a.StartsAt, bs[i].StartsAt)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user