@@ -3,7 +3,6 @@ package asserts_test
33import (
44 "context"
55 "fmt"
6- "regexp"
76 "testing"
87 "time"
98
@@ -30,9 +29,9 @@ func TestAccAssertsLogConfig_basic(t *testing.T) {
3029 resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "data_source_uid" , "grafanacloud-logs" ),
3130 resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "error_label" , "error" ),
3231 // match rules
33- resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "match.0.property" , "asserts_entity_type " ),
32+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "match.0.property" , "environment " ),
3433 resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "match.0.op" , "=" ),
35- resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "match.0.values.0" , "Service " ),
34+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "match.0.values.0" , "production " ),
3635 // mappings
3736 resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "entity_property_to_log_label_mapping.otel_namespace" , "service_namespace" ),
3837 resource .TestCheckResourceAttr ("grafana_asserts_log_config.test" , "entity_property_to_log_label_mapping.otel_service" , "service_name" ),
@@ -96,14 +95,16 @@ func TestAccAssertsLogConfig_fullFields(t *testing.T) {
9695 resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "default_config" , "false" ),
9796 resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "data_source_uid" , "loki-uid-456" ),
9897 resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "error_label" , "error" ),
99- // match rules
100- resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.0.property" , "service" ),
98+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.0.property" , "cluster" ),
10199 resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.0.op" , "=" ),
102- resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.0.values.0" , "api" ),
103- resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.0.values.1" , "web" ),
104- resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.1.property" , "environment" ),
105- resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.1.op" , "CONTAINS" ),
106- resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.1.values.0" , "prod" ),
100+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.0.values.0" , "prod-cluster" ),
101+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.1.property" , "service" ),
102+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.1.op" , "=" ),
103+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.1.values.0" , "api" ),
104+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.1.values.1" , "web" ),
105+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.2.property" , "environment" ),
106+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.2.op" , "CONTAINS" ),
107+ resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "match.2.values.0" , "prod" ),
107108 // mappings
108109 resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "entity_property_to_log_label_mapping.service" , "service_name" ),
109110 resource .TestCheckResourceAttr ("grafana_asserts_log_config.full" , "entity_property_to_log_label_mapping.environment" , "env" ),
@@ -116,26 +117,6 @@ func TestAccAssertsLogConfig_fullFields(t *testing.T) {
116117 })
117118}
118119
119- func TestAccAssertsLogConfig_optimisticLocking (t * testing.T ) {
120- testutils .CheckCloudInstanceTestsEnabled (t )
121-
122- baseName := fmt .Sprintf ("lock-%s" , acctest .RandString (8 ))
123-
124- resource .ParallelTest (t , resource.TestCase {
125- ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
126- CheckDestroy : testAccAssertsLogConfigCheckDestroy ,
127- Steps : []resource.TestStep {
128- {
129- Config : testAccAssertsLogConfigOptimisticLockingConfig (baseName ),
130- // Expect an apply error due to conflicting concurrent upserts against
131- // the tenant log config (optimistic locking). Terraform will retry
132- // but ultimately one apply may fail; that is acceptable and expected.
133- ExpectError : regexp .MustCompile (`failed to create log configuration.*giving up after.*attempt` ),
134- },
135- },
136- })
137- }
138-
139120func testAccAssertsLogConfigCheckDestroy (s * terraform.State ) error {
140121 client := testutils .Provider .Meta ().(* common.Client )
141122 if client .AssertsAPIClient == nil {
@@ -197,9 +178,9 @@ resource "grafana_asserts_log_config" "test" {
197178 error_label = "error"
198179
199180 match {
200- property = "asserts_entity_type "
181+ property = "environment "
201182 op = "="
202- values = ["Service "]
183+ values = ["production "]
203184 }
204185
205186 entity_property_to_log_label_mapping = {
@@ -224,6 +205,12 @@ resource "grafana_asserts_log_config" "test" {
224205 default_config = %s
225206 data_source_uid = "grafanacloud-logs"
226207
208+ match {
209+ property = "namespace"
210+ op = "="
211+ values = ["default"]
212+ }
213+
227214 match {
228215 property = "otel_service"
229216 op = "IS NOT NULL"
@@ -241,6 +228,12 @@ resource "grafana_asserts_log_config" "test" {
241228 default_config = false
242229 data_source_uid = "grafanacloud-logs"
243230
231+ match {
232+ property = "namespace"
233+ op = "="
234+ values = ["default"]
235+ }
236+
244237 match {
245238 property = "otel_service"
246239 op = "IS NOT NULL"
@@ -259,6 +252,12 @@ resource "grafana_asserts_log_config" "full" {
259252 data_source_uid = "loki-uid-456"
260253 error_label = "error"
261254
255+ match {
256+ property = "cluster"
257+ op = "="
258+ values = ["prod-cluster"]
259+ }
260+
262261 match {
263262 property = "service"
264263 op = "="
@@ -281,21 +280,3 @@ resource "grafana_asserts_log_config" "full" {
281280}
282281` , name )
283282}
284-
285- func testAccAssertsLogConfigOptimisticLockingConfig (baseName string ) string {
286- return fmt .Sprintf (`
287- resource "grafana_asserts_log_config" "lock1" {
288- name = "%s-1"
289- priority = 3001
290- default_config = false
291- data_source_uid = "loki-uid-lock1"
292- }
293-
294- resource "grafana_asserts_log_config" "lock2" {
295- name = "%s-2"
296- priority = 3002
297- default_config = false
298- data_source_uid = "loki-uid-lock2"
299- }
300- ` , baseName , baseName )
301- }
0 commit comments