From 44002d46fabd9cf7c50ca158a6be627572fcb40e Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Wed, 22 Jan 2025 20:36:52 -0800 Subject: [PATCH] [chore] update test to use a different prometheus endpoint (#37425) Instead of relying on the same port for each test, use `GetAvailableLocalAddress` to get a new port for each test. --------- Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- exporter/datadogexporter/integrationtest/go.mod | 2 +- exporter/datadogexporter/integrationtest/integration_test.go | 5 +++++ .../integration_test_internal_metrics_config.yaml | 4 ++-- .../integrationtest/integration_test_logs_config.yaml | 4 ++-- .../integrationtest/no_race_integration_test.go | 4 +++- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/exporter/datadogexporter/integrationtest/go.mod b/exporter/datadogexporter/integrationtest/go.mod index 363575858803..65b7307f844d 100644 --- a/exporter/datadogexporter/integrationtest/go.mod +++ b/exporter/datadogexporter/integrationtest/go.mod @@ -7,6 +7,7 @@ require ( github.com/DataDog/datadog-agent/pkg/proto v0.63.0-devel github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector v0.118.0 github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter v0.118.0 + github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.118.0 github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.118.0 github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.118.0 github.com/stretchr/testify v1.10.0 @@ -254,7 +255,6 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/ecsutil v0.118.0 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.118.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.118.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.118.0 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.118.0 // indirect diff --git a/exporter/datadogexporter/integrationtest/integration_test.go b/exporter/datadogexporter/integrationtest/integration_test.go index ef586f5423b6..7d04569e859e 100644 --- a/exporter/datadogexporter/integrationtest/integration_test.go +++ b/exporter/datadogexporter/integrationtest/integration_test.go @@ -47,6 +47,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter" + commonTestutil "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver" ) @@ -92,6 +93,7 @@ func testIntegration(t *testing.T) { server := testutil.DatadogServerMock(apmstatsRec.HandlerFunc, tracesRec.HandlerFunc) defer server.Close() t.Setenv("SERVER_URL", server.URL) + t.Setenv("PROM_SERVER", commonTestutil.GetAvailableLocalAddress(t)) // 2. Start in-process collector factories := getIntegrationTestComponents(t) @@ -284,6 +286,7 @@ func TestIntegrationComputeTopLevelBySpanKind(t *testing.T) { server := testutil.DatadogServerMock(apmstatsRec.HandlerFunc, tracesRec.HandlerFunc) defer server.Close() t.Setenv("SERVER_URL", server.URL) + t.Setenv("PROM_SERVER", commonTestutil.GetAvailableLocalAddress(t)) // 2. Start in-process collector factories := getIntegrationTestComponents(t) @@ -463,7 +466,9 @@ func TestIntegrationLogs(t *testing.T) { } }) defer server.Close() + thing := commonTestutil.GetAvailableLocalAddress(t) t.Setenv("SERVER_URL", server.URL) + t.Setenv("PROM_SERVER", thing) // 2. Start in-process collector factories := getIntegrationTestComponents(t) diff --git a/exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml b/exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml index 9100aecf8cad..47a7115436dd 100644 --- a/exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml +++ b/exporter/datadogexporter/integrationtest/integration_test_internal_metrics_config.yaml @@ -12,7 +12,7 @@ receivers: - job_name: 'otelcol' scrape_interval: 1s static_configs: - - targets: [ 'localhost:8888' ] + - targets: [ '${env:PROM_SERVER}' ] exporters: datadog: @@ -33,7 +33,7 @@ service: telemetry: metrics: level: basic - address: "localhost:8888" + address: ${env:PROM_SERVER} pipelines: traces: receivers: [otlp] diff --git a/exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml b/exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml index f02d45dafc16..28ac1ff0789b 100644 --- a/exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml +++ b/exporter/datadogexporter/integrationtest/integration_test_logs_config.yaml @@ -12,7 +12,7 @@ receivers: - job_name: 'otelcol' scrape_interval: 1s static_configs: - - targets: [ 'localhost:8888' ] + - targets: [ '${env:PROM_SERVER}' ] metric_relabel_configs: - source_labels: [ __name__ ] regex: "(otelcol_receiver_accepted_log_records|otelcol_exporter_sent_log_records)" @@ -37,7 +37,7 @@ service: telemetry: metrics: level: basic - address: "localhost:8888" + address: ${env:PROM_SERVER} pipelines: logs: receivers: [otlp] diff --git a/exporter/datadogexporter/integrationtest/no_race_integration_test.go b/exporter/datadogexporter/integrationtest/no_race_integration_test.go index a42262337550..7c7bb38651b2 100644 --- a/exporter/datadogexporter/integrationtest/no_race_integration_test.go +++ b/exporter/datadogexporter/integrationtest/no_race_integration_test.go @@ -14,19 +14,21 @@ import ( "github.com/DataDog/datadog-agent/comp/otelcol/otlp/testutil" "github.com/stretchr/testify/assert" + + commonTestutil "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" ) func TestIntegrationInternalMetrics(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("flaky test on windows https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/34836") } - // 1. Set up mock Datadog server seriesRec := &testutil.HTTPRequestRecorderWithChan{Pattern: testutil.MetricV2Endpoint, ReqChan: make(chan []byte, 100)} tracesRec := &testutil.HTTPRequestRecorderWithChan{Pattern: testutil.TraceEndpoint, ReqChan: make(chan []byte, 100)} server := testutil.DatadogServerMock(seriesRec.HandlerFunc, tracesRec.HandlerFunc) defer server.Close() t.Setenv("SERVER_URL", server.URL) + t.Setenv("PROM_SERVER", commonTestutil.GetAvailableLocalAddress(t)) // 2. Start in-process collector factories := getIntegrationTestComponents(t)