1
2
3
4
5
6
7
8
9
10
11
12
13
14 package test
15
16 import (
17 "fmt"
18 "testing"
19 "time"
20
21 . "github.com/prometheus/alertmanager/test/with_api_v2"
22 )
23
24 func TestSilencing(t *testing.T) {
25 t.Parallel()
26
27 conf := `
28 route:
29 receiver: "default"
30 group_by: []
31 group_wait: 1s
32 group_interval: 1s
33 repeat_interval: 1ms
34
35 receivers:
36 - name: "default"
37 webhook_configs:
38 - url: 'http://%s'
39 `
40
41 at := NewAcceptanceTest(t, &AcceptanceOpts{
42 Tolerance: 150 * time.Millisecond,
43 })
44
45 co := at.Collector("webhook")
46 wh := NewWebhook(t, co)
47
48 amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
49
50
51
52 amc.Push(At(1), Alert("alertname", "test1").Active(1))
53 amc.Push(At(1), Alert("alertname", "test2").Active(1))
54
55 co.Want(Between(2, 2.5),
56 Alert("alertname", "test1").Active(1),
57 Alert("alertname", "test2").Active(1),
58 )
59
60
61 amc.SetSilence(At(2.3), Silence(2.5, 4.5).Match("alertname", "test1"))
62
63 co.Want(Between(3, 3.5), Alert("alertname", "test2").Active(1))
64 co.Want(Between(4, 4.5), Alert("alertname", "test2").Active(1))
65
66
67
68 co.Want(Between(5, 5.5),
69 Alert("alertname", "test1").Active(1),
70 Alert("alertname", "test2").Active(1),
71 )
72
73 at.Run()
74
75 t.Log(co.Check())
76 }
77
78 func TestSilenceDelete(t *testing.T) {
79 t.Parallel()
80
81 conf := `
82 route:
83 receiver: "default"
84 group_by: []
85 group_wait: 1s
86 group_interval: 1s
87 repeat_interval: 1ms
88
89 receivers:
90 - name: "default"
91 webhook_configs:
92 - url: 'http://%s'
93 `
94
95 at := NewAcceptanceTest(t, &AcceptanceOpts{
96 Tolerance: 150 * time.Millisecond,
97 })
98
99 co := at.Collector("webhook")
100 wh := NewWebhook(t, co)
101
102 amc := at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
103
104
105
106 amc.Push(At(1), Alert("alertname", "test1").Active(1))
107 amc.Push(At(1), Alert("alertname", "test2").Active(1))
108
109
110
111 sil := Silence(1.5, 100).MatchRE("alertname", ".+")
112
113 amc.SetSilence(At(1.3), sil)
114 amc.DelSilence(At(3.5), sil)
115
116 co.Want(Between(3.5, 4.5),
117 Alert("alertname", "test1").Active(1),
118 Alert("alertname", "test2").Active(1),
119 )
120
121 at.Run()
122
123 t.Log(co.Check())
124 }
125
View as plain text