Skip to content

Commit 9b73f04

Browse files
4565: Add Asserts provider support for alert configurations (#2287)
* 4565: Updating test 4565: Updating stack id docs 4565: fixing test 4565: running test and fixing comment 4565: owner update 4565: fixing path Fix concurrency race condition in generate tool Fix 'panic: send on closed channel' error in generateImportBlocks. The issue was a classic Go concurrency race condition: - Goroutines called wg.Done() before sending to results channel - Main goroutine could close(results) while sends were still pending - This caused 'send on closed channel' panics Fix: Move all 'results <- result{}' sends BEFORE wg.Done() calls to ensure all channel operations complete before waitgroup finishes. This prevents the channel from being closed while goroutines are still trying to send results. Fixes integration test failures in CI. Add dedicated environment check for Asserts service tests Create CheckAssertsTestsEnabled() function to properly gate Asserts tests. Tests now require TF_ACC_ASSERTS=true to run, preventing 404 errors when Asserts service is not available in test environments. This follows the same pattern as other optional cloud services and ensures tests only run when the service is actually configured. Fix linter error: remove unused getTestStackIDForDisabled function Removed duplicate getTestStackIDForDisabled function and unnecessary imports. Both test files now share the getTestStackID function from the same package. Fixes: - unused function (golangci-lint) - unnecessary imports (os, strconv, require) All tests still pass and linter is clean. 4565: adding test 4565: adding test 4565: adding to catalog Update asserts resources and configuration 4565: fixing client 4565: update to add stack_id 4565: small revert 4565: Setup for asserts TF * 4565: clean up * 4565: stack id is set at the provider level * 4565: updating docs * 4565: updating naming * 4565: updating docs * 4565: updating docs * 4565: updating docs * 4565: updating docs * 4565: updating docs * 4565: updating docs * 4565: adding retry * 4565: fixing retry * 4565: adding test for retry * 4565: adding test for retry * 4565: adding test for retry --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 00c26e7 commit 9b73f04

File tree

25 files changed

+1591
-10
lines changed

25 files changed

+1591
-10
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/internal/resources/cloud/* @grafana/platform-monitoring @grafana/grafana-com-maintainers
55
/internal/resources/cloud/*_access_policy_* @grafana/platform-monitoring @grafana/identity-squad
66
/internal/resources/grafana/*_organization_user* @grafana/platform-monitoring @grafana/identity-squad
7+
/internal/resources/asserts/* @grafana/platform-monitoring @grafana/asserts
78
/internal/resources/cloudprovider/* @grafana/platform-monitoring @grafana/middleware-apps
89
/internal/resources/connections/* @grafana/platform-monitoring @grafana/middleware-apps
910
/internal/resources/fleetmanagement/* @grafana/platform-monitoring @grafana/fleet-management-backend

catalog-info.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ metadata:
2323
spec:
2424
targets:
2525
- ./internal/resources/appplatform/catalog-resource.yaml
26+
- ./internal/resources/asserts/catalog-resource.yaml
2627
- ./internal/resources/cloud/catalog-resource.yaml
2728
- ./internal/resources/cloudprovider/catalog-resource.yaml
2829
- ./internal/resources/connections/catalog-resource.yaml
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_asserts_notification_alerts_config Resource - terraform-provider-grafana"
4+
subcategory: "Asserts"
5+
description: |-
6+
Manages Asserts Alert Configurations through Grafana API.
7+
---
8+
9+
# grafana_asserts_notification_alerts_config (Resource)
10+
11+
Manages Asserts Alert Configurations through Grafana API.
12+
13+
## Example Usage
14+
15+
```terraform
16+
# Basic alert configuration with silencing
17+
resource "grafana_asserts_notification_alerts_config" "prometheus_remote_storage_failures" {
18+
name = "PrometheusRemoteStorageFailures"
19+
20+
match_labels = {
21+
alertname = "PrometheusRemoteStorageFailures"
22+
alertgroup = "prometheus.alerts"
23+
asserts_env = "prod"
24+
}
25+
26+
silenced = true
27+
}
28+
29+
# High severity alert with specific job and context matching
30+
resource "grafana_asserts_notification_alerts_config" "error_buildup_notify" {
31+
name = "ErrorBuildupNotify"
32+
33+
match_labels = {
34+
alertname = "ErrorBuildup"
35+
job = "acai"
36+
asserts_request_type = "inbound"
37+
asserts_request_context = "/auth"
38+
}
39+
40+
silenced = false
41+
}
42+
43+
# Alert with additional labels and custom duration
44+
resource "grafana_asserts_notification_alerts_config" "payment_test_alert" {
45+
name = "PaymentTestAlert"
46+
47+
match_labels = {
48+
alertname = "PaymentTestAlert"
49+
additional_labels = "asserts_severity=~\"critical\""
50+
alertgroup = "alex-k8s-integration-test.alerts"
51+
}
52+
53+
alert_labels = {
54+
testing = "onetwothree"
55+
}
56+
57+
duration = "5m"
58+
silenced = false
59+
}
60+
61+
# Latency alert for shipping service
62+
resource "grafana_asserts_notification_alerts_config" "high_shipping_latency" {
63+
name = "high shipping latency"
64+
65+
match_labels = {
66+
alertname = "LatencyP99ErrorBuildup"
67+
job = "shipping"
68+
asserts_request_type = "inbound"
69+
}
70+
71+
silenced = false
72+
}
73+
74+
# CPU throttling alert with warning severity
75+
resource "grafana_asserts_notification_alerts_config" "cpu_throttling_sustained" {
76+
name = "CPUThrottlingSustained"
77+
78+
match_labels = {
79+
alertname = "CPUThrottlingSustained"
80+
additional_labels = "asserts_severity=~\"warning\""
81+
}
82+
83+
silenced = true
84+
}
85+
86+
# Ingress error rate alert
87+
resource "grafana_asserts_notification_alerts_config" "ingress_error" {
88+
name = "ingress error"
89+
90+
match_labels = {
91+
alertname = "ErrorRatioBreach"
92+
job = "ingress-nginx-controller-metrics"
93+
asserts_request_type = "inbound"
94+
}
95+
96+
silenced = false
97+
}
98+
99+
# MySQL Galera cluster alert
100+
resource "grafana_asserts_notification_alerts_config" "mysql_galera_not_ready" {
101+
name = "MySQLGaleraNotReady"
102+
103+
match_labels = {
104+
alertname = "MySQLGaleraNotReady"
105+
}
106+
107+
silenced = false
108+
}
109+
```
110+
111+
<!-- schema generated by tfplugindocs -->
112+
## Schema
113+
114+
### Required
115+
116+
- `name` (String) The name of the alert configuration.
117+
118+
### Optional
119+
120+
- `alert_labels` (Map of String) Labels to add to alerts generated by this configuration.
121+
- `duration` (String) Duration for which the condition must be true before firing (e.g., '5m', '30s'). Maps to 'for' in Asserts API.
122+
- `match_labels` (Map of String) Labels to match for this alert configuration.
123+
- `silenced` (Boolean) Whether this alert configuration is silenced. Defaults to `false`.
124+
125+
### Read-Only
126+
127+
- `id` (String) The ID of this resource.
128+
129+
## Import
130+
131+
Import is supported using the following syntax:
132+
133+
```shell
134+
terraform import grafana_asserts_notification_alerts_config.name "{{ name }}"
135+
```
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_asserts_suppressed_assertions_config Resource - terraform-provider-grafana"
4+
subcategory: "Asserts"
5+
description: |-
6+
Manages Asserts Disabled Alert Configurations through Grafana API.
7+
---
8+
9+
# grafana_asserts_suppressed_assertions_config (Resource)
10+
11+
Manages Asserts Disabled Alert Configurations through Grafana API.
12+
13+
## Example Usage
14+
15+
```terraform
16+
# Basic suppressed alert configuration for maintenance
17+
resource "grafana_asserts_suppressed_assertions_config" "maintenance_window" {
18+
name = "MaintenanceWindow"
19+
20+
match_labels = {
21+
service = "api-service"
22+
maintenance = "true"
23+
}
24+
}
25+
26+
# Suppress specific alertname during deployment
27+
resource "grafana_asserts_suppressed_assertions_config" "deployment_suppression" {
28+
name = "DeploymentSuppression"
29+
30+
match_labels = {
31+
alertname = "HighLatency"
32+
job = "web-service"
33+
env = "staging"
34+
}
35+
}
36+
37+
# Suppress alerts for specific test environment
38+
resource "grafana_asserts_suppressed_assertions_config" "test_environment_suppression" {
39+
name = "TestEnvironmentSuppression"
40+
41+
match_labels = {
42+
alertgroup = "test.alerts"
43+
environment = "test"
44+
}
45+
}
46+
```
47+
48+
<!-- schema generated by tfplugindocs -->
49+
## Schema
50+
51+
### Required
52+
53+
- `name` (String) The name of the disabled alert configuration.
54+
55+
### Optional
56+
57+
- `match_labels` (Map of String) Labels to match for this disabled alert configuration.
58+
59+
### Read-Only
60+
61+
- `id` (String) The ID of this resource.
62+
63+
## Import
64+
65+
Import is supported using the following syntax:
66+
67+
```shell
68+
terraform import grafana_asserts_suppressed_assertions_config.name "{{ name }}"
69+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import grafana_asserts_notification_alerts_config.name "{{ name }}"
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Basic alert configuration with silencing
2+
resource "grafana_asserts_notification_alerts_config" "prometheus_remote_storage_failures" {
3+
name = "PrometheusRemoteStorageFailures"
4+
5+
match_labels = {
6+
alertname = "PrometheusRemoteStorageFailures"
7+
alertgroup = "prometheus.alerts"
8+
asserts_env = "prod"
9+
}
10+
11+
silenced = true
12+
}
13+
14+
# High severity alert with specific job and context matching
15+
resource "grafana_asserts_notification_alerts_config" "error_buildup_notify" {
16+
name = "ErrorBuildupNotify"
17+
18+
match_labels = {
19+
alertname = "ErrorBuildup"
20+
job = "acai"
21+
asserts_request_type = "inbound"
22+
asserts_request_context = "/auth"
23+
}
24+
25+
silenced = false
26+
}
27+
28+
# Alert with additional labels and custom duration
29+
resource "grafana_asserts_notification_alerts_config" "payment_test_alert" {
30+
name = "PaymentTestAlert"
31+
32+
match_labels = {
33+
alertname = "PaymentTestAlert"
34+
additional_labels = "asserts_severity=~\"critical\""
35+
alertgroup = "alex-k8s-integration-test.alerts"
36+
}
37+
38+
alert_labels = {
39+
testing = "onetwothree"
40+
}
41+
42+
duration = "5m"
43+
silenced = false
44+
}
45+
46+
# Latency alert for shipping service
47+
resource "grafana_asserts_notification_alerts_config" "high_shipping_latency" {
48+
name = "high shipping latency"
49+
50+
match_labels = {
51+
alertname = "LatencyP99ErrorBuildup"
52+
job = "shipping"
53+
asserts_request_type = "inbound"
54+
}
55+
56+
silenced = false
57+
}
58+
59+
# CPU throttling alert with warning severity
60+
resource "grafana_asserts_notification_alerts_config" "cpu_throttling_sustained" {
61+
name = "CPUThrottlingSustained"
62+
63+
match_labels = {
64+
alertname = "CPUThrottlingSustained"
65+
additional_labels = "asserts_severity=~\"warning\""
66+
}
67+
68+
silenced = true
69+
}
70+
71+
# Ingress error rate alert
72+
resource "grafana_asserts_notification_alerts_config" "ingress_error" {
73+
name = "ingress error"
74+
75+
match_labels = {
76+
alertname = "ErrorRatioBreach"
77+
job = "ingress-nginx-controller-metrics"
78+
asserts_request_type = "inbound"
79+
}
80+
81+
silenced = false
82+
}
83+
84+
# MySQL Galera cluster alert
85+
resource "grafana_asserts_notification_alerts_config" "mysql_galera_not_ready" {
86+
name = "MySQLGaleraNotReady"
87+
88+
match_labels = {
89+
alertname = "MySQLGaleraNotReady"
90+
}
91+
92+
silenced = false
93+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import grafana_asserts_suppressed_assertions_config.name "{{ name }}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Basic suppressed alert configuration for maintenance
2+
resource "grafana_asserts_suppressed_assertions_config" "maintenance_window" {
3+
name = "MaintenanceWindow"
4+
5+
match_labels = {
6+
service = "api-service"
7+
maintenance = "true"
8+
}
9+
}
10+
11+
# Suppress specific alertname during deployment
12+
resource "grafana_asserts_suppressed_assertions_config" "deployment_suppression" {
13+
name = "DeploymentSuppression"
14+
15+
match_labels = {
16+
alertname = "HighLatency"
17+
job = "web-service"
18+
env = "staging"
19+
}
20+
}
21+
22+
# Suppress alerts for specific test environment
23+
resource "grafana_asserts_suppressed_assertions_config" "test_environment_suppression" {
24+
name = "TestEnvironmentSuppression"
25+
26+
match_labels = {
27+
alertgroup = "test.alerts"
28+
environment = "test"
29+
}
30+
}

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/grafana/fleet-management-api v1.0.0
1414
github.com/grafana/grafana-app-sdk v0.35.2-0.20250408075831-c2a87bde0849
1515
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20250526074454-7ec66e02e4bb
16-
github.com/grafana/grafana-openapi-client-go v0.0.0-20250516123951-83fcd32d7bbe
16+
github.com/grafana/grafana-openapi-client-go v0.0.0-20250617151817-c0f8cbb88d5c
1717
github.com/grafana/grafana/apps/dashboard v0.0.0-20250424064802-2fbb2d6f5d27
1818
github.com/grafana/grafana/apps/playlist v0.0.0-20250424064802-2fbb2d6f5d27
1919
github.com/grafana/grafana/pkg/apimachinery v0.0.0-20250424064802-2fbb2d6f5d27
@@ -52,6 +52,8 @@ require (
5252
k8s.io/client-go v0.32.3
5353
)
5454

55+
require github.com/grafana/grafana-asserts-public-clients/go/gcom v0.0.0-20250805165836-14e16b51b910
56+
5557
require (
5658
cuelang.org/go v0.11.1 // indirect
5759
dario.cat/mergo v1.0.1 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1
170170
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
171171
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
172172
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
173-
github.com/grafana/amixr-api-go-client v0.0.24 h1:Yvj8Ir02e3GTcetd+qHmajrLC690YJxK8lppEUkrsyA=
174-
github.com/grafana/amixr-api-go-client v0.0.24/go.mod h1:ihgLhTVimmjASuZ06y/mQxPcYH3toAIuUVGK6flHsMU=
175173
github.com/grafana/amixr-api-go-client v0.0.25 h1:tAQeJRuq9ihHotxq6/oEB6lIhuAdM+MUP0uPkNn1I3A=
176174
github.com/grafana/amixr-api-go-client v0.0.25/go.mod h1:ihgLhTVimmjASuZ06y/mQxPcYH3toAIuUVGK6flHsMU=
177175
github.com/grafana/authlib/claims v0.0.0-20250120084028-e3328c576437 h1:OlwbIVFcYgMjnQhpbZwRPVNrvZKTodvPMqwb8yEqVW0=
@@ -182,10 +180,12 @@ github.com/grafana/grafana-app-sdk v0.35.2-0.20250408075831-c2a87bde0849 h1:fzoG
182180
github.com/grafana/grafana-app-sdk v0.35.2-0.20250408075831-c2a87bde0849/go.mod h1:hQFtfn65wd/zTcQ/ftwOpRTr/B37MfIzPZD8jGoAx5E=
183181
github.com/grafana/grafana-app-sdk/logging v0.35.1 h1:taVpl+RoixTYl0JBJGhH+fPVmwA9wvdwdzJTZsv9buM=
184182
github.com/grafana/grafana-app-sdk/logging v0.35.1/go.mod h1:Y/bvbDhBiV/tkIle9RW49pgfSPIPSON8Q4qjx3pyqDk=
183+
github.com/grafana/grafana-asserts-public-clients/go/gcom v0.0.0-20250805165836-14e16b51b910 h1:2OfDIhMtXWWVQcDp9cq/VMSBOJJfDek9450rcsV+qLg=
184+
github.com/grafana/grafana-asserts-public-clients/go/gcom v0.0.0-20250805165836-14e16b51b910/go.mod h1:EL/5hluCvj6EDjkUfoClLKSKDoCoDowZUety28jhxQI=
185185
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20250526074454-7ec66e02e4bb h1:rmYEnCXHNQbRsuzc5jCX5qkBqFF37c5RCHlyqAAPJZo=
186186
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20250526074454-7ec66e02e4bb/go.mod h1:sYWkB3NhyirQJfy3wtNQ29UYjoHbRlJlYhqN1jNsC5g=
187-
github.com/grafana/grafana-openapi-client-go v0.0.0-20250516123951-83fcd32d7bbe h1:OdLLQKwEBVVhe9wHAncGp+Ff1N5aDl7erDIBdO9xBmA=
188-
github.com/grafana/grafana-openapi-client-go v0.0.0-20250516123951-83fcd32d7bbe/go.mod h1:hiZnMmXc9KXNUlvkV2BKFsiWuIFF/fF4wGgYWEjBitI=
187+
github.com/grafana/grafana-openapi-client-go v0.0.0-20250617151817-c0f8cbb88d5c h1:jox7J0BnJmcZJp8lp631u4gjDEoIfpi6O3yrpiXNTtg=
188+
github.com/grafana/grafana-openapi-client-go v0.0.0-20250617151817-c0f8cbb88d5c/go.mod h1:AOzHLStinAJHJmcih1eEbIRImxpT6enYUsZLnnOvhbo=
189189
github.com/grafana/grafana-plugin-sdk-go v0.275.0 h1:icGmZG91lVqIo79w/pSki6N44d3IjOjTfsfQPfu4THU=
190190
github.com/grafana/grafana-plugin-sdk-go v0.275.0/go.mod h1:mO9LJqdXDh5JpO/xIdPAeg5LdThgQ06Y/SLpXDWKw2c=
191191
github.com/grafana/grafana/apps/dashboard v0.0.0-20250424064802-2fbb2d6f5d27 h1:UAv+x7lwteJR4pPMpIZ9hzngzAT1oiOQ55pq2GS4YCE=

0 commit comments

Comments
 (0)