2015-10-11 15:24:49 +00:00
|
|
|
// Copyright 2015 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2015-10-05 14:08:00 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
. "github.com/prometheus/alertmanager/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInhibiting(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2018-04-18 14:26:04 +00:00
|
|
|
// This integration test checks that alerts can be inhibited and that an
|
|
|
|
// inhibited alert will be notified again as soon as the inhibiting alert
|
|
|
|
// gets resolved.
|
|
|
|
|
2015-10-05 14:08:00 +00:00
|
|
|
conf := `
|
2015-10-19 14:52:54 +00:00
|
|
|
route:
|
2015-11-10 13:08:20 +00:00
|
|
|
receiver: "default"
|
2015-10-19 15:35:59 +00:00
|
|
|
group_by: []
|
2015-10-08 08:50:37 +00:00
|
|
|
group_wait: 1s
|
|
|
|
group_interval: 1s
|
|
|
|
repeat_interval: 1s
|
2015-10-05 14:08:00 +00:00
|
|
|
|
2015-11-10 13:08:20 +00:00
|
|
|
receivers:
|
2015-10-05 14:08:00 +00:00
|
|
|
- name: "default"
|
|
|
|
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"))
|
|
|
|
|
2018-04-18 14:26:04 +00:00
|
|
|
// InstanceDown in zone aa should fire again in the third batch of
|
|
|
|
// notifications once JobDown in zone aa gets resolved.
|
|
|
|
am.Push(At(3.6), Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(2.2, 3.6))
|
|
|
|
|
2015-10-05 14:08:00 +00:00
|
|
|
co.Want(Between(2, 2.5),
|
2015-10-05 14:51:34 +00:00
|
|
|
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),
|
2015-10-05 14:08:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
co.Want(Between(3, 3.5),
|
2015-10-05 14:51:34 +00:00
|
|
|
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),
|
2015-10-05 14:08:00 +00:00
|
|
|
)
|
|
|
|
|
2018-04-18 14:26:04 +00:00
|
|
|
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", "JobDown", "job", "testjob", "zone", "aa").Active(2.2, 3.6),
|
|
|
|
)
|
|
|
|
|
|
|
|
at.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlwaysInhibiting(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
// This integration test checks that when inhibited and inhibiting alerts
|
|
|
|
// gets resolved at the same time, the final notification contains both
|
|
|
|
// alerts.
|
|
|
|
|
|
|
|
conf := `
|
|
|
|
route:
|
|
|
|
receiver: "default"
|
|
|
|
group_by: []
|
|
|
|
group_wait: 1s
|
|
|
|
group_interval: 1s
|
|
|
|
repeat_interval: 1s
|
|
|
|
|
|
|
|
receivers:
|
|
|
|
- name: "default"
|
|
|
|
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", "InstanceDown", "job", "testjob", "zone", "aa"))
|
|
|
|
am.Push(At(1), Alert("alertname", "JobDown", "job", "testjob", "zone", "aa"))
|
|
|
|
|
|
|
|
am.Push(At(2.6), Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(1, 2.6))
|
|
|
|
am.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),
|
|
|
|
)
|
|
|
|
|
|
|
|
co.Want(Between(3, 3.5),
|
|
|
|
Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa").Active(1, 2.6),
|
|
|
|
Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(1, 2.6),
|
|
|
|
)
|
|
|
|
|
2015-10-05 14:08:00 +00:00
|
|
|
at.Run()
|
|
|
|
}
|