Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky prom remote write exporter concurrency test #37430

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion exporter/prometheusremotewriteexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"os"
"runtime"
"strconv"
"sync"
"testing"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are still failures on this test it may be necessary to reduce even further the amount of concurrency allowed here.

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()
Expand Down
Loading