Skip to content

Commit c8bb737

Browse files
authored
feat: Add k8s alertrule and recordingrule resources (#2404)
* Add k8s alertrule and recordingrule resources * Tidy up go.mod * Enable panel_ref support for alert rules * Update docs * Add missing example tests * Gen docs with examples + use friendlier ds uids * Fix panel ref type * Update golangci-lint to support go 1.25 * Fix linting problems * Fix docs gen * Update golangci config to match previous behavior * Fix lints * Temporarily skip rules example tests * Remove debug logging used in development
1 parent 61d37df commit c8bb737

File tree

16 files changed

+2290
-118
lines changed

16 files changed

+2290
-118
lines changed

.golangci.toml

Lines changed: 70 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,75 @@
1-
[run]
2-
timeout = "10m"
1+
version = '2'
32

4-
[linters-settings.goconst]
3+
[linters]
4+
default = 'none'
5+
enable = [
6+
'copyloopvar',
7+
'dogsled',
8+
'goconst',
9+
'gocritic',
10+
'gocyclo',
11+
'goprintffuncname',
12+
'gosec',
13+
'govet',
14+
'ineffassign',
15+
'misspell',
16+
'nakedret',
17+
'rowserrcheck',
18+
'staticcheck',
19+
'unconvert',
20+
'unused',
21+
'whitespace'
22+
]
23+
24+
[linters.settings]
25+
[linters.settings.goconst]
526
min-len = 5
627
min-occurrences = 5
28+
[linters.settings.staticcheck]
29+
checks = ['all', '-QF1001', '-QF1003', '-QF1008']
730

8-
[linters]
9-
disable-all = true
31+
[linters.exclusions]
32+
generated = 'lax'
33+
presets = [
34+
'comments',
35+
'common-false-positives',
36+
'legacy',
37+
'std-error-handling'
38+
]
39+
paths = [
40+
'third_party$',
41+
'builtin$',
42+
'examples$'
43+
]
44+
45+
[[linters.exclusions.rules]]
46+
linters = [
47+
'staticcheck'
48+
]
49+
path = '_test.go'
50+
text = 'ST1003: should not use underscores in Go names;'
51+
52+
[[linters.exclusions.rules]]
53+
linters = [
54+
'gocritic'
55+
]
56+
text = 'deprecatedComment: the proper format is `Deprecated: <text>`'
57+
58+
[[linters.exclusions.rules]]
59+
linters = [
60+
'gosec'
61+
]
62+
text = 'G402: TLS MinVersion too low.'
63+
64+
[formatters]
1065
enable = [
11-
"dogsled",
12-
"copyloopvar",
13-
"goconst",
14-
"gocritic",
15-
"gocyclo",
16-
"goimports",
17-
"goprintffuncname",
18-
"gosec",
19-
"gosimple",
20-
"govet",
21-
"ineffassign",
22-
"misspell",
23-
"nakedret",
24-
"rowserrcheck",
25-
"staticcheck",
26-
"stylecheck",
27-
"typecheck",
28-
"unconvert",
29-
"unused",
30-
"whitespace"
31-
]
32-
33-
[[issues.exclude-rules]]
34-
linters = ["stylecheck"]
35-
path = "_test.go"
36-
text = "ST1003: should not use underscores in Go names;"
37-
38-
[[issues.exclude-rules]]
39-
linters = ["gocritic"]
40-
text = "deprecatedComment: the proper format is `Deprecated: <text>`"
41-
42-
[[issues.exclude-rules]]
43-
linters = ["gosec"]
44-
text = "G402: TLS MinVersion too low."
66+
'goimports'
67+
]
68+
69+
[formatters.exclusions]
70+
generated = 'lax'
71+
paths = [
72+
'third_party$',
73+
'builtin$',
74+
'examples$'
75+
]

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ golangci-lint:
6767
--rm \
6868
--volume "$(shell pwd):/src" \
6969
--workdir "/src" \
70-
golangci/golangci-lint:v1.64.7 golangci-lint run ./... -v
70+
golangci/golangci-lint:v2.5.0 golangci-lint run ./... -v
7171

