Skip to content

Commit

Permalink
[chore] update test to use a different prometheus endpoint (#37425)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
codeboten authored Jan 23, 2025
1 parent 23117ab commit 44002d4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion exporter/datadogexporter/integrationtest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions exporter/datadogexporter/integrationtest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ receivers:
- job_name: 'otelcol'
scrape_interval: 1s
static_configs:
- targets: [ 'localhost:8888' ]
- targets: [ '${env:PROM_SERVER}' ]

exporters:
datadog:
Expand All @@ -33,7 +33,7 @@ service:
telemetry:
metrics:
level: basic
address: "localhost:8888"
address: ${env:PROM_SERVER}
pipelines:
traces:
receivers: [otlp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -37,7 +37,7 @@ service:
telemetry:
metrics:
level: basic
address: "localhost:8888"
address: ${env:PROM_SERVER}
pipelines:
logs:
receivers: [otlp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 44002d4

Please sign in to comment.