From b04d1b2bfa17cf6ee04690f61d8086da2dd3e14c Mon Sep 17 00:00:00 2001 From: Dmitry Anoshin Date: Wed, 5 Mar 2025 15:14:51 -0800 Subject: [PATCH] [chore] Move functional test to separate directories Move functional test to separate directories instead of using build tags --- .github/workflows/functional_test_v2.yaml | 16 ++-- Makefile | 4 +- functional_tests/README.md | 2 +- .../configuration_switching_test.go | 95 +++++++++---------- .../values_cluster_receiver_only.yaml.tmpl | 0 ...alues_cluster_receiver_switching.yaml.tmpl | 0 .../values/values_indexes_switching.yaml.tmpl | 0 ...alues_logs_and_metrics_switching.yaml.tmpl | 0 .../{ => functional}/functional_test.go | 50 +++++----- .../testdata/dotnet/Dockerfile | 0 .../testdata/dotnet/DotNetTestApp.csproj | 0 .../{ => functional}/testdata/dotnet/Makefile | 0 .../testdata/dotnet/Program.cs | 0 .../testdata/dotnet/README.md | 0 .../testdata/dotnet/Startup.cs | 0 .../testdata/dotnet/deployment.yaml | 0 .../expected_cluster_receiver.yaml | 0 .../expected_dotnet_traces.yaml | 0 .../expected_internal_metrics.yaml | 0 .../expected_java_traces.yaml | 0 .../expected_kubeletstats_metrics.yaml | 0 .../expected_nodejs_traces.yaml | 0 .../expected_python_traces.yaml | 0 .../expected_cluster_receiver.yaml | 0 .../expected_dotnet_traces.yaml | 0 .../expected_internal_metrics.yaml | 0 .../expected_java_traces.yaml | 0 .../expected_kubeletstats_metrics.yaml | 0 .../expected_nodejs_traces.yaml | 0 .../expected_python_traces.yaml | 0 .../{ => functional}/testdata/java/Dockerfile | 0 .../{ => functional}/testdata/java/Makefile | 0 .../{ => functional}/testdata/java/README.md | 0 .../testdata/java/deployment.yaml | 0 .../{ => functional}/testdata/java/start.sh | 0 ...eployment_with_prometheus_annotations.yaml | 0 .../testdata/manifests/operator_crds.yaml | 0 .../testdata/manifests/pod_monitor.yaml | 0 .../manifests/prometheus_operator_crds.yaml | 0 .../testdata/manifests/service.yaml | 0 .../testdata/manifests/service_monitor.yaml | 0 .../testdata/manifests/test_jobs.yaml | 0 .../testdata/nodejs/Dockerfile | 0 .../{ => functional}/testdata/nodejs/Makefile | 0 .../testdata/nodejs/README.md | 0 .../testdata/nodejs/deployment.yaml | 0 .../{ => functional}/testdata/nodejs/index.js | 0 .../{ => functional}/testdata/nodejs/start.sh | 0 .../testdata/python/Dockerfile | 0 .../{ => functional}/testdata/python/Makefile | 0 .../testdata/python/README.md | 0 .../testdata/python/deployment.yaml | 0 .../{ => functional}/testdata/python/start.sh | 0 .../{ => functional}/testdata/python/web.py | 0 .../testdata/values/aks_test_values.yaml.tmpl | 0 .../values/autopilot_test_values.yaml.tmpl | 0 .../testdata/values/test_values.yaml.tmpl | 0 .../{ => histogram}/histogram_test.go | 37 ++++---- .../testdata}/expected/v1.25/api_metrics.yaml | 0 .../v1.25/controller_manager_metrics.yaml | 0 .../expected/v1.25/coredns_metrics.yaml | 0 .../expected/v1.25/etcd_metrics.yaml | 0 .../expected/v1.25/proxy_metrics.yaml | 0 .../expected/v1.25/scheduler_metrics.yaml | 0 .../testdata}/expected/v1.26/api_metrics.yaml | 0 .../v1.26/controller_manager_metrics.yaml | 0 .../expected/v1.26/coredns_metrics.yaml | 0 .../expected/v1.26/etcd_metrics.yaml | 0 .../expected/v1.26/proxy_metrics.yaml | 0 .../expected/v1.26/scheduler_metrics.yaml | 0 .../testdata}/expected/v1.27/api_metrics.yaml | 0 .../v1.27/controller_manager_metrics.yaml | 0 .../expected/v1.27/coredns_metrics.yaml | 0 .../expected/v1.27/etcd_metrics.yaml | 0 .../expected/v1.27/proxy_metrics.yaml | 0 .../expected/v1.27/scheduler_metrics.yaml | 0 .../testdata}/expected/v1.28/api_metrics.yaml | 0 .../v1.28/controller_manager_metrics.yaml | 0 .../expected/v1.28/coredns_metrics.yaml | 0 .../expected/v1.28/etcd_metrics.yaml | 0 .../expected/v1.28/proxy_metrics.yaml | 0 .../expected/v1.28/scheduler_metrics.yaml | 0 .../testdata}/expected/v1.29/api_metrics.yaml | 0 .../v1.29/controller_manager_metrics.yaml | 0 .../expected/v1.29/coredns_metrics.yaml | 0 .../expected/v1.29/etcd_metrics.yaml | 0 .../expected/v1.29/proxy_metrics.yaml | 0 .../expected/v1.29/scheduler_metrics.yaml | 0 .../testdata}/expected/v1.30/api_metrics.yaml | 0 .../v1.30/controller_manager_metrics.yaml | 0 .../expected/v1.30/coredns_metrics.yaml | 0 .../expected/v1.30/etcd_metrics.yaml | 0 .../expected/v1.30/proxy_metrics.yaml | 0 .../expected/v1.30/scheduler_metrics.yaml | 0 .../testdata}/values/test_values.yaml.tmpl | 0 functional_tests/internal/api_server.go | 3 + functional_tests/{ => internal}/common.go | 53 +++++++---- functional_tests/{ => istio}/istio_test.go | 34 +++---- .../testdata}/expected_istiod.yaml | 0 .../testdata}/expected_istioingress.yaml | 0 .../testdata}/istio_values.yaml.tmpl | 0 .../testobjects/1-serviceaccount.yaml | 0 .../testdata}/testobjects/2-service.yaml | 0 .../testdata}/testobjects/3-deployment.yaml | 0 .../testdata}/testobjects/gateway.yaml | 0 .../testdata}/testobjects/virtualservice.yaml | 0 .../{ => k8sevents}/k8sevents_test.go | 34 +++---- .../testdata}/expected_k8sevents.yaml | 0 .../testdata}/expected_k8sobjects.yaml | 0 .../testdata}/k8sevents_values.yaml.tmpl | 0 .../testobjects/1-serviceaccount.yaml | 0 .../testdata}/testobjects/2-svc.yaml | 0 .../testdata}/testobjects/3-sts.yaml | 0 113 files changed, 161 insertions(+), 167 deletions(-) rename functional_tests/{ => configuration_switching}/configuration_switching_test.go (90%) rename functional_tests/{testdata_configuration_switching => configuration_switching/testdata}/values/values_cluster_receiver_only.yaml.tmpl (100%) rename functional_tests/{testdata_configuration_switching => configuration_switching/testdata}/values/values_cluster_receiver_switching.yaml.tmpl (100%) rename functional_tests/{testdata_configuration_switching => configuration_switching/testdata}/values/values_indexes_switching.yaml.tmpl (100%) rename functional_tests/{testdata_configuration_switching => configuration_switching/testdata}/values/values_logs_and_metrics_switching.yaml.tmpl (100%) rename functional_tests/{ => functional}/functional_test.go (97%) rename functional_tests/{ => functional}/testdata/dotnet/Dockerfile (100%) rename functional_tests/{ => functional}/testdata/dotnet/DotNetTestApp.csproj (100%) rename functional_tests/{ => functional}/testdata/dotnet/Makefile (100%) rename functional_tests/{ => functional}/testdata/dotnet/Program.cs (100%) rename functional_tests/{ => functional}/testdata/dotnet/README.md (100%) rename functional_tests/{ => functional}/testdata/dotnet/Startup.cs (100%) rename functional_tests/{ => functional}/testdata/dotnet/deployment.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_eks_values/expected_cluster_receiver.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_eks_values/expected_dotnet_traces.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_eks_values/expected_internal_metrics.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_eks_values/expected_java_traces.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_eks_values/expected_kubeletstats_metrics.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_eks_values/expected_nodejs_traces.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_eks_values/expected_python_traces.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_kind_values/expected_cluster_receiver.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_kind_values/expected_dotnet_traces.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_kind_values/expected_internal_metrics.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_kind_values/expected_java_traces.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_kind_values/expected_kubeletstats_metrics.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_kind_values/expected_nodejs_traces.yaml (100%) rename functional_tests/{ => functional}/testdata/expected_kind_values/expected_python_traces.yaml (100%) rename functional_tests/{ => functional}/testdata/java/Dockerfile (100%) rename functional_tests/{ => functional}/testdata/java/Makefile (100%) rename functional_tests/{ => functional}/testdata/java/README.md (100%) rename functional_tests/{ => functional}/testdata/java/deployment.yaml (100%) rename functional_tests/{ => functional}/testdata/java/start.sh (100%) rename functional_tests/{ => functional}/testdata/manifests/deployment_with_prometheus_annotations.yaml (100%) rename functional_tests/{ => functional}/testdata/manifests/operator_crds.yaml (100%) rename functional_tests/{ => functional}/testdata/manifests/pod_monitor.yaml (100%) rename functional_tests/{ => functional}/testdata/manifests/prometheus_operator_crds.yaml (100%) rename functional_tests/{ => functional}/testdata/manifests/service.yaml (100%) rename functional_tests/{ => functional}/testdata/manifests/service_monitor.yaml (100%) rename functional_tests/{ => functional}/testdata/manifests/test_jobs.yaml (100%) rename functional_tests/{ => functional}/testdata/nodejs/Dockerfile (100%) rename functional_tests/{ => functional}/testdata/nodejs/Makefile (100%) rename functional_tests/{ => functional}/testdata/nodejs/README.md (100%) rename functional_tests/{ => functional}/testdata/nodejs/deployment.yaml (100%) rename functional_tests/{ => functional}/testdata/nodejs/index.js (100%) rename functional_tests/{ => functional}/testdata/nodejs/start.sh (100%) rename functional_tests/{ => functional}/testdata/python/Dockerfile (100%) rename functional_tests/{ => functional}/testdata/python/Makefile (100%) rename functional_tests/{ => functional}/testdata/python/README.md (100%) rename functional_tests/{ => functional}/testdata/python/deployment.yaml (100%) rename functional_tests/{ => functional}/testdata/python/start.sh (100%) rename functional_tests/{ => functional}/testdata/python/web.py (100%) rename functional_tests/{ => functional}/testdata/values/aks_test_values.yaml.tmpl (100%) rename functional_tests/{ => functional}/testdata/values/autopilot_test_values.yaml.tmpl (100%) rename functional_tests/{ => functional}/testdata/values/test_values.yaml.tmpl (100%) rename functional_tests/{ => histogram}/histogram_test.go (94%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.25/api_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.25/controller_manager_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.25/coredns_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.25/etcd_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.25/proxy_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.25/scheduler_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.26/api_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.26/controller_manager_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.26/coredns_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.26/etcd_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.26/proxy_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.26/scheduler_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.27/api_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.27/controller_manager_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.27/coredns_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.27/etcd_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.27/proxy_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.27/scheduler_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.28/api_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.28/controller_manager_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.28/coredns_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.28/etcd_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.28/proxy_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.28/scheduler_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.29/api_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.29/controller_manager_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.29/coredns_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.29/etcd_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.29/proxy_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.29/scheduler_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.30/api_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.30/controller_manager_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.30/coredns_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.30/etcd_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.30/proxy_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/expected/v1.30/scheduler_metrics.yaml (100%) rename functional_tests/{testdata_histogram => histogram/testdata}/values/test_values.yaml.tmpl (100%) rename functional_tests/{ => internal}/common.go (80%) rename functional_tests/{ => istio}/istio_test.go (93%) rename functional_tests/{testdata_istio => istio/testdata}/expected_istiod.yaml (100%) rename functional_tests/{testdata_istio => istio/testdata}/expected_istioingress.yaml (100%) rename functional_tests/{testdata_istio => istio/testdata}/istio_values.yaml.tmpl (100%) rename functional_tests/{testdata_istio => istio/testdata}/testobjects/1-serviceaccount.yaml (100%) rename functional_tests/{testdata_istio => istio/testdata}/testobjects/2-service.yaml (100%) rename functional_tests/{testdata_istio => istio/testdata}/testobjects/3-deployment.yaml (100%) rename functional_tests/{testdata_istio => istio/testdata}/testobjects/gateway.yaml (100%) rename functional_tests/{testdata_istio => istio/testdata}/testobjects/virtualservice.yaml (100%) rename functional_tests/{ => k8sevents}/k8sevents_test.go (93%) rename functional_tests/{testdata_k8sevents => k8sevents/testdata}/expected_k8sevents.yaml (100%) rename functional_tests/{testdata_k8sevents => k8sevents/testdata}/expected_k8sobjects.yaml (100%) rename functional_tests/{testdata_k8sevents => k8sevents/testdata}/k8sevents_values.yaml.tmpl (100%) rename functional_tests/{testdata_k8sevents => k8sevents/testdata}/testobjects/1-serviceaccount.yaml (100%) rename functional_tests/{testdata_k8sevents => k8sevents/testdata}/testobjects/2-svc.yaml (100%) rename functional_tests/{testdata_k8sevents => k8sevents/testdata}/testobjects/3-sts.yaml (100%) diff --git a/.github/workflows/functional_test_v2.yaml b/.github/workflows/functional_test_v2.yaml index a9c3bdc2c..5b496f398 100644 --- a/.github/workflows/functional_test_v2.yaml +++ b/.github/workflows/functional_test_v2.yaml @@ -72,7 +72,7 @@ jobs: env: K8S_VERSION: ${{ matrix.k8s-version }} run: | - TEARDOWN_BEFORE_SETUP=true UPDATE_EXPECTED_RESULTS=${{ env.UPLOAD_UPDATED_EXPECTED_RESULTS }} TAGS=${{ matrix.test-job }} make functionaltest + TEARDOWN_BEFORE_SETUP=true UPDATE_EXPECTED_RESULTS=${{ env.UPLOAD_UPDATED_EXPECTED_RESULTS }} SUITE=${{ matrix.test-job }} make functionaltest - name: Collect Kubernetes Cluster debug info on failure if: always() && (steps.run-functional-tests.outcome == 'failure' || env.UPLOAD_KUBERNETES_DEBUG_INFO == 'true') id: collect-debug-info @@ -129,7 +129,7 @@ jobs: env: HOST_ENDPOINT: 0.0.0.0 run: | - TEARDOWN_BEFORE_SETUP=true TAGS=functional make functionaltest + TEARDOWN_BEFORE_SETUP=true SUITE=functional make functionaltest eks-upgrade-test: name: Test helm upgrade in EKS - credentials needed @@ -188,7 +188,7 @@ jobs: env: HOST_ENDPOINT: 0.0.0.0 run: | - TAGS=functional make functionaltest + SUITE=functional make functionaltest eks-upgrade-from-release-test: name: Test helm upgrade from release in EKS - credentials needed @@ -243,7 +243,7 @@ jobs: env: HOST_ENDPOINT: 0.0.0.0 run: | - TAGS=functional make functionaltest + SUITE=functional make functionaltest gke-autopilot-test: name: Test helm install in GKE/Autopilot - credentials needed @@ -281,7 +281,7 @@ jobs: env: HOST_ENDPOINT: 0.0.0.0 run: | - TEARDOWN_BEFORE_SETUP=true TAGS=functional make functionaltest + TEARDOWN_BEFORE_SETUP=true SUITE=functional make functionaltest gke-autopilot-upgrade-test: name: Test helm upgrade in GKE/Autopilot - credentials needed @@ -340,7 +340,7 @@ jobs: env: HOST_ENDPOINT: 0.0.0.0 run: | - TAGS=functional make functionaltest + SUITE=functional make functionaltest aks-windows-test: name: Test helm install in AKS - credentials needed @@ -379,7 +379,7 @@ jobs: env: HOST_ENDPOINT: 0.0.0.0 run: | - TEARDOWN_BEFORE_SETUP=true TAGS=functional make functionaltest + TEARDOWN_BEFORE_SETUP=true SUITE=functional make functionaltest gce-autopilot-test: name: Test helm install in GCE (kops) - credentials needed @@ -410,4 +410,4 @@ jobs: HOST_ENDPOINT: 0.0.0.0 KUBECONFIG: /tmp/kubeconfig run: | - TEARDOWN_BEFORE_SETUP=true TAGS=functional make functionaltest + TEARDOWN_BEFORE_SETUP=true SUITE=functional make functionaltest diff --git a/Makefile b/Makefile index 03f494fa7..13b7cfc77 100644 --- a/Makefile +++ b/Makefile @@ -94,11 +94,11 @@ unittest: ## Run unittests on the Helm chart # Example Usage: # make functionaltest -# make functionaltest SKIP_SETUP=true SKIP_TEARDOWN=true SKIP_TESTS=true TEARDOWN_BEFORE_SETUP=true TAGS="functional" UPDATE_EXPECTED_RESULTS=true KUBE_TEST_ENV="kind" KUBECONFIG="/path/to/kubeconfig" +# make functionaltest SKIP_SETUP=true SKIP_TEARDOWN=true SKIP_TESTS=true TEARDOWN_BEFORE_SETUP=true SUITE="functional" UPDATE_EXPECTED_RESULTS=true KUBE_TEST_ENV="kind" KUBECONFIG="/path/to/kubeconfig" .PHONY: functionaltest functionaltest: ## Run functional tests for this Helm chart with optional tags and environment variables @echo "Running functional tests for this helm chart..." - cd functional_tests && go test -v $(if $(TAGS),-tags $(TAGS)) || exit 1 + cd functional_tests && go test -v ./$(SUITE)/... || exit 1 ##@ Changelog # Tasks related to changelog management diff --git a/functional_tests/README.md b/functional_tests/README.md index 2293266a5..07e8ee36e 100644 --- a/functional_tests/README.md +++ b/functional_tests/README.md @@ -29,7 +29,7 @@ When running tests you can use the following env vars to help with local develop - `SKIP_TEARDOWN`: Skip cleanup (useful to keep apps for local dev). - `SKIP_TESTS`: Skip tests; only set up and tear down the cluster. - `TEARDOWN_BEFORE_SETUP`: Clean up deployments before setting up. -- `TAGS`: Specify which tests to run (e.g., `TAGS="functional"`). +- `SUITE`: Specify which test suite to run (e.g., `SUITE="functional"`). - `UPDATE_EXPECTED_RESULTS`: Generate new golden files for test results. ## Run diff --git a/functional_tests/configuration_switching_test.go b/functional_tests/configuration_switching/configuration_switching_test.go similarity index 90% rename from functional_tests/configuration_switching_test.go rename to functional_tests/configuration_switching/configuration_switching_test.go index 6905b37ea..0a92d0684 100644 --- a/functional_tests/configuration_switching_test.go +++ b/functional_tests/configuration_switching/configuration_switching_test.go @@ -1,9 +1,7 @@ // Copyright Splunk Inc. // SPDX-License-Identifier: Apache-2.0 -//go:build configuration_switching - -package functional_tests +package configuration_switching import ( "bytes" @@ -28,7 +26,6 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/consumer/consumertest" "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/kube" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -44,7 +41,7 @@ const ( hecMetricsReceiverPort = 8091 apiPort = 8881 hecLogsObjectsReceiverPort = 8092 - testDir = "testdata_configuration_switching" + testDir = "testdata" valuesDir = "values" ) @@ -84,15 +81,13 @@ func deployChartsAndApps(t *testing.T, valuesFileName string, repl map[string]in client, err := kubernetes.NewForConfig(kubeConfig) require.NoError(t, err) - chartPath := filepath.Join("..", "helm-charts", "splunk-otel-collector") - chart, err := loader.Load(chartPath) - require.NoError(t, err) + chart := internal.LoadCollectorChart(t) var valuesBytes []byte valuesBytes, err = os.ReadFile(filepath.Join(testDir, valuesDir, valuesFileName)) require.NoError(t, err) - hostEp := hostEndpoint(t) + hostEp := internal.HostEndpoint(t) if len(hostEp) == 0 { require.Fail(t, "Host endpoint not found") } @@ -195,11 +190,11 @@ func testAgentLogsAndMetrics(t *testing.T) { agentLogsConsumer := setupOnce(t).logsConsumer t.Run("check logs and metrics received when both are enabled", func(t *testing.T) { - resetLogsSink(t, agentLogsConsumer) - resetMetricsSink(t, hecMetricsConsumer) + internal.ResetLogsSink(t, agentLogsConsumer) + internal.ResetMetricsSink(t, hecMetricsConsumer) - checkNoMetricsReceived(t, hecMetricsConsumer) - checkNoEventsReceived(t, agentLogsConsumer) + internal.CheckNoMetricsReceived(t, hecMetricsConsumer) + internal.CheckNoEventsReceived(t, agentLogsConsumer) replacements := map[string]interface{}{ "MetricsEnabled": true, @@ -207,17 +202,17 @@ func testAgentLogsAndMetrics(t *testing.T) { } deployChartsAndApps(t, valuesFileName, replacements) - waitForMetrics(t, 5, hecMetricsConsumer) - waitForLogs(t, 5, agentLogsConsumer) + internal.WaitForMetrics(t, 5, hecMetricsConsumer) + internal.WaitForLogs(t, 5, agentLogsConsumer) uninstallDeployment(t) }) t.Run("check metrics only enabled", func(t *testing.T) { - resetLogsSink(t, agentLogsConsumer) - resetMetricsSink(t, hecMetricsConsumer) + internal.ResetLogsSink(t, agentLogsConsumer) + internal.ResetMetricsSink(t, hecMetricsConsumer) - checkNoMetricsReceived(t, hecMetricsConsumer) - checkNoEventsReceived(t, agentLogsConsumer) + internal.CheckNoMetricsReceived(t, hecMetricsConsumer) + internal.CheckNoEventsReceived(t, agentLogsConsumer) replacements := map[string]interface{}{ "MetricsEnabled": true, @@ -225,14 +220,14 @@ func testAgentLogsAndMetrics(t *testing.T) { } deployChartsAndApps(t, valuesFileName, replacements) - waitForMetrics(t, 5, hecMetricsConsumer) - checkNoEventsReceived(t, agentLogsConsumer) + internal.WaitForMetrics(t, 5, hecMetricsConsumer) + internal.CheckNoEventsReceived(t, agentLogsConsumer) uninstallDeployment(t) }) t.Run("check logs only enabled", func(t *testing.T) { - resetLogsSink(t, agentLogsConsumer) - resetMetricsSink(t, hecMetricsConsumer) + internal.ResetLogsSink(t, agentLogsConsumer) + internal.ResetMetricsSink(t, hecMetricsConsumer) replacements := map[string]interface{}{ "MetricsEnabled": false, @@ -240,10 +235,10 @@ func testAgentLogsAndMetrics(t *testing.T) { } deployChartsAndApps(t, valuesFileName, replacements) - waitForLogs(t, 5, agentLogsConsumer) + internal.WaitForLogs(t, 5, agentLogsConsumer) uninstallDeployment(t) - resetLogsSink(t, agentLogsConsumer) - resetMetricsSink(t, hecMetricsConsumer) + internal.ResetLogsSink(t, agentLogsConsumer) + internal.ResetMetricsSink(t, hecMetricsConsumer) }) } @@ -256,9 +251,9 @@ func testIndexSwitch(t *testing.T) { valuesFileName := "values_indexes_switching.yaml.tmpl" hecMetricsConsumer := setupOnce(t).hecMetricsConsumer - checkNoMetricsReceived(t, hecMetricsConsumer) + internal.CheckNoMetricsReceived(t, hecMetricsConsumer) agentLogsConsumer := setupOnce(t).logsConsumer - checkNoEventsReceived(t, agentLogsConsumer) + internal.CheckNoEventsReceived(t, agentLogsConsumer) t.Run("check logs and metrics index switching", func(t *testing.T) { replacements := map[string]interface{}{ @@ -267,8 +262,8 @@ func testIndexSwitch(t *testing.T) { } deployChartsAndApps(t, valuesFileName, replacements) - waitForMetrics(t, 3, hecMetricsConsumer) - waitForLogs(t, 3, agentLogsConsumer) + internal.WaitForMetrics(t, 3, hecMetricsConsumer) + internal.WaitForLogs(t, 3, agentLogsConsumer) var sourcetypes []string var indices []string @@ -291,11 +286,11 @@ func testIndexSwitch(t *testing.T) { "Sourcetype": nonDefaultSourcetype, } deployChartsAndApps(t, valuesFileName, replacements) - resetLogsSink(t, agentLogsConsumer) - resetMetricsSink(t, hecMetricsConsumer) + internal.ResetLogsSink(t, agentLogsConsumer) + internal.ResetMetricsSink(t, hecMetricsConsumer) - waitForMetrics(t, 3, hecMetricsConsumer) - waitForLogs(t, 3, agentLogsConsumer) + internal.WaitForMetrics(t, 3, hecMetricsConsumer) + internal.WaitForLogs(t, 3, agentLogsConsumer) logs = agentLogsConsumer.AllLogs() sourcetypes, indices = getLogsIndexAndSourceType(logs) t.Logf("Indices: %v", indices) @@ -308,15 +303,15 @@ func testIndexSwitch(t *testing.T) { assert.True(t, mIndices[0] == newMetricsIndex) }) uninstallDeployment(t) - resetLogsSink(t, agentLogsConsumer) - resetMetricsSink(t, hecMetricsConsumer) + internal.ResetLogsSink(t, agentLogsConsumer) + internal.ResetMetricsSink(t, hecMetricsConsumer) } func testClusterReceiverEnabledOrDisabled(t *testing.T) { valuesFileName := "values_cluster_receiver_switching.yaml.tmpl" namespace := "default" logsObjectsConsumer := setupOnce(t).logsObjectsConsumer - hostEp := hostEndpoint(t) + hostEp := internal.HostEndpoint(t) if len(hostEp) == 0 { require.Fail(t, "Host endpoint not found") } @@ -332,7 +327,7 @@ func testClusterReceiverEnabledOrDisabled(t *testing.T) { pods = listPodsInNamespace(t, namespace) assert.True(t, len(pods.Items) == 1) assert.True(t, strings.HasPrefix(pods.Items[0].Name, "sock-splunk-otel-collector-agent")) - checkNoEventsReceived(t, logsObjectsConsumer) + internal.CheckNoEventsReceived(t, logsObjectsConsumer) t.Log("cluster receiver enabled") replacements = map[string]interface{}{ @@ -340,22 +335,22 @@ func testClusterReceiverEnabledOrDisabled(t *testing.T) { "LogObjectsHecEndpoint": logsObjectsHecEndpoint, } deployChartsAndApps(t, valuesFileName, replacements) - resetLogsSink(t, logsObjectsConsumer) + internal.ResetLogsSink(t, logsObjectsConsumer) pods = listPodsInNamespace(t, namespace) assert.True(t, len(pods.Items) == 2) assert.True(t, checkPodExists(pods, "sock-splunk-otel-collector-agent")) assert.True(t, checkPodExists(pods, "sock-splunk-otel-collector-k8s-cluster-receiver")) - waitForLogs(t, 5, logsObjectsConsumer) + internal.WaitForLogs(t, 5, logsObjectsConsumer) }) uninstallDeployment(t) - resetLogsSink(t, logsObjectsConsumer) + internal.ResetLogsSink(t, logsObjectsConsumer) } func testVerifyLogsAndMetricsAttributes(t *testing.T) { attributesList := [4]string{"k8s.node.name", "k8s.pod.name", "k8s.pod.uid", "k8s.namespace.name"} - hostEp := hostEndpoint(t) + hostEp := internal.HostEndpoint(t) if len(hostEp) == 0 { require.Fail(t, "Host endpoint not found") } @@ -370,8 +365,8 @@ func testVerifyLogsAndMetricsAttributes(t *testing.T) { "LogObjectsHecEndpoint": logsObjectsHecEndpoint, } deployChartsAndApps(t, valuesFileName, replacements) - resetLogsSink(t, logsObjectsConsumer) - waitForLogs(t, 5, logsObjectsConsumer) + internal.ResetLogsSink(t, logsObjectsConsumer) + internal.WaitForLogs(t, 5, logsObjectsConsumer) t.Logf("===> >>>> Logs: %v", len(logsObjectsConsumer.AllLogs())) for _, attr := range attributesList { @@ -393,10 +388,10 @@ func testVerifyLogsAndMetricsAttributes(t *testing.T) { "LogObjectsHecEndpoint": logsObjectsHecEndpoint, } deployChartsAndApps(t, valuesFileName, replacements) - resetMetricsSink(t, hecMetricsConsumer) + internal.ResetMetricsSink(t, hecMetricsConsumer) t.Logf("===> >>>> Metrics: %d", len(hecMetricsConsumer.AllMetrics())) - waitForMetrics(t, 5, hecMetricsConsumer) + internal.WaitForMetrics(t, 5, hecMetricsConsumer) for _, attr := range attributesList { t.Log("Checking attributes: ", attr) attrValues, notFoundCounter := getMetricsAttributes(hecMetricsConsumer.AllMetrics(), attr) @@ -415,9 +410,9 @@ func testVerifyLogsAndMetricsAttributes(t *testing.T) { "LogsEnabled": true, } deployChartsAndApps(t, valuesFileName, replacements) - resetLogsSink(t, agentLogsConsumer) + internal.ResetLogsSink(t, agentLogsConsumer) - waitForLogs(t, 5, agentLogsConsumer) + internal.WaitForLogs(t, 5, agentLogsConsumer) for _, attr := range attributesList { t.Log("Checking attribute: ", attr) attrValues, notFoundCounter := getLogsAttributes(agentLogsConsumer.AllLogs(), attr) @@ -436,9 +431,9 @@ func testVerifyLogsAndMetricsAttributes(t *testing.T) { "LogsEnabled": true, } deployChartsAndApps(t, valuesFileName, replacements) - resetMetricsSink(t, hecMetricsConsumer) + internal.ResetMetricsSink(t, hecMetricsConsumer) - waitForMetrics(t, 5, hecMetricsConsumer) + internal.WaitForMetrics(t, 5, hecMetricsConsumer) for _, attr := range attributesList { t.Log("Checking attribute: ", attr) attrValues, notFoundCounter := getMetricsAttributes(hecMetricsConsumer.AllMetrics(), attr) diff --git a/functional_tests/testdata_configuration_switching/values/values_cluster_receiver_only.yaml.tmpl b/functional_tests/configuration_switching/testdata/values/values_cluster_receiver_only.yaml.tmpl similarity index 100% rename from functional_tests/testdata_configuration_switching/values/values_cluster_receiver_only.yaml.tmpl rename to functional_tests/configuration_switching/testdata/values/values_cluster_receiver_only.yaml.tmpl diff --git a/functional_tests/testdata_configuration_switching/values/values_cluster_receiver_switching.yaml.tmpl b/functional_tests/configuration_switching/testdata/values/values_cluster_receiver_switching.yaml.tmpl similarity index 100% rename from functional_tests/testdata_configuration_switching/values/values_cluster_receiver_switching.yaml.tmpl rename to functional_tests/configuration_switching/testdata/values/values_cluster_receiver_switching.yaml.tmpl diff --git a/functional_tests/testdata_configuration_switching/values/values_indexes_switching.yaml.tmpl b/functional_tests/configuration_switching/testdata/values/values_indexes_switching.yaml.tmpl similarity index 100% rename from functional_tests/testdata_configuration_switching/values/values_indexes_switching.yaml.tmpl rename to functional_tests/configuration_switching/testdata/values/values_indexes_switching.yaml.tmpl diff --git a/functional_tests/testdata_configuration_switching/values/values_logs_and_metrics_switching.yaml.tmpl b/functional_tests/configuration_switching/testdata/values/values_logs_and_metrics_switching.yaml.tmpl similarity index 100% rename from functional_tests/testdata_configuration_switching/values/values_logs_and_metrics_switching.yaml.tmpl rename to functional_tests/configuration_switching/testdata/values/values_logs_and_metrics_switching.yaml.tmpl diff --git a/functional_tests/functional_test.go b/functional_tests/functional/functional_test.go similarity index 97% rename from functional_tests/functional_test.go rename to functional_tests/functional/functional_test.go index dd89e5d2e..c6e6131e5 100644 --- a/functional_tests/functional_test.go +++ b/functional_tests/functional/functional_test.go @@ -1,9 +1,7 @@ // Copyright Splunk Inc. // SPDX-License-Identifier: Apache-2.0 -//go:build functional - -package functional_tests +package functional import ( "bytes" @@ -34,7 +32,6 @@ import ( "go.opentelemetry.io/collector/receiver/receivertest" "gopkg.in/yaml.v3" "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/kube" appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" @@ -100,12 +97,13 @@ func setupOnce(t *testing.T) *sinks { // set ingest pipelines logs, metrics := setupHEC(t) globalSinks = &sinks{ - logsConsumer: logs, - hecMetricsConsumer: metrics, - logsObjectsConsumer: setupHECLogsObjects(t), - agentMetricsConsumer: setupSignalfxReceiver(t, signalFxReceiverPort), - k8sclusterReceiverMetricsConsumer: setupSignalfxReceiver(t, signalFxReceiverK8sClusterReceiverPort), - tracesConsumer: setupTraces(t), + logsConsumer: logs, + hecMetricsConsumer: metrics, + logsObjectsConsumer: setupHECLogsObjects(t), + agentMetricsConsumer: internal.SetupSignalfxReceiver(t, signalFxReceiverPort), + k8sclusterReceiverMetricsConsumer: internal.SetupSignalfxReceiver(t, + signalFxReceiverK8sClusterReceiverPort), + tracesConsumer: setupTraces(t), } if os.Getenv("TEARDOWN_BEFORE_SETUP") == "true" { teardown(t) @@ -196,9 +194,7 @@ func deployChartsAndApps(t *testing.T) { } }, 1*time.Minute, 5*time.Second) - chartPath := filepath.Join("..", "helm-charts", "splunk-otel-collector") - chart, err := loader.Load(chartPath) - require.NoError(t, err) + chart := internal.LoadCollectorChart(t) var valuesBytes []byte switch kubeTestEnv { @@ -212,7 +208,7 @@ func deployChartsAndApps(t *testing.T) { require.NoError(t, err) - hostEp := hostEndpoint(t) + hostEp := internal.HostEndpoint(t) if len(hostEp) == 0 { require.Fail(t, "Host endpoint not found") } @@ -573,7 +569,7 @@ func testNodeJSTraces(t *testing.T) { expectedTraces, err := golden.ReadTraces(expectedTracesFile) require.NoError(t, err) - waitForTraces(t, 10, tracesConsumer) + internal.WaitForTraces(t, 10, tracesConsumer) var selectedTrace *ptrace.Traces @@ -627,7 +623,7 @@ func testNodeJSTraces(t *testing.T) { ptracetest.IgnoreScopeSpansOrder(), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedTracesResult(t, expectedTracesFile, selectedTrace) + internal.WriteNewExpectedTracesResult(t, expectedTracesFile, selectedTrace) } require.NoError(t, err) } @@ -640,7 +636,7 @@ func testPythonTraces(t *testing.T) { expectedTraces, err := golden.ReadTraces(expectedTracesFile) require.NoError(t, err) - waitForTraces(t, 10, tracesConsumer) + internal.WaitForTraces(t, 10, tracesConsumer) var selectedTrace *ptrace.Traces @@ -696,7 +692,7 @@ func testPythonTraces(t *testing.T) { ptracetest.IgnoreScopeSpansOrder(), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedTracesResult(t, expectedTracesFile, selectedTrace) + internal.WriteNewExpectedTracesResult(t, expectedTracesFile, selectedTrace) } require.NoError(t, err) } @@ -709,7 +705,7 @@ func testJavaTraces(t *testing.T) { expectedTraces, err := golden.ReadTraces(expectedTracesFile) require.NoError(t, err) - waitForTraces(t, 10, tracesConsumer) + internal.WaitForTraces(t, 10, tracesConsumer) var selectedTrace *ptrace.Traces @@ -760,7 +756,7 @@ func testJavaTraces(t *testing.T) { ptracetest.IgnoreScopeSpansOrder(), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedTracesResult(t, expectedTracesFile, selectedTrace) + internal.WriteNewExpectedTracesResult(t, expectedTracesFile, selectedTrace) } require.NoError(t, err) } @@ -773,7 +769,7 @@ func testDotNetTraces(t *testing.T) { expectedTraces, err := golden.ReadTraces(expectedTracesFile) require.NoError(t, err) - waitForTraces(t, 30, tracesConsumer) + internal.WaitForTraces(t, 30, tracesConsumer) var selectedTrace *ptrace.Traces require.Eventually(t, func() bool { @@ -825,7 +821,7 @@ func testDotNetTraces(t *testing.T) { ptracetest.IgnoreScopeSpansOrder(), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedTracesResult(t, expectedTracesFile, selectedTrace) + internal.WriteNewExpectedTracesResult(t, expectedTracesFile, selectedTrace) } require.NoError(t, err) } @@ -949,7 +945,7 @@ func testK8sClusterReceiverMetrics(t *testing.T) { pmetrictest.IgnoreSubsequentDataPoints("k8s.container.ready", "k8s.container.restarts", "k8s.pod.phase"), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedMetricsFile, selectedMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedMetricsFile, selectedMetrics) } require.NoError(t, err) } @@ -957,7 +953,7 @@ func testK8sClusterReceiverMetrics(t *testing.T) { func testAgentLogs(t *testing.T) { logsConsumer := setupOnce(t).logsConsumer - waitForLogs(t, 5, logsConsumer) + internal.WaitForLogs(t, 5, logsConsumer) var helloWorldResource pcommon.Resource var helloWorldLogRecord *plog.LogRecord @@ -1066,7 +1062,7 @@ func testAgentLogs(t *testing.T) { func testK8sObjects(t *testing.T) { logsObjectsConsumer := setupOnce(t).logsObjectsConsumer - waitForLogs(t, 5, logsObjectsConsumer) + internal.WaitForLogs(t, 5, logsObjectsConsumer) var kinds []string var sourceTypes []string @@ -1225,7 +1221,7 @@ func testAgentMetrics(t *testing.T) { pmetrictest.IgnoreSubsequentDataPoints("otelcol_receiver_accepted_log_records", "otelcol_receiver_refused_log_records"), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedInternalMetricsFile, selectedInternalMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedInternalMetricsFile, selectedInternalMetrics) } assert.NoError(t, err) @@ -1279,7 +1275,7 @@ func testAgentMetrics(t *testing.T) { pmetrictest.IgnoreMetricDataPointsOrder(), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedKubeletStatsMetricsFile, selectedKubeletstatsMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedKubeletStatsMetricsFile, selectedKubeletstatsMetrics) } assert.NoError(t, err) } diff --git a/functional_tests/testdata/dotnet/Dockerfile b/functional_tests/functional/testdata/dotnet/Dockerfile similarity index 100% rename from functional_tests/testdata/dotnet/Dockerfile rename to functional_tests/functional/testdata/dotnet/Dockerfile diff --git a/functional_tests/testdata/dotnet/DotNetTestApp.csproj b/functional_tests/functional/testdata/dotnet/DotNetTestApp.csproj similarity index 100% rename from functional_tests/testdata/dotnet/DotNetTestApp.csproj rename to functional_tests/functional/testdata/dotnet/DotNetTestApp.csproj diff --git a/functional_tests/testdata/dotnet/Makefile b/functional_tests/functional/testdata/dotnet/Makefile similarity index 100% rename from functional_tests/testdata/dotnet/Makefile rename to functional_tests/functional/testdata/dotnet/Makefile diff --git a/functional_tests/testdata/dotnet/Program.cs b/functional_tests/functional/testdata/dotnet/Program.cs similarity index 100% rename from functional_tests/testdata/dotnet/Program.cs rename to functional_tests/functional/testdata/dotnet/Program.cs diff --git a/functional_tests/testdata/dotnet/README.md b/functional_tests/functional/testdata/dotnet/README.md similarity index 100% rename from functional_tests/testdata/dotnet/README.md rename to functional_tests/functional/testdata/dotnet/README.md diff --git a/functional_tests/testdata/dotnet/Startup.cs b/functional_tests/functional/testdata/dotnet/Startup.cs similarity index 100% rename from functional_tests/testdata/dotnet/Startup.cs rename to functional_tests/functional/testdata/dotnet/Startup.cs diff --git a/functional_tests/testdata/dotnet/deployment.yaml b/functional_tests/functional/testdata/dotnet/deployment.yaml similarity index 100% rename from functional_tests/testdata/dotnet/deployment.yaml rename to functional_tests/functional/testdata/dotnet/deployment.yaml diff --git a/functional_tests/testdata/expected_eks_values/expected_cluster_receiver.yaml b/functional_tests/functional/testdata/expected_eks_values/expected_cluster_receiver.yaml similarity index 100% rename from functional_tests/testdata/expected_eks_values/expected_cluster_receiver.yaml rename to functional_tests/functional/testdata/expected_eks_values/expected_cluster_receiver.yaml diff --git a/functional_tests/testdata/expected_eks_values/expected_dotnet_traces.yaml b/functional_tests/functional/testdata/expected_eks_values/expected_dotnet_traces.yaml similarity index 100% rename from functional_tests/testdata/expected_eks_values/expected_dotnet_traces.yaml rename to functional_tests/functional/testdata/expected_eks_values/expected_dotnet_traces.yaml diff --git a/functional_tests/testdata/expected_eks_values/expected_internal_metrics.yaml b/functional_tests/functional/testdata/expected_eks_values/expected_internal_metrics.yaml similarity index 100% rename from functional_tests/testdata/expected_eks_values/expected_internal_metrics.yaml rename to functional_tests/functional/testdata/expected_eks_values/expected_internal_metrics.yaml diff --git a/functional_tests/testdata/expected_eks_values/expected_java_traces.yaml b/functional_tests/functional/testdata/expected_eks_values/expected_java_traces.yaml similarity index 100% rename from functional_tests/testdata/expected_eks_values/expected_java_traces.yaml rename to functional_tests/functional/testdata/expected_eks_values/expected_java_traces.yaml diff --git a/functional_tests/testdata/expected_eks_values/expected_kubeletstats_metrics.yaml b/functional_tests/functional/testdata/expected_eks_values/expected_kubeletstats_metrics.yaml similarity index 100% rename from functional_tests/testdata/expected_eks_values/expected_kubeletstats_metrics.yaml rename to functional_tests/functional/testdata/expected_eks_values/expected_kubeletstats_metrics.yaml diff --git a/functional_tests/testdata/expected_eks_values/expected_nodejs_traces.yaml b/functional_tests/functional/testdata/expected_eks_values/expected_nodejs_traces.yaml similarity index 100% rename from functional_tests/testdata/expected_eks_values/expected_nodejs_traces.yaml rename to functional_tests/functional/testdata/expected_eks_values/expected_nodejs_traces.yaml diff --git a/functional_tests/testdata/expected_eks_values/expected_python_traces.yaml b/functional_tests/functional/testdata/expected_eks_values/expected_python_traces.yaml similarity index 100% rename from functional_tests/testdata/expected_eks_values/expected_python_traces.yaml rename to functional_tests/functional/testdata/expected_eks_values/expected_python_traces.yaml diff --git a/functional_tests/testdata/expected_kind_values/expected_cluster_receiver.yaml b/functional_tests/functional/testdata/expected_kind_values/expected_cluster_receiver.yaml similarity index 100% rename from functional_tests/testdata/expected_kind_values/expected_cluster_receiver.yaml rename to functional_tests/functional/testdata/expected_kind_values/expected_cluster_receiver.yaml diff --git a/functional_tests/testdata/expected_kind_values/expected_dotnet_traces.yaml b/functional_tests/functional/testdata/expected_kind_values/expected_dotnet_traces.yaml similarity index 100% rename from functional_tests/testdata/expected_kind_values/expected_dotnet_traces.yaml rename to functional_tests/functional/testdata/expected_kind_values/expected_dotnet_traces.yaml diff --git a/functional_tests/testdata/expected_kind_values/expected_internal_metrics.yaml b/functional_tests/functional/testdata/expected_kind_values/expected_internal_metrics.yaml similarity index 100% rename from functional_tests/testdata/expected_kind_values/expected_internal_metrics.yaml rename to functional_tests/functional/testdata/expected_kind_values/expected_internal_metrics.yaml diff --git a/functional_tests/testdata/expected_kind_values/expected_java_traces.yaml b/functional_tests/functional/testdata/expected_kind_values/expected_java_traces.yaml similarity index 100% rename from functional_tests/testdata/expected_kind_values/expected_java_traces.yaml rename to functional_tests/functional/testdata/expected_kind_values/expected_java_traces.yaml diff --git a/functional_tests/testdata/expected_kind_values/expected_kubeletstats_metrics.yaml b/functional_tests/functional/testdata/expected_kind_values/expected_kubeletstats_metrics.yaml similarity index 100% rename from functional_tests/testdata/expected_kind_values/expected_kubeletstats_metrics.yaml rename to functional_tests/functional/testdata/expected_kind_values/expected_kubeletstats_metrics.yaml diff --git a/functional_tests/testdata/expected_kind_values/expected_nodejs_traces.yaml b/functional_tests/functional/testdata/expected_kind_values/expected_nodejs_traces.yaml similarity index 100% rename from functional_tests/testdata/expected_kind_values/expected_nodejs_traces.yaml rename to functional_tests/functional/testdata/expected_kind_values/expected_nodejs_traces.yaml diff --git a/functional_tests/testdata/expected_kind_values/expected_python_traces.yaml b/functional_tests/functional/testdata/expected_kind_values/expected_python_traces.yaml similarity index 100% rename from functional_tests/testdata/expected_kind_values/expected_python_traces.yaml rename to functional_tests/functional/testdata/expected_kind_values/expected_python_traces.yaml diff --git a/functional_tests/testdata/java/Dockerfile b/functional_tests/functional/testdata/java/Dockerfile similarity index 100% rename from functional_tests/testdata/java/Dockerfile rename to functional_tests/functional/testdata/java/Dockerfile diff --git a/functional_tests/testdata/java/Makefile b/functional_tests/functional/testdata/java/Makefile similarity index 100% rename from functional_tests/testdata/java/Makefile rename to functional_tests/functional/testdata/java/Makefile diff --git a/functional_tests/testdata/java/README.md b/functional_tests/functional/testdata/java/README.md similarity index 100% rename from functional_tests/testdata/java/README.md rename to functional_tests/functional/testdata/java/README.md diff --git a/functional_tests/testdata/java/deployment.yaml b/functional_tests/functional/testdata/java/deployment.yaml similarity index 100% rename from functional_tests/testdata/java/deployment.yaml rename to functional_tests/functional/testdata/java/deployment.yaml diff --git a/functional_tests/testdata/java/start.sh b/functional_tests/functional/testdata/java/start.sh similarity index 100% rename from functional_tests/testdata/java/start.sh rename to functional_tests/functional/testdata/java/start.sh diff --git a/functional_tests/testdata/manifests/deployment_with_prometheus_annotations.yaml b/functional_tests/functional/testdata/manifests/deployment_with_prometheus_annotations.yaml similarity index 100% rename from functional_tests/testdata/manifests/deployment_with_prometheus_annotations.yaml rename to functional_tests/functional/testdata/manifests/deployment_with_prometheus_annotations.yaml diff --git a/functional_tests/testdata/manifests/operator_crds.yaml b/functional_tests/functional/testdata/manifests/operator_crds.yaml similarity index 100% rename from functional_tests/testdata/manifests/operator_crds.yaml rename to functional_tests/functional/testdata/manifests/operator_crds.yaml diff --git a/functional_tests/testdata/manifests/pod_monitor.yaml b/functional_tests/functional/testdata/manifests/pod_monitor.yaml similarity index 100% rename from functional_tests/testdata/manifests/pod_monitor.yaml rename to functional_tests/functional/testdata/manifests/pod_monitor.yaml diff --git a/functional_tests/testdata/manifests/prometheus_operator_crds.yaml b/functional_tests/functional/testdata/manifests/prometheus_operator_crds.yaml similarity index 100% rename from functional_tests/testdata/manifests/prometheus_operator_crds.yaml rename to functional_tests/functional/testdata/manifests/prometheus_operator_crds.yaml diff --git a/functional_tests/testdata/manifests/service.yaml b/functional_tests/functional/testdata/manifests/service.yaml similarity index 100% rename from functional_tests/testdata/manifests/service.yaml rename to functional_tests/functional/testdata/manifests/service.yaml diff --git a/functional_tests/testdata/manifests/service_monitor.yaml b/functional_tests/functional/testdata/manifests/service_monitor.yaml similarity index 100% rename from functional_tests/testdata/manifests/service_monitor.yaml rename to functional_tests/functional/testdata/manifests/service_monitor.yaml diff --git a/functional_tests/testdata/manifests/test_jobs.yaml b/functional_tests/functional/testdata/manifests/test_jobs.yaml similarity index 100% rename from functional_tests/testdata/manifests/test_jobs.yaml rename to functional_tests/functional/testdata/manifests/test_jobs.yaml diff --git a/functional_tests/testdata/nodejs/Dockerfile b/functional_tests/functional/testdata/nodejs/Dockerfile similarity index 100% rename from functional_tests/testdata/nodejs/Dockerfile rename to functional_tests/functional/testdata/nodejs/Dockerfile diff --git a/functional_tests/testdata/nodejs/Makefile b/functional_tests/functional/testdata/nodejs/Makefile similarity index 100% rename from functional_tests/testdata/nodejs/Makefile rename to functional_tests/functional/testdata/nodejs/Makefile diff --git a/functional_tests/testdata/nodejs/README.md b/functional_tests/functional/testdata/nodejs/README.md similarity index 100% rename from functional_tests/testdata/nodejs/README.md rename to functional_tests/functional/testdata/nodejs/README.md diff --git a/functional_tests/testdata/nodejs/deployment.yaml b/functional_tests/functional/testdata/nodejs/deployment.yaml similarity index 100% rename from functional_tests/testdata/nodejs/deployment.yaml rename to functional_tests/functional/testdata/nodejs/deployment.yaml diff --git a/functional_tests/testdata/nodejs/index.js b/functional_tests/functional/testdata/nodejs/index.js similarity index 100% rename from functional_tests/testdata/nodejs/index.js rename to functional_tests/functional/testdata/nodejs/index.js diff --git a/functional_tests/testdata/nodejs/start.sh b/functional_tests/functional/testdata/nodejs/start.sh similarity index 100% rename from functional_tests/testdata/nodejs/start.sh rename to functional_tests/functional/testdata/nodejs/start.sh diff --git a/functional_tests/testdata/python/Dockerfile b/functional_tests/functional/testdata/python/Dockerfile similarity index 100% rename from functional_tests/testdata/python/Dockerfile rename to functional_tests/functional/testdata/python/Dockerfile diff --git a/functional_tests/testdata/python/Makefile b/functional_tests/functional/testdata/python/Makefile similarity index 100% rename from functional_tests/testdata/python/Makefile rename to functional_tests/functional/testdata/python/Makefile diff --git a/functional_tests/testdata/python/README.md b/functional_tests/functional/testdata/python/README.md similarity index 100% rename from functional_tests/testdata/python/README.md rename to functional_tests/functional/testdata/python/README.md diff --git a/functional_tests/testdata/python/deployment.yaml b/functional_tests/functional/testdata/python/deployment.yaml similarity index 100% rename from functional_tests/testdata/python/deployment.yaml rename to functional_tests/functional/testdata/python/deployment.yaml diff --git a/functional_tests/testdata/python/start.sh b/functional_tests/functional/testdata/python/start.sh similarity index 100% rename from functional_tests/testdata/python/start.sh rename to functional_tests/functional/testdata/python/start.sh diff --git a/functional_tests/testdata/python/web.py b/functional_tests/functional/testdata/python/web.py similarity index 100% rename from functional_tests/testdata/python/web.py rename to functional_tests/functional/testdata/python/web.py diff --git a/functional_tests/testdata/values/aks_test_values.yaml.tmpl b/functional_tests/functional/testdata/values/aks_test_values.yaml.tmpl similarity index 100% rename from functional_tests/testdata/values/aks_test_values.yaml.tmpl rename to functional_tests/functional/testdata/values/aks_test_values.yaml.tmpl diff --git a/functional_tests/testdata/values/autopilot_test_values.yaml.tmpl b/functional_tests/functional/testdata/values/autopilot_test_values.yaml.tmpl similarity index 100% rename from functional_tests/testdata/values/autopilot_test_values.yaml.tmpl rename to functional_tests/functional/testdata/values/autopilot_test_values.yaml.tmpl diff --git a/functional_tests/testdata/values/test_values.yaml.tmpl b/functional_tests/functional/testdata/values/test_values.yaml.tmpl similarity index 100% rename from functional_tests/testdata/values/test_values.yaml.tmpl rename to functional_tests/functional/testdata/values/test_values.yaml.tmpl diff --git a/functional_tests/histogram_test.go b/functional_tests/histogram/histogram_test.go similarity index 94% rename from functional_tests/histogram_test.go rename to functional_tests/histogram/histogram_test.go index 3a5647464..533813c1c 100644 --- a/functional_tests/histogram_test.go +++ b/functional_tests/histogram/histogram_test.go @@ -1,17 +1,12 @@ // Copyright Splunk Inc. // SPDX-License-Identifier: Apache-2.0 -//go:build histogram - -package functional_tests +package histogram import ( "bytes" "context" "fmt" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" - "go.opentelemetry.io/collector/pdata/pmetric" "os" "path/filepath" "strings" @@ -20,16 +15,20 @@ import ( "text/template" "time" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/receivertest" "gopkg.in/yaml.v3" "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/kube" + + "github.com/signalfx/splunk-otel-collector-chart/functional_tests/internal" ) const ( @@ -82,14 +81,12 @@ func deployChartsAndApps(t *testing.T) { testKubeConfig, setKubeConfig := os.LookupEnv("KUBECONFIG") require.True(t, setKubeConfig, "the environment variable KUBECONFIG must be set") - chartPath := filepath.Join("..", "helm-charts", "splunk-otel-collector") - chart, err := loader.Load(chartPath) - require.NoError(t, err) + chart := internal.LoadCollectorChart(t) - valuesBytes, err := os.ReadFile(filepath.Join("testdata_histogram", valuesDir, "test_values.yaml.tmpl")) + valuesBytes, err := os.ReadFile(filepath.Join("testdata", valuesDir, "test_values.yaml.tmpl")) require.NoError(t, err) - hostEp := hostEndpoint(t) + hostEp := internal.HostEndpoint(t) if len(hostEp) == 0 { require.Fail(t, "Host endpoint not found") } @@ -158,10 +155,10 @@ func testHistogramMetrics(t *testing.T) { k8sVersion := os.Getenv("K8S_VERSION") majorMinor := k8sVersion[0:strings.LastIndex(k8sVersion, ".")] - testDir := filepath.Join("testdata_histogram", "expected", majorMinor) + testDir := filepath.Join("testdata", "expected", majorMinor) otlpMetricsSink := setupOnce(t) - waitForMetrics(t, 5, otlpMetricsSink) + internal.WaitForMetrics(t, 5, otlpMetricsSink) expectedKubeSchedulerMetricsFile := filepath.Join(testDir, "scheduler_metrics.yaml") expectedKubeSchedulerMetrics, err := golden.ReadMetrics(expectedKubeSchedulerMetricsFile) @@ -266,7 +263,7 @@ func testHistogramMetrics(t *testing.T) { ) assert.NoError(t, err) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedCoreDNSMetricsFile, corednsMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedCoreDNSMetricsFile, corednsMetrics) } err = pmetrictest.CompareMetrics(expectedKubeSchedulerMetrics, *schedulerMetrics, @@ -295,7 +292,7 @@ func testHistogramMetrics(t *testing.T) { ) assert.NoError(t, err) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedKubeSchedulerMetricsFile, etcdMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedKubeSchedulerMetricsFile, etcdMetrics) } err = pmetrictest.CompareMetrics(expectedKubeProxyMetrics, *kubeProxyMetrics, @@ -324,7 +321,7 @@ func testHistogramMetrics(t *testing.T) { ) assert.NoError(t, err) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedKubeProxyMetricsFile, &expectedKubeProxyMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedKubeProxyMetricsFile, &expectedKubeProxyMetrics) } err = pmetrictest.CompareMetrics(expectedApiMetrics, *apiMetrics, @@ -345,7 +342,7 @@ func testHistogramMetrics(t *testing.T) { ) assert.NoError(t, err) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedApiMetricsFile, apiMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedApiMetricsFile, apiMetrics) } err = pmetrictest.CompareMetrics(expectedControllerManagerMetrics, *controllerManagerMetrics, @@ -374,7 +371,7 @@ func testHistogramMetrics(t *testing.T) { ) assert.NoError(t, err) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedControllerManagerMetricsFile, controllerManagerMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedControllerManagerMetricsFile, controllerManagerMetrics) } err = pmetrictest.CompareMetrics(expectedEtcdMetrics, *etcdMetrics, @@ -405,6 +402,6 @@ func testHistogramMetrics(t *testing.T) { ) assert.NoError(t, err) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedEtcdMetricsFile, etcdMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedEtcdMetricsFile, etcdMetrics) } } diff --git a/functional_tests/testdata_histogram/expected/v1.25/api_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.25/api_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.25/api_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.25/api_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.25/controller_manager_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.25/controller_manager_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.25/controller_manager_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.25/controller_manager_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.25/coredns_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.25/coredns_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.25/coredns_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.25/coredns_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.25/etcd_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.25/etcd_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.25/etcd_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.25/etcd_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.25/proxy_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.25/proxy_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.25/proxy_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.25/proxy_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.25/scheduler_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.25/scheduler_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.25/scheduler_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.25/scheduler_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.26/api_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.26/api_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.26/api_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.26/api_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.26/controller_manager_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.26/controller_manager_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.26/controller_manager_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.26/controller_manager_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.26/coredns_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.26/coredns_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.26/coredns_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.26/coredns_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.26/etcd_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.26/etcd_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.26/etcd_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.26/etcd_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.26/proxy_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.26/proxy_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.26/proxy_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.26/proxy_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.26/scheduler_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.26/scheduler_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.26/scheduler_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.26/scheduler_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.27/api_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.27/api_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.27/api_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.27/api_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.27/controller_manager_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.27/controller_manager_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.27/controller_manager_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.27/controller_manager_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.27/coredns_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.27/coredns_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.27/coredns_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.27/coredns_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.27/etcd_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.27/etcd_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.27/etcd_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.27/etcd_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.27/proxy_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.27/proxy_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.27/proxy_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.27/proxy_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.27/scheduler_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.27/scheduler_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.27/scheduler_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.27/scheduler_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.28/api_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.28/api_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.28/api_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.28/api_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.28/controller_manager_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.28/controller_manager_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.28/controller_manager_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.28/controller_manager_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.28/coredns_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.28/coredns_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.28/coredns_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.28/coredns_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.28/etcd_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.28/etcd_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.28/etcd_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.28/etcd_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.28/proxy_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.28/proxy_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.28/proxy_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.28/proxy_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.28/scheduler_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.28/scheduler_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.28/scheduler_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.28/scheduler_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.29/api_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.29/api_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.29/api_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.29/api_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.29/controller_manager_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.29/controller_manager_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.29/controller_manager_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.29/controller_manager_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.29/coredns_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.29/coredns_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.29/coredns_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.29/coredns_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.29/etcd_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.29/etcd_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.29/etcd_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.29/etcd_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.29/proxy_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.29/proxy_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.29/proxy_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.29/proxy_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.29/scheduler_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.29/scheduler_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.29/scheduler_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.29/scheduler_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.30/api_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.30/api_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.30/api_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.30/api_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.30/controller_manager_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.30/controller_manager_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.30/controller_manager_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.30/controller_manager_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.30/coredns_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.30/coredns_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.30/coredns_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.30/coredns_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.30/etcd_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.30/etcd_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.30/etcd_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.30/etcd_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.30/proxy_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.30/proxy_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.30/proxy_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.30/proxy_metrics.yaml diff --git a/functional_tests/testdata_histogram/expected/v1.30/scheduler_metrics.yaml b/functional_tests/histogram/testdata/expected/v1.30/scheduler_metrics.yaml similarity index 100% rename from functional_tests/testdata_histogram/expected/v1.30/scheduler_metrics.yaml rename to functional_tests/histogram/testdata/expected/v1.30/scheduler_metrics.yaml diff --git a/functional_tests/testdata_histogram/values/test_values.yaml.tmpl b/functional_tests/histogram/testdata/values/test_values.yaml.tmpl similarity index 100% rename from functional_tests/testdata_histogram/values/test_values.yaml.tmpl rename to functional_tests/histogram/testdata/values/test_values.yaml.tmpl diff --git a/functional_tests/internal/api_server.go b/functional_tests/internal/api_server.go index 51dd08480..d87fb2f6a 100644 --- a/functional_tests/internal/api_server.go +++ b/functional_tests/internal/api_server.go @@ -1,3 +1,6 @@ +// Copyright Splunk Inc. +// SPDX-License-Identifier: Apache-2.0 + package internal import ( diff --git a/functional_tests/common.go b/functional_tests/internal/common.go similarity index 80% rename from functional_tests/common.go rename to functional_tests/internal/common.go index e688a352c..0c7a70760 100644 --- a/functional_tests/common.go +++ b/functional_tests/internal/common.go @@ -1,11 +1,17 @@ // Copyright Splunk Inc. // SPDX-License-Identifier: Apache-2.0 -package functional_tests +package internal import ( "context" "fmt" + "os" + "path/filepath" + "runtime" + "testing" + "time" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver" "go.opentelemetry.io/collector/component/componenttest" @@ -14,14 +20,11 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/collector/receiver/receivertest" + "helm.sh/helm/v3/pkg/chart" + "helm.sh/helm/v3/pkg/chart/loader" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "os" - "path/filepath" - "runtime" - "testing" - "time" "github.com/docker/docker/api/types" docker "github.com/docker/docker/client" @@ -29,7 +32,7 @@ import ( "github.com/stretchr/testify/require" ) -func hostEndpoint(t *testing.T) string { +func HostEndpoint(t *testing.T) string { if host, ok := os.LookupEnv("HOST_ENDPOINT"); ok { return host } @@ -53,7 +56,7 @@ func hostEndpoint(t *testing.T) string { return "" } -func waitForTraces(t *testing.T, entriesNum int, tc *consumertest.TracesSink) { +func WaitForTraces(t *testing.T, entriesNum int, tc *consumertest.TracesSink) { timeoutMinutes := 3 require.Eventuallyf(t, func() bool { return len(tc.AllTraces()) > entriesNum @@ -62,7 +65,7 @@ func waitForTraces(t *testing.T, entriesNum int, tc *consumertest.TracesSink) { len(tc.AllTraces()), timeoutMinutes) } -func waitForLogs(t *testing.T, entriesNum int, lc *consumertest.LogsSink) { +func WaitForLogs(t *testing.T, entriesNum int, lc *consumertest.LogsSink) { timeoutMinutes := 3 require.Eventuallyf(t, func() bool { return len(lc.AllLogs()) > entriesNum @@ -71,7 +74,7 @@ func waitForLogs(t *testing.T, entriesNum int, lc *consumertest.LogsSink) { len(lc.AllLogs()), timeoutMinutes) } -func waitForMetrics(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { +func WaitForMetrics(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) { timeoutMinutes := 3 require.Eventuallyf(t, func() bool { return len(mc.AllMetrics()) > entriesNum @@ -80,42 +83,42 @@ func waitForMetrics(t *testing.T, entriesNum int, mc *consumertest.MetricsSink) len(mc.AllMetrics()), timeoutMinutes) } -func checkNoEventsReceived(t *testing.T, lc *consumertest.LogsSink) { +func CheckNoEventsReceived(t *testing.T, lc *consumertest.LogsSink) { require.True(t, len(lc.AllLogs()) == 0, "received %d logs, expected 0 logs", len(lc.AllLogs())) } -func checkNoMetricsReceived(t *testing.T, lc *consumertest.MetricsSink) { +func CheckNoMetricsReceived(t *testing.T, lc *consumertest.MetricsSink) { require.True(t, len(lc.AllMetrics()) == 0, "received %d metrics, expected 0 metrics", len(lc.AllMetrics())) } -func resetMetricsSink(t *testing.T, mc *consumertest.MetricsSink) { +func ResetMetricsSink(t *testing.T, mc *consumertest.MetricsSink) { mc.Reset() t.Logf("Metrics sink reset, current metrics: %d", len(mc.AllMetrics())) } -func resetLogsSink(t *testing.T, lc *consumertest.LogsSink) { +func ResetLogsSink(t *testing.T, lc *consumertest.LogsSink) { lc.Reset() t.Logf("Logs sink reset, current logs: %d", len(lc.AllLogs())) } -func writeNewExpectedTracesResult(t *testing.T, file string, trace *ptrace.Traces) { +func WriteNewExpectedTracesResult(t *testing.T, file string, trace *ptrace.Traces) { require.NoError(t, os.MkdirAll("results", 0755)) require.NoError(t, golden.WriteTraces(t, filepath.Join("results", filepath.Base(file)), *trace)) } -func writeNewExpectedMetricsResult(t *testing.T, file string, metric *pmetric.Metrics) { +func WriteNewExpectedMetricsResult(t *testing.T, file string, metric *pmetric.Metrics) { require.NoError(t, os.MkdirAll("results", 0755)) require.NoError(t, golden.WriteMetrics(t, filepath.Join("results", filepath.Base(file)), *metric)) } -func writeNewExpectedLogsResult(t *testing.T, file string, log *plog.Logs) { +func WriteNewExpectedLogsResult(t *testing.T, file string, log *plog.Logs) { require.NoError(t, os.MkdirAll("results", 0755)) require.NoError(t, golden.WriteLogs(t, filepath.Join("results", filepath.Base(file)), *log)) } -func setupSignalfxReceiver(t *testing.T, port int) *consumertest.MetricsSink { +func SetupSignalfxReceiver(t *testing.T, port int) *consumertest.MetricsSink { mc := new(consumertest.MetricsSink) f := signalfxreceiver.NewFactory() cfg := f.CreateDefaultConfig().(*signalfxreceiver.Config) @@ -133,7 +136,8 @@ func setupSignalfxReceiver(t *testing.T, port int) *consumertest.MetricsSink { return mc } -func checkPodsReady(t *testing.T, clientset *kubernetes.Clientset, namespace, labelSelector string, timeout time.Duration) { +func CheckPodsReady(t *testing.T, clientset *kubernetes.Clientset, namespace, labelSelector string, + timeout time.Duration) { require.Eventually(t, func() bool { pods, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{ LabelSelector: labelSelector, @@ -161,7 +165,7 @@ func checkPodsReady(t *testing.T, clientset *kubernetes.Clientset, namespace, la }, timeout, 5*time.Second, "Pods in namespace %s with label %s are not ready", namespace, labelSelector) } -func createNamespace(t *testing.T, clientset *kubernetes.Clientset, name string) { +func CreateNamespace(t *testing.T, clientset *kubernetes.Clientset, name string) { ns := &v1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -176,7 +180,7 @@ func createNamespace(t *testing.T, clientset *kubernetes.Clientset, name string) }, 1*time.Minute, 5*time.Second, "namespace %s is not available", name) } -func labelNamespace(t *testing.T, clientset *kubernetes.Clientset, name, key, value string) { +func LabelNamespace(t *testing.T, clientset *kubernetes.Clientset, name, key, value string) { ns, err := clientset.CoreV1().Namespaces().Get(context.TODO(), name, metav1.GetOptions{}) require.NoError(t, err) if ns.Labels == nil { @@ -186,3 +190,10 @@ func labelNamespace(t *testing.T, clientset *kubernetes.Clientset, name, key, va _, err = clientset.CoreV1().Namespaces().Update(context.TODO(), ns, metav1.UpdateOptions{}) require.NoError(t, err) } + +func LoadCollectorChart(t *testing.T) *chart.Chart { + chartPath := filepath.Join("..", "..", "helm-charts", "splunk-otel-collector") + c, err := loader.Load(chartPath) + require.NoError(t, err) + return c +} diff --git a/functional_tests/istio_test.go b/functional_tests/istio/istio_test.go similarity index 93% rename from functional_tests/istio_test.go rename to functional_tests/istio/istio_test.go index 0ec4b2d4a..69bf29dcf 100644 --- a/functional_tests/istio_test.go +++ b/functional_tests/istio/istio_test.go @@ -1,8 +1,7 @@ // Copyright Splunk Inc. // SPDX-License-Identifier: Apache-2.0 -//go:build istio -package functional_tests +package istio import ( "archive/tar" @@ -29,7 +28,6 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pdata/pmetric" "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/kube" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -75,7 +73,7 @@ func setupOnce(t *testing.T) *consumertest.MetricsSink { // create an API server internal.CreateApiServer(t, apiPort) - istioMetricsConsumer = setupSignalfxReceiver(t, signalFxReceiverPort) + istioMetricsConsumer = internal.SetupSignalfxReceiver(t, signalFxReceiverPort) if os.Getenv("SKIP_SETUP") == "true" { t.Log("Skipping setup as SKIP_SETUP is set to true") @@ -104,33 +102,31 @@ func deployIstioAndCollector(t *testing.T) { patchResource(t, clientset, "istio-system", "istio-ingressgateway", "deployments", `{"spec":{"template":{"spec":{"containers":[{"name":"istio-proxy","ports":[{"containerPort":8080,"hostPort":80},{"containerPort":8443,"hostPort":443}]}]}}}}`) patchResource(t, clientset, "istio-system", "istio-ingressgateway", "services", `{"spec": {"type": "ClusterIP"}}`) - createNamespace(t, clientset, "istio-workloads") - labelNamespace(t, clientset, "istio-workloads", "istio-injection", "enabled") + internal.CreateNamespace(t, clientset, "istio-workloads") + internal.LabelNamespace(t, clientset, "istio-workloads", "istio-injection", "enabled") k8sClient, err := k8stest.NewK8sClient(testKubeConfig) require.NoError(t, err) - _, err = k8stest.CreateObjects(k8sClient, "testdata_istio/testobjects") + _, err = k8stest.CreateObjects(k8sClient, "testdata/testobjects") require.NoError(t, err) deployment, err := clientset.AppsV1().Deployments("istio-workloads").Get(context.TODO(), "httpbin", metav1.GetOptions{}) require.NoError(t, err, "failed to get httpbin deployment") t.Logf("Deployment %s created successfully", deployment.Name) - checkPodsReady(t, clientset, "istio-system", "app=istio-ingressgateway", 5*time.Minute) - checkPodsReady(t, clientset, "istio-system", "app=istiod", 2*time.Minute) - checkPodsReady(t, clientset, "istio-workloads", "app=httpbin", 3*time.Minute) + internal.CheckPodsReady(t, clientset, "istio-system", "app=istio-ingressgateway", 5*time.Minute) + internal.CheckPodsReady(t, clientset, "istio-system", "app=istiod", 2*time.Minute) + internal.CheckPodsReady(t, clientset, "istio-workloads", "app=httpbin", 3*time.Minute) // Send traffic through ingress gateways sendWorkloadHTTPRequests(t) - chartPath := filepath.Join("..", "helm-charts", "splunk-otel-collector") - chart, err := loader.Load(chartPath) - require.NoError(t, err) + chart := internal.LoadCollectorChart(t) - valuesBytes, err := os.ReadFile(filepath.Join("testdata_istio", "istio_values.yaml.tmpl")) + valuesBytes, err := os.ReadFile(filepath.Join("testdata", "istio_values.yaml.tmpl")) require.NoError(t, err) - hostEp := hostEndpoint(t) + hostEp := internal.HostEndpoint(t) if len(hostEp) == 0 { require.Fail(t, "Host endpoint not found") } @@ -387,12 +383,12 @@ func Test_IstioMetrics(t *testing.T) { flakyMetrics := []string{"galley_validation_config_update_error"} // only shows up when config validation fails - removed if present when comparing t.Run("istiod metrics captured", func(t *testing.T) { - testIstioMetrics(t, "testdata_istio/expected_istiod.yaml", "pilot_xds_pushes", flakyMetrics, true) + testIstioMetrics(t, "testdata/expected_istiod.yaml", "pilot_xds_pushes", flakyMetrics, true) }) flakyMetrics = []string{"istio_agent_pilot_xds_expired_nonce"} t.Run("istio ingress metrics captured", func(t *testing.T) { - testIstioMetrics(t, "testdata_istio/expected_istioingress.yaml", "istio_requests_total", flakyMetrics, true) + testIstioMetrics(t, "testdata/expected_istioingress.yaml", "istio_requests_total", flakyMetrics, true) }) } @@ -400,7 +396,7 @@ func testIstioMetrics(t *testing.T, expectedMetricsFile string, includeMetricNam expectedMetrics, err := golden.ReadMetrics(expectedMetricsFile) require.NoError(t, err) - waitForMetrics(t, 2, istioMetricsConsumer) + internal.WaitForMetrics(t, 2, istioMetricsConsumer) selectedMetrics := selectMetricSetWithTimeout(t, expectedMetrics, includeMetricName, istioMetricsConsumer, ignoreLen, 5*time.Minute, 30*time.Second) if selectedMetrics == nil { @@ -447,7 +443,7 @@ func testIstioMetrics(t *testing.T, expectedMetricsFile string, includeMetricNam pmetrictest.IgnoreSubsequentDataPoints(metricNames...), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedMetricsResult(t, expectedMetricsFile, selectedMetrics) + internal.WriteNewExpectedMetricsResult(t, expectedMetricsFile, selectedMetrics) } require.NoError(t, err) } diff --git a/functional_tests/testdata_istio/expected_istiod.yaml b/functional_tests/istio/testdata/expected_istiod.yaml similarity index 100% rename from functional_tests/testdata_istio/expected_istiod.yaml rename to functional_tests/istio/testdata/expected_istiod.yaml diff --git a/functional_tests/testdata_istio/expected_istioingress.yaml b/functional_tests/istio/testdata/expected_istioingress.yaml similarity index 100% rename from functional_tests/testdata_istio/expected_istioingress.yaml rename to functional_tests/istio/testdata/expected_istioingress.yaml diff --git a/functional_tests/testdata_istio/istio_values.yaml.tmpl b/functional_tests/istio/testdata/istio_values.yaml.tmpl similarity index 100% rename from functional_tests/testdata_istio/istio_values.yaml.tmpl rename to functional_tests/istio/testdata/istio_values.yaml.tmpl diff --git a/functional_tests/testdata_istio/testobjects/1-serviceaccount.yaml b/functional_tests/istio/testdata/testobjects/1-serviceaccount.yaml similarity index 100% rename from functional_tests/testdata_istio/testobjects/1-serviceaccount.yaml rename to functional_tests/istio/testdata/testobjects/1-serviceaccount.yaml diff --git a/functional_tests/testdata_istio/testobjects/2-service.yaml b/functional_tests/istio/testdata/testobjects/2-service.yaml similarity index 100% rename from functional_tests/testdata_istio/testobjects/2-service.yaml rename to functional_tests/istio/testdata/testobjects/2-service.yaml diff --git a/functional_tests/testdata_istio/testobjects/3-deployment.yaml b/functional_tests/istio/testdata/testobjects/3-deployment.yaml similarity index 100% rename from functional_tests/testdata_istio/testobjects/3-deployment.yaml rename to functional_tests/istio/testdata/testobjects/3-deployment.yaml diff --git a/functional_tests/testdata_istio/testobjects/gateway.yaml b/functional_tests/istio/testdata/testobjects/gateway.yaml similarity index 100% rename from functional_tests/testdata_istio/testobjects/gateway.yaml rename to functional_tests/istio/testdata/testobjects/gateway.yaml diff --git a/functional_tests/testdata_istio/testobjects/virtualservice.yaml b/functional_tests/istio/testdata/testobjects/virtualservice.yaml similarity index 100% rename from functional_tests/testdata_istio/testobjects/virtualservice.yaml rename to functional_tests/istio/testdata/testobjects/virtualservice.yaml diff --git a/functional_tests/k8sevents_test.go b/functional_tests/k8sevents/k8sevents_test.go similarity index 93% rename from functional_tests/k8sevents_test.go rename to functional_tests/k8sevents/k8sevents_test.go index 3cb14c8b6..d27d7eedb 100644 --- a/functional_tests/k8sevents_test.go +++ b/functional_tests/k8sevents/k8sevents_test.go @@ -1,9 +1,7 @@ // Copyright Splunk Inc. // SPDX-License-Identifier: Apache-2.0 -//go:build k8events - -package functional_tests +package k8sevents import ( "bytes" @@ -22,7 +20,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/plogtest" k8stest "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver" - "github.com/signalfx/splunk-otel-collector-chart/functional_tests/internal" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/consumer/consumertest" @@ -30,12 +27,13 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/receiver/receivertest" "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/kube" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" + + "github.com/signalfx/splunk-otel-collector-chart/functional_tests/internal" ) const ( @@ -60,7 +58,7 @@ func Test_K8SEvents(t *testing.T) { return } - waitForLogs(t, 3, eventsLogsConsumer) + internal.WaitForLogs(t, 3, eventsLogsConsumer) t.Run("CheckK8SEventsLogs", func(t *testing.T) { actualLogs := selectResLogs("com.splunk.sourcetype", "kube:events", eventsLogsConsumer) @@ -70,7 +68,7 @@ func Test_K8SEvents(t *testing.T) { }) removeFlakyLogRecordAttr(k8sEventsLogs, "container.id") - expectedEventsLogsFile := "testdata_k8sevents/expected_k8sevents.yaml" + expectedEventsLogsFile := "testdata/expected_k8sevents.yaml" expectedEventsLogs, err := golden.ReadLogs(expectedEventsLogsFile) require.NoError(t, err, "failed to read expected events logs from file") @@ -86,7 +84,7 @@ func Test_K8SEvents(t *testing.T) { plogtest.IgnoreLogRecordsOrder(), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedLogsResult(t, expectedEventsLogsFile, &k8sEventsLogs) + internal.WriteNewExpectedLogsResult(t, expectedEventsLogsFile, &k8sEventsLogs) } require.NoError(t, err) }) @@ -99,7 +97,7 @@ func Test_K8SEvents(t *testing.T) { k8sObjectsLogs = updateLogRecordBody(k8sObjectsLogs, []string{"object", "metadata", "managedFields", "0", "time"}, "2025-03-04T01:59:10Z") // k8sObjectsLogs = updateLogRecordBody(k8sObjectsLogs, []string{"object", "metadata", "managedFields", "0", "manager"}, "functional_test.test") - expectedObjectsLogsFile := "testdata_k8sevents/expected_k8sobjects.yaml" + expectedObjectsLogsFile := "testdata/expected_k8sobjects.yaml" expectedObjectsLogs, err := golden.ReadLogs(expectedObjectsLogsFile) require.NoError(t, err, "failed to read expected objects logs from file") @@ -115,7 +113,7 @@ func Test_K8SEvents(t *testing.T) { plogtest.IgnoreLogRecordsOrder(), ) if err != nil && os.Getenv("UPDATE_EXPECTED_RESULTS") == "true" { - writeNewExpectedLogsResult(t, expectedObjectsLogsFile, &k8sObjectsLogs) + internal.WriteNewExpectedLogsResult(t, expectedObjectsLogsFile, &k8sObjectsLogs) } require.NoError(t, err) }) @@ -152,14 +150,12 @@ func deployWorkloadAndCollector(t *testing.T) { k8sClient, err := k8stest.NewK8sClient(testKubeConfig) require.NoError(t, err) - chartPath := filepath.Join("..", "helm-charts", "splunk-otel-collector") - chart, err := loader.Load(chartPath) - require.NoError(t, err) + chart := internal.LoadCollectorChart(t) - valuesBytes, err := os.ReadFile(filepath.Join("testdata_k8sevents", "k8sevents_values.yaml.tmpl")) + valuesBytes, err := os.ReadFile(filepath.Join("testdata", "k8sevents_values.yaml.tmpl")) require.NoError(t, err) - hostEp := hostEndpoint(t) + hostEp := internal.HostEndpoint(t) if len(hostEp) == 0 { require.Fail(t, "host endpoint not found") } @@ -205,16 +201,16 @@ func deployWorkloadAndCollector(t *testing.T) { clientset, err := kubernetes.NewForConfig(config) require.NoError(t, err) - checkPodsReady(t, clientset, "default", "component=otel-k8s-cluster-receiver", 3*time.Minute) + internal.CheckPodsReady(t, clientset, "default", "component=otel-k8s-cluster-receiver", 3*time.Minute) time.Sleep(30 * time.Second) // Deploy the workload - createNamespace(t, clientset, "k8sevents-test") - createdObjs, err := k8stest.CreateObjects(k8sClient, "testdata_k8sevents/testobjects") + internal.CreateNamespace(t, clientset, "k8sevents-test") + createdObjs, err := k8stest.CreateObjects(k8sClient, "testdata/testobjects") require.NoError(t, err) require.NotEmpty(t, createdObjs) - checkPodsReady(t, clientset, "k8sevents-test", "app=k8sevents-test", 2*time.Minute) + internal.CheckPodsReady(t, clientset, "k8sevents-test", "app=k8sevents-test", 2*time.Minute) t.Cleanup(func() { if os.Getenv("SKIP_TEARDOWN") == "true" { diff --git a/functional_tests/testdata_k8sevents/expected_k8sevents.yaml b/functional_tests/k8sevents/testdata/expected_k8sevents.yaml similarity index 100% rename from functional_tests/testdata_k8sevents/expected_k8sevents.yaml rename to functional_tests/k8sevents/testdata/expected_k8sevents.yaml diff --git a/functional_tests/testdata_k8sevents/expected_k8sobjects.yaml b/functional_tests/k8sevents/testdata/expected_k8sobjects.yaml similarity index 100% rename from functional_tests/testdata_k8sevents/expected_k8sobjects.yaml rename to functional_tests/k8sevents/testdata/expected_k8sobjects.yaml diff --git a/functional_tests/testdata_k8sevents/k8sevents_values.yaml.tmpl b/functional_tests/k8sevents/testdata/k8sevents_values.yaml.tmpl similarity index 100% rename from functional_tests/testdata_k8sevents/k8sevents_values.yaml.tmpl rename to functional_tests/k8sevents/testdata/k8sevents_values.yaml.tmpl diff --git a/functional_tests/testdata_k8sevents/testobjects/1-serviceaccount.yaml b/functional_tests/k8sevents/testdata/testobjects/1-serviceaccount.yaml similarity index 100% rename from functional_tests/testdata_k8sevents/testobjects/1-serviceaccount.yaml rename to functional_tests/k8sevents/testdata/testobjects/1-serviceaccount.yaml diff --git a/functional_tests/testdata_k8sevents/testobjects/2-svc.yaml b/functional_tests/k8sevents/testdata/testobjects/2-svc.yaml similarity index 100% rename from functional_tests/testdata_k8sevents/testobjects/2-svc.yaml rename to functional_tests/k8sevents/testdata/testobjects/2-svc.yaml diff --git a/functional_tests/testdata_k8sevents/testobjects/3-sts.yaml b/functional_tests/k8sevents/testdata/testobjects/3-sts.yaml similarity index 100% rename from functional_tests/testdata_k8sevents/testobjects/3-sts.yaml rename to functional_tests/k8sevents/testdata/testobjects/3-sts.yaml