7272
docs:
7373
go generate ./...
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_apps_rules_alertrule_v0alpha1 Resource - terraform-provider-grafana"
4+
subcategory: "Alerting"
5+
description: |-
6+
Manages Grafana Alert Rules.
7+
---
8+
9+
# grafana_apps_rules_alertrule_v0alpha1 (Resource)
10+
11+
Manages Grafana Alert Rules.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "grafana_folder" "alertrule_folder" {
17+
title = "Alert Rule Folder"
18+
}
19+
20+
resource "grafana_apps_rules_alertrule_v0alpha1" "example" {
21+
metadata {
22+
uid = "example-alert-rule"
23+
folder_uid = grafana_folder.alertrule_folder.uid
24+
}
25+
spec {
26+
title = "Example Alert Rule"
27+
trigger {
28+
interval = "1m"
29+
}
30+
paused = true
31+
expressions = {
32+
"A" = {
33+
model = {
34+
datasource = {
35+
type = "prometheus"
36+
uid = "ds_uid"
37+
}
38+
editorMode = "code"
39+
expr = "count(up{})"
40+
instant = true
41+
intervalMs = 1000
42+
legendFormat = "__auto"
43+
maxDataPoints = 43200
44+
range = false
45+
refId = "A"
46+
}
47+
datasource_uid = "ds_uid"
48+
relative_time_range = {
49+
from = "600s"
50+
to = "0s"
51+
}
52+
query_type = ""
53+
source = true
54+
}
55+
"B" = {
56+
model = {
57+
conditions = [
58+
{
59+
evaluator = {
60+
params = [1]
61+
type = "gt"
62+
}
63+
operator = {
64+
type = "and"
65+
}
66+
query = {
67+
params = ["C"]
68+
}
69+
reducer = {
70+
params = []
71+
type = "last"
72+
}
73+
type = "query"
74+
}
75+
]
76+
datasource = {
77+
type = "__expr__"
78+
uid = "__expr__"
79+
}
80+
expression = "A"
81+
intervalMs = 1000
82+
maxDataPoints = 43200
83+
refId = "C"
84+
type = "threshold"
85+
}
86+
datasource_uid = "__expr__"
87+
query_type = ""
88+
source = false
89+
}
90+
}
91+
for = "5m"
92+
labels = {
93+
severity = "critical"
94+
}
95+
annotations = {
96+
runbook_url = "https://example.com"
97+
}
98+
no_data_state = "KeepLast"
99+
exec_err_state = "KeepLast"
100+
missing_series_evals_to_resolve = 5
101+
notification_settings {
102+
contact_point = "grafana-default-email"
103+
}
104+
}
105+
}
106+
```
107+
108+
<!-- schema generated by tfplugindocs -->
109+
## Schema
110+
111+
### Optional
112+
113+
- `metadata` (Block, Optional) The metadata of the resource. (see [below for nested schema](#nestedblock--metadata))
114+
- `options` (Block, Optional) Options for applying the resource. (see [below for nested schema](#nestedblock--options))
115+
- `spec` (Block, Optional) The spec of the resource. (see [below for nested schema](#nestedblock--spec))
116+
117+
### Read-Only
118+
119+
- `id` (String) The ID of the resource derived from UUID.
120+
121+
<a id="nestedblock--metadata"></a>
122+
### Nested Schema for `metadata`
123+
124+
Required:
125+
126+
- `uid` (String) The unique identifier of the resource.
127+
128+
Optional:
129+
130+
- `folder_uid` (String) The UID of the folder to save the resource in.
131+
132+
Read-Only:
133+
134+
- `annotations` (Map of String) Annotations of the resource.
135+
- `url` (String) The full URL of the resource.
136+
- `uuid` (String) The globally unique identifier of a resource, used by the API for tracking.
137+
- `version` (String) The version of the resource.
138+
139+
140+
<a id="nestedblock--options"></a>
141+
### Nested Schema for `options`
142+
143+
Optional:
144+
145+
- `overwrite` (Boolean) Set to true if you want to overwrite existing resource with newer version, same resource title in folder or same resource uid.
146+
147+
148+
<a id="nestedblock--spec"></a>
149+
### Nested Schema for `spec`
150+
151+
Required:
152+
153+
- `exec_err_state` (String) Describes what state to enter when the rule's query is invalid and the rule cannot be executed. Options are OK, Error, KeepLast, and Alerting.
154+
- `expressions` (Dynamic) A sequence of stages that describe the contents of the rule.
155+
- `no_data_state` (String) Describes what state to enter when the rule's query returns No Data. Options are OK, NoData, KeepLast, and Alerting.
156+
- `title` (String) The title of the alert rule.
157+
158+
Optional:
159+
160+
- `annotations` (Map of String) Key-value pairs of metadata to attach to the alert rule. They add additional information, such as a `summary` or `runbook_url`, to help identify and investigate alerts.
161+
- `for` (String) The amount of time for which the rule must be breached for the rule to be considered to be Firing. Before this time has elapsed, the rule is only considered to be Pending.
162+
- `keep_firing_for` (String) The amount of time for which the rule will considered to be Recovering after initially Firing. Before this time has elapsed, the rule will continue to fire once it's been triggered.
163+
- `labels` (Map of String) Key-value pairs to attach to the alert rule that can be used in matching, grouping, and routing.
164+
- `missing_series_evals_to_resolve` (Number) The number of missing series evaluations that must occur before the rule is considered to be resolved.
165+
- `notification_settings` (Block, Optional) Notification settings for the rule. If specified, it overrides the notification policies. (see [below for nested schema](#nestedblock--spec--notification_settings))
166+
- `panel_ref` (Dynamic) Reference to a panel that this alert rule is associated with. Should be an object with 'dashboard_uid' (string) and 'panel_id' (number) fields.
167+
- `paused` (Boolean) Sets whether the rule should be paused or not.
168+
- `trigger` (Block, Optional) The trigger configuration for the alert rule. (see [below for nested schema](#nestedblock--spec--trigger))
169+
170+
<a id="nestedblock--spec--notification_settings"></a>
171+
### Nested Schema for `spec.notification_settings`
172+
173+
Required:
174+
175+
- `contact_point` (String) The contact point to route notifications that match this rule to.
176+
177+
Optional:
178+
179+
- `active_timings` (List of String) A list of time interval names to apply to alerts that match this policy to suppress them unless they are sent at the specified time.
180+
- `group_by` (List of String) A list of alert labels to group alerts into notifications by.
181+
- `group_interval` (String) Minimum time interval between two notifications for the same group.
182+
- `group_wait` (String) Time to wait to buffer alerts of the same group before sending a notification.
183+
- `mute_timings` (List of String) A list of mute timing names to apply to alerts that match this policy.
184+
- `repeat_interval` (String) Minimum time interval for re-sending a notification if an alert is still firing.
185+
186+
187+
<a id="nestedblock--spec--trigger"></a>
188+
### Nested Schema for `spec.trigger`
189+
190+
Required:
191+
192+
- `interval` (String) The interval at which the alert rule should be evaluated.

0 commit comments

Comments
 (0)