@@ -1377,3 +1377,89 @@ func Test_buildLatencyPercentiles(t *testing.T) {
1377
1377
})
1378
1378
}
1379
1379
}
1380
+
1381
+ func TestAccSpanLatencyConditionInvalidQuery (t * testing.T ) {
1382
+ var condition client.UnifiedCondition
1383
+
1384
+ invalidQuery := "customer IN (\\ \" test\\ \" )"
1385
+ validQuery := "\\ \" customer\\ \" IN (\\ \" test\\ \" )"
1386
+
1387
+ conditionConfigTemplate := `
1388
+ resource "lightstep_slack_destination" "slack" {
1389
+ project_name = "` + testProject + `"
1390
+ channel = "#emergency-room"
1391
+ }
1392
+
1393
+ resource "lightstep_metric_condition" "test" {
1394
+ project_name = "` + testProject + `"
1395
+ name = "Span latency alert"
1396
+
1397
+ expression {
1398
+ is_multi = false
1399
+ is_no_data = true
1400
+ operand = "above"
1401
+ thresholds {
1402
+ critical = 10
1403
+ warning = 5
1404
+ }
1405
+ }
1406
+
1407
+ metric_query {
1408
+ hidden = false
1409
+ query_name = "a"
1410
+ display = "line"
1411
+ spans {
1412
+ query = "%s"
1413
+ operator = "latency"
1414
+ operator_input_window_ms = 3600000
1415
+ latency_percentiles = [50]
1416
+ }
1417
+
1418
+ final_window_operation {
1419
+ operator = "min"
1420
+ input_window_ms = 30000
1421
+ }
1422
+ }
1423
+
1424
+ alerting_rule {
1425
+ id = lightstep_slack_destination.slack.id
1426
+ update_interval = "1h"
1427
+ }
1428
+ }
1429
+ `
1430
+
1431
+ resourceName := "lightstep_metric_condition.test"
1432
+ resource .Test (t , resource.TestCase {
1433
+ PreCheck : func () { testAccPreCheck (t ) },
1434
+ Providers : testAccProviders ,
1435
+ CheckDestroy : testAccMetricConditionDestroy ,
1436
+ Steps : []resource.TestStep {
1437
+ // make a valid legacy span alert
1438
+ {
1439
+ Config : fmt .Sprintf (conditionConfigTemplate , validQuery ),
1440
+ Check : resource .ComposeTestCheckFunc (
1441
+ testAccCheckMetricConditionExists (resourceName , & condition ),
1442
+ resource .TestCheckResourceAttr (resourceName , "metric_query.0.spans.0.query" , "\" customer\" IN (\" test\" )" ),
1443
+ ),
1444
+ },
1445
+ // attempt to update with an invalid query, this fails but stores the invalid query in state
1446
+ {
1447
+ Config : fmt .Sprintf (conditionConfigTemplate , invalidQuery ),
1448
+ Check : resource .ComposeTestCheckFunc (
1449
+ testAccCheckMetricConditionExists (resourceName , & condition ),
1450
+ // the resource in state has an invalid query
1451
+ resource .TestCheckResourceAttr (resourceName , "metric_query.0.spans.0.query" , invalidQuery ),
1452
+ ),
1453
+ ExpectError : regexp .MustCompile (".*Invalid query predicate.*" ),
1454
+ },
1455
+ // fix the query, apply should succeed despite the invalid query in state
1456
+ {
1457
+ Config : fmt .Sprintf (conditionConfigTemplate , validQuery ),
1458
+ Check : resource .ComposeTestCheckFunc (
1459
+ testAccCheckMetricConditionExists (resourceName , & condition ),
1460
+ resource .TestCheckResourceAttr (resourceName , "metric_query.0.spans.0.query" , "\" customer\" IN (\" test\" )" ),
1461
+ ),
1462
+ },
1463
+ },
1464
+ })
1465
+ }
0 commit comments