Skip to content

Commit 97535da

Browse files
authored
test(monitor-alert): add = and != operator test coverage for alert v2 resources (#709)
## Summary Investigated #707 and found the reported behavior is **not reproducible**. The Sysdig API (`us2.app.sysdig.com`) accepts `conditionOperator: "="` and returns it unchanged — there is no normalization to `"=="`. Curl testing confirmed: - `conditionOperator: "="` → **200 OK**, stored and returned as `=` - `conditionOperator: "=="` → **422 "Wrong grammar for condition"** (only valid for PromQL/form_based_prometheus alerts) This PR adds acceptance test coverage for the `=` and `!=` operators across all three affected alert types (metric, change, event) to prevent regressions and document the expected behavior. Closes #707
1 parent ec49dbf commit 97535da

3 files changed

Lines changed: 142 additions & 0 deletions

sysdig/resource_sysdig_monitor_alert_v2_change_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ func TestAccAlertV2Change(t *testing.T) {
5757
{
5858
Config: alertV2ChangeWithUnreportedAlertNotificationsRetentionSec(rText()),
5959
},
60+
{
61+
Config: alertV2ChangeWithNotEqualOperator(rText()),
62+
Check: resource.ComposeTestCheckFunc(
63+
resource.TestCheckResourceAttr("sysdig_monitor_alert_v2_change.sample", "operator", "!="),
64+
),
65+
},
66+
{
67+
Config: alertV2ChangeWithEqualOperator(rText()),
68+
Check: resource.ComposeTestCheckFunc(
69+
resource.TestCheckResourceAttr("sysdig_monitor_alert_v2_change.sample", "operator", "="),
70+
),
71+
},
6072
{
6173
Config: alertV2ChangeWithWarningThreshold(rText()),
6274
},
@@ -314,6 +326,36 @@ resource "sysdig_monitor_alert_v2_change" "sample" {
314326
`, name)
315327
}
316328

329+
func alertV2ChangeWithNotEqualOperator(name string) string {
330+
return fmt.Sprintf(`
331+
resource "sysdig_monitor_alert_v2_change" "sample" {
332+
name = "TERRAFORM TEST - CHANGE %s"
333+
metric = "sysdig_container_cpu_used_percent"
334+
group_aggregation = "avg"
335+
time_aggregation = "avg"
336+
operator = "!="
337+
threshold = 50
338+
shorter_time_range_seconds = 300
339+
longer_time_range_seconds = 3600
340+
}
341+
`, name)
342+
}
343+
344+
func alertV2ChangeWithEqualOperator(name string) string {
345+
return fmt.Sprintf(`
346+
resource "sysdig_monitor_alert_v2_change" "sample" {
347+
name = "TERRAFORM TEST - CHANGE %s"
348+
metric = "sysdig_container_cpu_used_percent"
349+
group_aggregation = "avg"
350+
time_aggregation = "avg"
351+
operator = "="
352+
threshold = 50
353+
shorter_time_range_seconds = 300
354+
longer_time_range_seconds = 3600
355+
}
356+
`, name)
357+
}
358+
317359
func alertV2ChangeWithWarningThreshold(name string) string {
318360
return fmt.Sprintf(`
319361
resource "sysdig_monitor_notification_channel_email" "nc_email1" {

sysdig/resource_sysdig_monitor_alert_v2_event_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ func TestAccAlertV2Event(t *testing.T) {
3636
{
3737
Config: alertV2EventWithScrambledSources(rText()),
3838
},
39+
{
40+
Config: alertV2EventWithNotEqualOperator(rText()),
41+
Check: resource.ComposeTestCheckFunc(
42+
resource.TestCheckResourceAttr("sysdig_monitor_alert_v2_event.sample", "operator", "!="),
43+
),
44+
},
45+
{
46+
Config: alertV2EventWithEqualOperator(rText()),
47+
Check: resource.ComposeTestCheckFunc(
48+
resource.TestCheckResourceAttr("sysdig_monitor_alert_v2_event.sample", "operator", "="),
49+
),
50+
},
3951
{
4052
Config: alertV2EventWithWarningThreshold(rText()),
4153
},
@@ -138,6 +150,50 @@ resource "sysdig_monitor_alert_v2_event" "sample" {
138150
`, name)
139151
}
140152

153+
func alertV2EventWithNotEqualOperator(name string) string {
154+
return fmt.Sprintf(`
155+
resource "sysdig_monitor_alert_v2_event" "sample" {
156+
157+
name = "TERRAFORM TEST - EVENTV2 %s"
158+
filter = "xxx"
159+
operator = "!="
160+
threshold = 50
161+
162+
scope {
163+
label = "kube_cluster_name"
164+
operator = "in"
165+
values = ["thom-cluster1", "demo-env-prom"]
166+
}
167+
168+
range_seconds = 600
169+
170+
}
171+
172+
`, name)
173+
}
174+
175+
func alertV2EventWithEqualOperator(name string) string {
176+
return fmt.Sprintf(`
177+
resource "sysdig_monitor_alert_v2_event" "sample" {
178+
179+
name = "TERRAFORM TEST - EVENTV2 %s"
180+
filter = "xxx"
181+
operator = "="
182+
threshold = 50
183+
184+
scope {
185+
label = "kube_cluster_name"
186+
operator = "in"
187+
values = ["thom-cluster1", "demo-env-prom"]
188+
}
189+
190+
range_seconds = 600
191+
192+
}
193+
194+
`, name)
195+
}
196+
141197
func alertV2EventWithWarningThreshold(name string) string {
142198
return fmt.Sprintf(`
143199
resource "sysdig_monitor_alert_v2_event" "sample" {

sysdig/resource_sysdig_monitor_alert_v2_metric_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ func TestAccAlertV2Metric(t *testing.T) {
8484
{
8585
Config: alertV2MetricWithLabels(rText()),
8686
},
87+
{
88+
Config: alertV2MetricWithNotEqualOperator(rText()),
89+
Check: resource.ComposeTestCheckFunc(
90+
resource.TestCheckResourceAttr("sysdig_monitor_alert_v2_metric.sample", "operator", "!="),
91+
),
92+
},
93+
{
94+
Config: alertV2MetricWithEqualOperator(rText()),
95+
Check: resource.ComposeTestCheckFunc(
96+
resource.TestCheckResourceAttr("sysdig_monitor_alert_v2_metric.sample", "operator", "="),
97+
),
98+
},
8799
{
88100
Config: alertV2MetricWithWarningThreshold(rText()),
89101
},
@@ -530,6 +542,38 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
530542
`, name)
531543
}
532544

545+
func alertV2MetricWithNotEqualOperator(name string) string {
546+
return fmt.Sprintf(`
547+
resource "sysdig_monitor_alert_v2_metric" "sample" {
548+
549+
name = "TERRAFORM TEST - METRICV2 %s"
550+
metric = "sysdig_container_cpu_used_percent"
551+
group_aggregation = "avg"
552+
time_aggregation = "avg"
553+
operator = "!="
554+
threshold = 50
555+
range_seconds = 600
556+
557+
}
558+
`, name)
559+
}
560+
561+
func alertV2MetricWithEqualOperator(name string) string {
562+
return fmt.Sprintf(`
563+
resource "sysdig_monitor_alert_v2_metric" "sample" {
564+
565+
name = "TERRAFORM TEST - METRICV2 %s"
566+
metric = "sysdig_container_cpu_used_percent"
567+
group_aggregation = "avg"
568+
time_aggregation = "avg"
569+
operator = "="
570+
threshold = 50
571+
range_seconds = 600
572+
573+
}
574+
`, name)
575+
}
576+
533577
func alertV2MetricWithWarningThreshold(name string) string {
534578
return fmt.Sprintf(`
535579
resource "sysdig_monitor_notification_channel_email" "nc_email1" {

0 commit comments

Comments
 (0)