From bc5384209e8d586f553344aa0cf9d55d7813e441 Mon Sep 17 00:00:00 2001 From: Yang Song Date: Fri, 11 Oct 2024 12:39:58 -0400 Subject: [PATCH] [OTEL-2125] Add E2E test for no dd exporter case --- comp/otelcol/ddflareextension/impl/server.go | 1 - .../otel/otel-agent/config/no-dd-exporter.yml | 23 +++++ .../tests/otel/otel-agent/minimal_test.go | 6 +- .../otel/otel-agent/no_dd_exporter_test.go | 59 ++++++++++++ .../testdata/no-dd-exporter-full-config.yml | 93 +++++++++++++++++++ .../no-dd-exporter-provided-config.yml | 49 ++++++++++ .../{minimal-sources.json => sources.json} | 0 test/new-e2e/tests/otel/utils/config_utils.go | 16 ++-- 8 files changed, 236 insertions(+), 11 deletions(-) create mode 100644 test/new-e2e/tests/otel/otel-agent/config/no-dd-exporter.yml create mode 100644 test/new-e2e/tests/otel/otel-agent/no_dd_exporter_test.go create mode 100644 test/new-e2e/tests/otel/otel-agent/testdata/no-dd-exporter-full-config.yml create mode 100644 test/new-e2e/tests/otel/otel-agent/testdata/no-dd-exporter-provided-config.yml rename test/new-e2e/tests/otel/otel-agent/testdata/{minimal-sources.json => sources.json} (100%) diff --git a/comp/otelcol/ddflareextension/impl/server.go b/comp/otelcol/ddflareextension/impl/server.go index 4b3c0fcf0c104..f3a0969b2aee0 100644 --- a/comp/otelcol/ddflareextension/impl/server.go +++ b/comp/otelcol/ddflareextension/impl/server.go @@ -111,7 +111,6 @@ func newServer(endpoint string, handler http.Handler) (*server, error) { r := mux.NewRouter() r.Handle("/", handler) - r.Use(validateToken) s := &http.Server{ diff --git a/test/new-e2e/tests/otel/otel-agent/config/no-dd-exporter.yml b/test/new-e2e/tests/otel/otel-agent/config/no-dd-exporter.yml new file mode 100644 index 0000000000000..3c008992c3d06 --- /dev/null +++ b/test/new-e2e/tests/otel/otel-agent/config/no-dd-exporter.yml @@ -0,0 +1,23 @@ +receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + +exporters: + debug: + verbosity: detailed + +service: + pipelines: + metrics: + receivers: [otlp] + exporters: [debug] + traces: + receivers: [otlp] + exporters: [debug] + logs: + receivers: [otlp] + exporters: [debug] diff --git a/test/new-e2e/tests/otel/otel-agent/minimal_test.go b/test/new-e2e/tests/otel/otel-agent/minimal_test.go index e3ccb0faaf971..d907785ca6543 100644 --- a/test/new-e2e/tests/otel/otel-agent/minimal_test.go +++ b/test/new-e2e/tests/otel/otel-agent/minimal_test.go @@ -32,8 +32,8 @@ var minimalProvidedConfig string //go:embed testdata/minimal-full-config.yml var minimalFullConfig string -//go:embed testdata/minimal-sources.json -var minimalSources string +//go:embed testdata/sources.json +var sources string func TestOTelAgentMinimal(t *testing.T) { values := ` @@ -82,5 +82,5 @@ func (s *minimalTestSuite) TestOTelAgentInstalled() { } func (s *minimalTestSuite) TestOTelFlare() { - utils.TestOTelFlare(s, minimalProvidedConfig, minimalFullConfig, minimalSources) + utils.TestOTelFlare(s, minimalProvidedConfig, minimalFullConfig, sources) } diff --git a/test/new-e2e/tests/otel/otel-agent/no_dd_exporter_test.go b/test/new-e2e/tests/otel/otel-agent/no_dd_exporter_test.go new file mode 100644 index 0000000000000..9e3b3b4b270cb --- /dev/null +++ b/test/new-e2e/tests/otel/otel-agent/no_dd_exporter_test.go @@ -0,0 +1,59 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package otelagent contains e2e otel agent tests +package otelagent + +import ( + _ "embed" + "testing" + + "github.com/DataDog/test-infra-definitions/components/datadog/kubernetesagentparams" + + "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" + "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments" + awskubernetes "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/kubernetes" + "github.com/DataDog/datadog-agent/test/new-e2e/tests/otel/utils" +) + +type noDDExporterTestSuite struct { + e2e.BaseSuite[environments.Kubernetes] +} + +//go:embed config/no-dd-exporter.yml +var noDDExporterConfig string + +//go:embed testdata/no-dd-exporter-provided-config.yml +var noDDExporterProvidedConfig string + +//go:embed testdata/no-dd-exporter-full-config.yml +var noDDExporterFullConfig string + +func TestOTelAgentWithNoDDExporter(t *testing.T) { + values := ` +datadog: + logs: + containerCollectAll: false + containerCollectUsingFiles: false +` + t.Parallel() + e2e.Run(t, &noDDExporterTestSuite{}, + e2e.WithProvisioner( + awskubernetes.KindProvisioner( + awskubernetes.WithAgentOptions( + kubernetesagentparams.WithoutDualShipping(), + kubernetesagentparams.WithHelmValues(values), + kubernetesagentparams.WithOTelAgent(), + kubernetesagentparams.WithOTelConfig(noDDExporterConfig), + )))) +} + +func (s *noDDExporterTestSuite) TestOTelAgentInstalled() { + utils.TestOTelAgentInstalled(s) +} + +func (s *noDDExporterTestSuite) TestFlare() { + utils.TestOTelFlare(s, noDDExporterProvidedConfig, noDDExporterFullConfig, sources) +} diff --git a/test/new-e2e/tests/otel/otel-agent/testdata/no-dd-exporter-full-config.yml b/test/new-e2e/tests/otel/otel-agent/testdata/no-dd-exporter-full-config.yml new file mode 100644 index 0000000000000..520d359737b52 --- /dev/null +++ b/test/new-e2e/tests/otel/otel-agent/testdata/no-dd-exporter-full-config.yml @@ -0,0 +1,93 @@ +connectors: {} +exporters: + debug: + sampling_initial: 2 + sampling_thereafter: 1 + use_internal_logger: true + verbosity: Detailed +extensions: + ddflare/dd-autoconfigured: + auth: null + compression_algorithms: [] + cors: null + endpoint: localhost:7777 + include_metadata: false + max_request_body_size: 0 + response_headers: {} + tls: null + health_check/dd-autoconfigured: + auth: null + check_collector_pipeline: + enabled: false + exporter_failure_threshold: 5 + interval: 5m + compression_algorithms: [] + cors: null + endpoint: localhost:13133 + include_metadata: false + max_request_body_size: 0 + path: / + response_body: null + response_headers: {} + tls: null + pprof/dd-autoconfigured: + block_profile_fraction: 0 + dialer: + timeout: 0s + endpoint: localhost:1777 + mutex_profile_fraction: 0 + save_to_file: "" + zpages/dd-autoconfigured: + auth: null + compression_algorithms: [] + cors: null + endpoint: localhost:55679 + include_metadata: false + max_request_body_size: 0 + response_headers: {} + tls: null +processors: {} +receivers: + hostmetrics: + collection_interval: 1m0s + initial_delay: 1s + root_path: "" + timeout: 0s +service: + extensions: + - pprof/dd-autoconfigured + - zpages/dd-autoconfigured + - health_check/dd-autoconfigured + - ddflare/dd-autoconfigured + pipelines: + metrics/sys: + exporters: + - debug + processors: [] + receivers: + - hostmetrics + telemetry: + logs: + development: false + disable_caller: false + disable_stacktrace: false + encoding: console + error_output_paths: + - stderr + initial_fields: {} + level: info + output_paths: + - stderr + sampling: + enabled: true + initial: 10 + thereafter: 100 + tick: 10s + metrics: + address: :8888 + level: Normal + readers: [] + resource: {} + traces: + processors: [] + propagators: [] diff --git a/test/new-e2e/tests/otel/otel-agent/testdata/no-dd-exporter-provided-config.yml b/test/new-e2e/tests/otel/otel-agent/testdata/no-dd-exporter-provided-config.yml new file mode 100644 index 0000000000000..92a1a2aff55e7 --- /dev/null +++ b/test/new-e2e/tests/otel/otel-agent/testdata/no-dd-exporter-provided-config.yml @@ -0,0 +1,49 @@ +connectors: {} +exporters: + debug: + sampling_initial: 2 + sampling_thereafter: 1 + use_internal_logger: true + verbosity: Detailed +extensions: {} +processors: {} +receivers: + hostmetrics: + collection_interval: 1m0s + initial_delay: 1s + root_path: "" + timeout: 0s +service: + extensions: [] + pipelines: + metrics/sys: + exporters: + - debug + processors: [] + receivers: + - hostmetrics + telemetry: + logs: + development: false + disable_caller: false + disable_stacktrace: false + encoding: console + error_output_paths: + - stderr + initial_fields: {} + level: info + output_paths: + - stderr + sampling: + enabled: true + initial: 10 + thereafter: 100 + tick: 10s + metrics: + address: :8888 + level: Normal + readers: [] + resource: {} + traces: + processors: [] + propagators: [] diff --git a/test/new-e2e/tests/otel/otel-agent/testdata/minimal-sources.json b/test/new-e2e/tests/otel/otel-agent/testdata/sources.json similarity index 100% rename from test/new-e2e/tests/otel/otel-agent/testdata/minimal-sources.json rename to test/new-e2e/tests/otel/otel-agent/testdata/sources.json diff --git a/test/new-e2e/tests/otel/utils/config_utils.go b/test/new-e2e/tests/otel/utils/config_utils.go index 9e359877d5700..33d85415ec855 100644 --- a/test/new-e2e/tests/otel/utils/config_utils.go +++ b/test/new-e2e/tests/otel/utils/config_utils.go @@ -141,13 +141,15 @@ func validateConfigs(t *testing.T, expectedCfg string, actualCfg string) { // Traces, metrics and logs endpoints are set dynamically to the fake intake address in the config // These endpoints vary from test to test and should be ignored in the comparison exps, _ := actualConfRaw["exporters"].(map[string]any) - ddExp, _ := exps["datadog"].(map[string]any) - tcfg := ddExp["traces"].(map[string]any) - delete(tcfg, "endpoint") - mcfg := ddExp["metrics"].(map[string]any) - delete(mcfg, "endpoint") - lcfg := ddExp["logs"].(map[string]any) - delete(lcfg, "endpoint") + if ddExp, ok := exps["datadog"]; ok { + ddExpCfg := ddExp.(map[string]any) + tcfg := ddExpCfg["traces"].(map[string]any) + delete(tcfg, "endpoint") + mcfg := ddExpCfg["metrics"].(map[string]any) + delete(mcfg, "endpoint") + lcfg := ddExpCfg["logs"].(map[string]any) + delete(lcfg, "endpoint") + } actualCfgBytes, err := yaml.Marshal(actualConfRaw) require.NoError(t, err)