Skip to content

Commit 8738156

Browse files
authored
Alerting: Add support for nested notification policies (#599)
* Define schema for depth 1 policy tree * Support for depth 1 policy tree * Support for matchers and implement tests * Workaround for linearization issue * Tests for sibling nested policies, remove commented out workaround * Support for 2-depth trees * Remove debug error * Complete remaining TODOs * Regenerate docs * Set supported tree depth to 4 * Fix bug exposed by increased depth
1 parent 1dd3efe commit 8738156

File tree

4 files changed

+484
-5
lines changed

4 files changed

+484
-5
lines changed

docs/resources/notification_policy.md

Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,24 @@ description: |-
1717
resource "grafana_contact_point" "a_contact_point" {
1818
name = "A Contact Point"
1919
20-
email {
20+
email {
2121
2222
message = "{{ len .Alerts.Firing }} firing."
2323
}
2424
}
2525
26+
resource "grafana_mute_timing" "a_mute_timing" {
27+
name = "Some Mute Timing"
28+
29+
intervals {
30+
weekdays = ["monday"]
31+
}
32+
33+
depends_on = [
34+
grafana_contact_point.a_contact_point
35+
]
36+
}
37+
2638
2739
resource "grafana_notification_policy" "my_notification_policy" {
2840
group_by = ["..."]
@@ -31,6 +43,42 @@ resource "grafana_notification_policy" "my_notification_policy" {
3143
group_wait = "45s"
3244
group_interval = "6m"
3345
repeat_interval = "3h"
46+
47+
policy {
48+
matcher {
49+
label = "mylabel"
50+
match = "="
51+
value = "myvalue"
52+
}
53+
contact_point = grafana_contact_point.a_contact_point.name
54+
group_by = ["alertname"]
55+
continue = true
56+
mute_timings = [grafana_mute_timing.a_mute_timing.name]
57+
58+
group_wait = "45s"
59+
group_interval = "6m"
60+
repeat_interval = "3h"
61+
62+
policy {
63+
matcher {
64+
label = "sublabel"
65+
match = "="
66+
value = "subvalue"
67+
}
68+
contact_point = grafana_contact_point.a_contact_point.name
69+
group_by = ["..."]
70+
}
71+
}
72+
73+
policy {
74+
matcher {
75+
label = "anotherlabel"
76+
match = "=~"
77+
value = "another value.*"
78+
}
79+
contact_point = grafana_contact_point.a_contact_point.name
80+
group_by = ["..."]
81+
}
3482
}
3583
```
3684

@@ -46,12 +94,123 @@ resource "grafana_notification_policy" "my_notification_policy" {
4694

4795
- `group_interval` (String) Minimum time interval between two notifications for the same group. Default is 5 minutes.
4896
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.
97+
- `policy` (Block List) Routing rules for specific label sets. (see [below for nested schema](#nestedblock--policy))
4998
- `repeat_interval` (String) Minimum time interval for re-sending a notification if an alert is still firing. Default is 4 hours.
5099

51100
### Read-Only
52101

53102
- `id` (String) The ID of this resource.
54103

104+
<a id="nestedblock--policy"></a>
105+
### Nested Schema for `policy`
106+
107+
Required:
108+
109+
- `contact_point` (String) The contact point to route notifications that match this rule to.
110+
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.
111+
112+
Optional:
113+
114+
- `continue` (Boolean) Whether to continue matching subsequent rules if an alert matches the current rule. Otherwise, the rule will be 'consumed' by the first policy to match it.
115+
- `group_interval` (String) Minimum time interval between two notifications for the same group. Default is 5 minutes.
116+
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.
117+
- `matcher` (Block List) Describes which labels this rule should match. When multiple matchers are supplied, an alert must match ALL matchers to be accepted by this policy. When no matchers are supplied, the rule will match all alert instances. (see [below for nested schema](#nestedblock--policy--matcher))
118+
- `mute_timings` (List of String) A list of mute timing names to apply to alerts that match this policy.
119+
- `policy` (Block List) Routing rules for specific label sets. (see [below for nested schema](#nestedblock--policy--policy))
120+
- `repeat_interval` (String) Minimum time interval for re-sending a notification if an alert is still firing. Default is 4 hours.
121+
122+
<a id="nestedblock--policy--matcher"></a>
123+
### Nested Schema for `policy.matcher`
124+
125+
Required:
126+
127+
- `label` (String) The name of the label to match against.
128+
- `match` (String) The operator to apply when matching values of the given label. Allowed operators are `=` for equality, `!=` for negated equality, `=~` for regex equality, and `!~` for negated regex equality.
129+
- `value` (String) The label value to match against.
130+
131+
132+
<a id="nestedblock--policy--policy"></a>
133+
### Nested Schema for `policy.policy`
134+
135+
Required:
136+
137+
- `contact_point` (String) The contact point to route notifications that match this rule to.
138+
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.
139+
140+
Optional:
141+
142+
- `continue` (Boolean) Whether to continue matching subsequent rules if an alert matches the current rule. Otherwise, the rule will be 'consumed' by the first policy to match it.
143+
- `group_interval` (String) Minimum time interval between two notifications for the same group. Default is 5 minutes.
144+
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.
145+
- `matcher` (Block List) Describes which labels this rule should match. When multiple matchers are supplied, an alert must match ALL matchers to be accepted by this policy. When no matchers are supplied, the rule will match all alert instances. (see [below for nested schema](#nestedblock--policy--policy--matcher))
146+
- `mute_timings` (List of String) A list of mute timing names to apply to alerts that match this policy.
147+
- `policy` (Block List) Routing rules for specific label sets. (see [below for nested schema](#nestedblock--policy--policy--policy))
148+
- `repeat_interval` (String) Minimum time interval for re-sending a notification if an alert is still firing. Default is 4 hours.
149+
150+
<a id="nestedblock--policy--policy--matcher"></a>
151+
### Nested Schema for `policy.policy.matcher`
152+
153+
Required:
154+
155+
- `label` (String) The name of the label to match against.
156+
- `match` (String) The operator to apply when matching values of the given label. Allowed operators are `=` for equality, `!=` for negated equality, `=~` for regex equality, and `!~` for negated regex equality.
157+
- `value` (String) The label value to match against.
158+
159+
160+
<a id="nestedblock--policy--policy--policy"></a>
161+
### Nested Schema for `policy.policy.policy`
162+
163+
Required:
164+
165+
- `contact_point` (String) The contact point to route notifications that match this rule to.
166+
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.
167+
168+
Optional:
169+
170+
- `continue` (Boolean) Whether to continue matching subsequent rules if an alert matches the current rule. Otherwise, the rule will be 'consumed' by the first policy to match it.
171+
- `group_interval` (String) Minimum time interval between two notifications for the same group. Default is 5 minutes.
172+
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.
173+
- `matcher` (Block List) Describes which labels this rule should match. When multiple matchers are supplied, an alert must match ALL matchers to be accepted by this policy. When no matchers are supplied, the rule will match all alert instances. (see [below for nested schema](#nestedblock--policy--policy--policy--matcher))
174+
- `mute_timings` (List of String) A list of mute timing names to apply to alerts that match this policy.
175+
- `policy` (Block List) Routing rules for specific label sets. (see [below for nested schema](#nestedblock--policy--policy--policy--policy))
176+
- `repeat_interval` (String) Minimum time interval for re-sending a notification if an alert is still firing. Default is 4 hours.
177+
178+
<a id="nestedblock--policy--policy--policy--matcher"></a>
179+
### Nested Schema for `policy.policy.policy.matcher`
180+
181+
Required:
182+
183+
- `label` (String) The name of the label to match against.
184+
- `match` (String) The operator to apply when matching values of the given label. Allowed operators are `=` for equality, `!=` for negated equality, `=~` for regex equality, and `!~` for negated regex equality.
185+
- `value` (String) The label value to match against.
186+
187+
188+
<a id="nestedblock--policy--policy--policy--policy"></a>
189+
### Nested Schema for `policy.policy.policy.policy`
190+
191+
Required:
192+
193+
- `contact_point` (String) The contact point to route notifications that match this rule to.
194+
- `group_by` (List of String) A list of alert labels to group alerts into notifications by. Use the special label `...` to group alerts by all labels, effectively disabling grouping.
195+
196+
Optional:
197+
198+
- `continue` (Boolean) Whether to continue matching subsequent rules if an alert matches the current rule. Otherwise, the rule will be 'consumed' by the first policy to match it.
199+
- `group_interval` (String) Minimum time interval between two notifications for the same group. Default is 5 minutes.
200+
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification. Default is 30 seconds.
201+
- `matcher` (Block List) Describes which labels this rule should match. When multiple matchers are supplied, an alert must match ALL matchers to be accepted by this policy. When no matchers are supplied, the rule will match all alert instances. (see [below for nested schema](#nestedblock--policy--policy--policy--policy--matcher))
202+
- `mute_timings` (List of String) A list of mute timing names to apply to alerts that match this policy.
203+
- `repeat_interval` (String) Minimum time interval for re-sending a notification if an alert is still firing. Default is 4 hours.
204+
205+
<a id="nestedblock--policy--policy--policy--policy--matcher"></a>
206+
### Nested Schema for `policy.policy.policy.policy.matcher`
207+
208+
Required:
209+
210+
- `label` (String) The name of the label to match against.
211+
- `match` (String) The operator to apply when matching values of the given label. Allowed operators are `=` for equality, `!=` for negated equality, `=~` for regex equality, and `!~` for negated regex equality.
212+
- `value` (String) The label value to match against.
213+
55214
## Import
56215

57216
Import is supported using the following syntax:
Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
resource "grafana_contact_point" "a_contact_point" {
22
name = "A Contact Point"
33

4-
email {
4+
email {
55
66
message = "{{ len .Alerts.Firing }} firing."
77
}
88
}
99

10+
resource "grafana_mute_timing" "a_mute_timing" {
11+
name = "Some Mute Timing"
12+
13+
intervals {
14+
weekdays = ["monday"]
15+
}
16+
17+
depends_on = [
18+
grafana_contact_point.a_contact_point
19+
]
20+
}
21+
1022

1123
resource "grafana_notification_policy" "my_notification_policy" {
1224
group_by = ["..."]
@@ -15,4 +27,40 @@ resource "grafana_notification_policy" "my_notification_policy" {
1527
group_wait = "45s"
1628
group_interval = "6m"
1729
repeat_interval = "3h"
30+
31+
policy {
32+
matcher {
33+
label = "mylabel"
34+
match = "="
35+
value = "myvalue"
36+
}
37+
contact_point = grafana_contact_point.a_contact_point.name
38+
group_by = ["alertname"]
39+
continue = true
40+
mute_timings = [grafana_mute_timing.a_mute_timing.name]
41+
42+
group_wait = "45s"
43+
group_interval = "6m"
44+
repeat_interval = "3h"
45+
46+
policy {
47+
matcher {
48+
label = "sublabel"
49+
match = "="
50+
value = "subvalue"
51+
}
52+
contact_point = grafana_contact_point.a_contact_point.name
53+
group_by = ["..."]
54+
}
55+
}
56+
57+
policy {
58+
matcher {
59+
label = "anotherlabel"
60+
match = "=~"
61+
value = "another value.*"
62+
}
63+
contact_point = grafana_contact_point.a_contact_point.name
64+
group_by = ["..."]
65+
}
1866
}

0 commit comments

Comments
 (0)