diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index 6ad7d31981c0..6829bb57201c 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -353,7 +353,10 @@ func (prwe *prwExporter) execute(ctx context.Context, writeReq *prompb.WriteRequ if err != nil { return err } - defer resp.Body.Close() + defer func() { + _, _ = io.Copy(io.Discard, resp.Body) + resp.Body.Close() + }() // 2xx status code is considered a success // 5xx errors are recoverable and the exporter should retry diff --git a/exporter/prometheusremotewriteexporter/exporter_concurrency_test.go b/exporter/prometheusremotewriteexporter/exporter_concurrency_test.go index bf9fcbd968cc..5369b201e526 100644 --- a/exporter/prometheusremotewriteexporter/exporter_concurrency_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_concurrency_test.go @@ -8,7 +8,7 @@ import ( "io" "net/http" "net/http/httptest" - "os" + "runtime" "strconv" "sync" "testing" @@ -32,9 +32,6 @@ import ( // Test everything works when there is more than one goroutine calling PushMetrics. // Today we only use 1 worker per exporter, but the intention of this test is to future-proof in case it changes. func Test_PushMetricsConcurrent(t *testing.T) { - if os.Getenv("ImageOs") == "win25" && os.Getenv("GITHUB_ACTIONS") == "true" { - t.Skip("Skipping test on Windows 2025 GH runners, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/37104") - } n := 1000 ms := make([]pmetric.Metrics, n) testIDKey := "test_id" @@ -137,15 +134,22 @@ func Test_PushMetricsConcurrent(t *testing.T) { resp, checkRequestErr := http.Get(server.URL) require.NoError(c, checkRequestErr) assert.NoError(c, resp.Body.Close()) - }, 5*time.Second, 100*time.Millisecond) + }, 15*time.Second, 100*time.Millisecond) var wg sync.WaitGroup wg.Add(n) + maxConcurrentGoroutines := runtime.NumCPU() * 4 + semaphore := make(chan struct{}, maxConcurrentGoroutines) for _, m := range ms { + semaphore <- struct{}{} go func() { + defer func() { + <-semaphore + wg.Done() + }() + err := prwe.PushMetrics(ctx, m) assert.NoError(t, err) - wg.Done() }() } wg.Wait()