Skip to content

Commit faf2847

Browse files
authored
[chore] fix k8sevents test (#1696)
* fix k8sevents test * drop skip * fix regex * remove flaky container attr * rm flaky attr
1 parent 3a32a4a commit faf2847

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

functional_tests/k8sevents/k8sevents_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ var eventsLogsConsumer *consumertest.LogsSink
5252
// UPDATE_EXPECTED_RESULTS: if set to true, the test will update the expected results
5353
// KUBECONFIG: the path to the kubeconfig file
5454
func Test_K8SEvents(t *testing.T) {
55-
t.Skip("Skip until fixed")
5655
eventsLogsConsumer := setup(t)
5756
if os.Getenv("SKIP_TESTS") == "true" {
5857
t.Log("Skipping tests as SKIP_TESTS is set to true")
@@ -64,10 +63,14 @@ func Test_K8SEvents(t *testing.T) {
6463
t.Run("CheckK8SEventsLogs", func(t *testing.T) {
6564
actualLogs := selectResLogs("com.splunk.sourcetype", "kube:events", eventsLogsConsumer)
6665
k8sEventsLogs := selectLogs(t, "k8s.namespace.name", "k8sevents-test", &actualLogs, func(body string) string {
67-
re := regexp.MustCompile(`Successfully pulled image "busybox:latest" in .* \(.* including waiting\)`)
66+
re := regexp.MustCompile(`Successfully pulled image "busybox:latest" in .* \(.* including waiting\).*`)
6867
return re.ReplaceAllString(body, `Successfully pulled image "busybox:latest" in <time> (<time> including waiting)`)
6968
})
69+
70+
// These container attributes may not get added by the k8sattributesprocessor on the events about container image pull/start
7071
removeFlakyLogRecordAttr(k8sEventsLogs, "container.id")
72+
removeFlakyLogRecordAttr(k8sEventsLogs, "container.image.name")
73+
removeFlakyLogRecordAttr(k8sEventsLogs, "container.image.tag")
7174

7275
expectedEventsLogsFile := "testdata/expected_k8sevents.yaml"
7376
expectedEventsLogs, err := golden.ReadLogs(expectedEventsLogsFile)
@@ -96,7 +99,7 @@ func Test_K8SEvents(t *testing.T) {
9699
k8sObjectsLogs = updateLogRecordBody(k8sObjectsLogs, []string{"object", "metadata", "resourceVersion"}, "85980")
97100
k8sObjectsLogs = updateLogRecordBody(k8sObjectsLogs, []string{"object", "metadata", "creationTimestamp"}, "2025-03-04T01:59:10Z")
98101
k8sObjectsLogs = updateLogRecordBody(k8sObjectsLogs, []string{"object", "metadata", "managedFields", "0", "time"}, "2025-03-04T01:59:10Z")
99-
// k8sObjectsLogs = updateLogRecordBody(k8sObjectsLogs, []string{"object", "metadata", "managedFields", "0", "manager"}, "functional_test.test")
102+
k8sObjectsLogs = updateLogRecordBody(k8sObjectsLogs, []string{"object", "metadata", "managedFields", "0", "manager"}, "k8sevents.test") // changes when the test name which runs k8s client changes
100103

101104
expectedObjectsLogsFile := "testdata/expected_k8sobjects.yaml"
102105
expectedObjectsLogs, err := golden.ReadLogs(expectedObjectsLogsFile)

functional_tests/k8sevents/testdata/expected_k8sevents.yaml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,6 @@ resourceLogs:
130130
timeUnixNano: "1740082291000000000"
131131
traceId: ""
132132
- attributes:
133-
- key: container.image.name
134-
value:
135-
stringValue: busybox
136-
- key: container.image.tag
137-
value:
138-
stringValue: latest
139133
- key: deployment.environment
140134
value:
141135
stringValue: dev
@@ -199,12 +193,6 @@ resourceLogs:
199193
timeUnixNano: "1740082292000000000"
200194
traceId: ""
201195
- attributes:
202-
- key: container.image.name
203-
value:
204-
stringValue: busybox
205-
- key: container.image.tag
206-
value:
207-
stringValue: latest
208196
- key: deployment.environment
209197
value:
210198
stringValue: dev
@@ -268,12 +256,6 @@ resourceLogs:
268256
timeUnixNano: "1740082293000000000"
269257
traceId: ""
270258
- attributes:
271-
- key: container.image.name
272-
value:
273-
stringValue: busybox
274-
- key: container.image.tag
275-
value:
276-
stringValue: latest
277259
- key: deployment.environment
278260
value:
279261
stringValue: dev
@@ -337,12 +319,6 @@ resourceLogs:
337319
timeUnixNano: "1740082293000000000"
338320
traceId: ""
339321
- attributes:
340-
- key: container.image.name
341-
value:
342-
stringValue: busybox
343-
- key: container.image.tag
344-
value:
345-
stringValue: latest
346322
- key: deployment.environment
347323
value:
348324
stringValue: dev

functional_tests/k8sevents/testdata/expected_k8sobjects.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ resourceLogs:
138138
kvlistValue: {}
139139
- key: manager
140140
value:
141-
stringValue: functional_tests.test
141+
stringValue: k8sevents.test
142142
- key: operation
143143
value:
144144
stringValue: Update

0 commit comments

Comments
 (0)