From ba02dfd641b4504a700fffc6ac6ce78c8f92a701 Mon Sep 17 00:00:00 2001 From: Pawel Szkamruk Date: Tue, 7 Jan 2025 13:06:00 +0100 Subject: [PATCH 1/3] improvements, stabilization --- functional_tests/configuration_switching_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/functional_tests/configuration_switching_test.go b/functional_tests/configuration_switching_test.go index 3cf5c8f6e7..64e4cf7a17 100644 --- a/functional_tests/configuration_switching_test.go +++ b/functional_tests/configuration_switching_test.go @@ -269,8 +269,15 @@ func testIndexSwitch(t *testing.T) { var indices []string logs := agentLogsConsumer.AllLogs() sourcetypes, indices = getLogsIndexAndSourceType(logs) - assert.True(t, len(sourcetypes) > 1) // we are also receiving logs from other kind containers - assert.Contains(t, sourcetypes, "kube:container:kindnet-cni") + assert.True(t, len(sourcetypes) > 1) // we are receiving logs from different containers + // check sourcetypes have same prefix + prefix := "kube:container:" + for _, element := range sourcetypes { + if !strings.HasPrefix(element, prefix) { + t.Errorf("Element does not start with the prefix '%s': %s", prefix, element) + } + } + assert.NotContains(t, sourcetypes, nonDefaultSourcetype) assert.True(t, len(indices) == 1) assert.True(t, indices[0] == logsIndex) @@ -289,7 +296,6 @@ func testIndexSwitch(t *testing.T) { resetLogsSink(t, agentLogsConsumer) resetMetricsSink(t, hecMetricsConsumer) - waitForMetrics(t, 3, hecMetricsConsumer) waitForLogs(t, 3, agentLogsConsumer) logs = agentLogsConsumer.AllLogs() sourcetypes, indices = getLogsIndexAndSourceType(logs) @@ -298,6 +304,8 @@ func testIndexSwitch(t *testing.T) { assert.Contains(t, sourcetypes, nonDefaultSourcetype) assert.True(t, len(indices) == 1) assert.True(t, len(sourcetypes) == 1) + + waitForMetrics(t, 3, hecMetricsConsumer) mIndices = getMetricsIndex(hecMetricsConsumer.AllMetrics()) assert.True(t, len(mIndices) == 1) assert.True(t, mIndices[0] == newMetricsIndex) @@ -318,6 +326,7 @@ func testClusterReceiverEnabledOrDisabled(t *testing.T) { logsObjectsHecEndpoint := fmt.Sprintf("http://%s:%d/services/collector", hostEp, hecLogsObjectsReceiverPort) t.Run("check cluster receiver enabled", func(t *testing.T) { + resetLogsSink(t, logsObjectsConsumer) replacements := map[string]interface{}{ "ClusterReceiverEnabled": false, "LogObjectsHecEndpoint": logsObjectsHecEndpoint, @@ -410,7 +419,6 @@ func getMetricsIndex(metrics []pmetric.Metrics) []string { var indices []string for i := 0; i < len(metrics); i++ { m := metrics[i] - fmt.Printf("Metrics: %v", m.ResourceMetrics().At(0).Resource().Attributes()) if value, ok := m.ResourceMetrics().At(0).Resource().Attributes().Get("com.splunk.index"); ok { index := value.AsString() if !contains(indices, index) { From 4df1c463f65f4f01f3e310a010c4a7e78ae1369c Mon Sep 17 00:00:00 2001 From: pszkamruk-splunk <75434853+pszkamruk-splunk@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:54:09 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Antoine Toulme --- functional_tests/configuration_switching_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functional_tests/configuration_switching_test.go b/functional_tests/configuration_switching_test.go index 64e4cf7a17..6205a6e80c 100644 --- a/functional_tests/configuration_switching_test.go +++ b/functional_tests/configuration_switching_test.go @@ -269,12 +269,12 @@ func testIndexSwitch(t *testing.T) { var indices []string logs := agentLogsConsumer.AllLogs() sourcetypes, indices = getLogsIndexAndSourceType(logs) - assert.True(t, len(sourcetypes) > 1) // we are receiving logs from different containers + assert.GreaterThan(t, len(sourcetypes), 1) // we are receiving logs from different containers // check sourcetypes have same prefix prefix := "kube:container:" for _, element := range sourcetypes { if !strings.HasPrefix(element, prefix) { - t.Errorf("Element does not start with the prefix '%s': %s", prefix, element) + t.Errorf("Element does not start with the prefix %q: %s", prefix, element) } } assert.NotContains(t, sourcetypes, nonDefaultSourcetype) From 4952eff831d1584dc0cc995568258ea47d38e2b5 Mon Sep 17 00:00:00 2001 From: Pawel Szkamruk Date: Thu, 16 Jan 2025 10:42:36 +0100 Subject: [PATCH 3/3] assertion fixing --- functional_tests/configuration_switching_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functional_tests/configuration_switching_test.go b/functional_tests/configuration_switching_test.go index 6205a6e80c..e20f6fa4c0 100644 --- a/functional_tests/configuration_switching_test.go +++ b/functional_tests/configuration_switching_test.go @@ -269,7 +269,7 @@ func testIndexSwitch(t *testing.T) { var indices []string logs := agentLogsConsumer.AllLogs() sourcetypes, indices = getLogsIndexAndSourceType(logs) - assert.GreaterThan(t, len(sourcetypes), 1) // we are receiving logs from different containers + assert.Greater(t, len(sourcetypes), 1) // we are receiving logs from different containers // check sourcetypes have same prefix prefix := "kube:container:" for _, element := range sourcetypes {