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

[receiver/datadog] Test case level retries for flaky DD receiver integration test #24857

Closed
Closed
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
1 change: 1 addition & 0 deletions receiver/datadogreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/DataDog/datadog-agent/pkg/trace v0.48.0-devel
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.82.0
github.com/stretchr/testify v1.8.4
github.com/vmihailenco/msgpack/v4 v4.3.12
Expand Down
2 changes: 2 additions & 0 deletions receiver/datadogreceiver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions receiver/datadogreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ import (
"net/http"
"strings"
"testing"
"time"

"github.com/cenkalti/backoff"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/receivertest"
"go.uber.org/multierr"
)

func TestDatadogReceiver_Lifecycle(t *testing.T) {

factory := NewFactory()
ddr, err := factory.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), factory.CreateDefaultConfig(), consumertest.NewNop())
assert.NoError(t, err, "Receiver should be created")

err = ddr.Start(context.Background(), componenttest.NewNopHost())
err = startComponentWithRetries(context.Background(), ddr, componenttest.NewNopHost())
assert.NoError(t, err, "Server should start")

err = ddr.Shutdown(context.Background())
Expand All @@ -44,7 +46,7 @@ func TestDatadogServer(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

require.NoError(t, dd.Start(ctx, componenttest.NewNopHost()))
require.NoError(t, startComponentWithRetries(ctx, dd, componenttest.NewNopHost()))
t.Cleanup(func() {
require.NoError(t, dd.Shutdown(ctx), "Must not error shutting down")
})
Expand Down Expand Up @@ -85,3 +87,13 @@ func TestDatadogServer(t *testing.T) {
})
}
}

// Throughout the repo, many tests are invoked with go test ... -parallel ...
// This means that in addition to explicitly parallelizable tests (t.Parallel()), most test cases can be executed
// in parallel. Components that statically try to bind a port (e.g., from an integration test) can therefore fail
// and cause flaky builds. This function wraps Component.start with a simple ≤5s retry schedule.
func startComponentWithRetries(ctx context.Context, component component.Component, host component.Host) error {
return backoff.Retry(func() error {
return component.Start(ctx, host)
}, backoff.WithMaxRetries(backoff.NewConstantBackOff(time.Second), 5))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maintainers: feel free to fiddle with the parameters here (e.g., feel free to edit on-PR yourself). I just wanted to point out the flake and propose a fix. I wouldn't want to use too many retries to slow down overall build times and mask an issue that should be fixed more structurally. However, I think that it makes sense for the integration test to use the expected standard port instead of a randomly generated (guaranteed-not-in-use) port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, alternatively, we can just mash the two test cases (functions) in this suite (file) into one which will guarantee serial execution of their steps regardless of -parallel N invocations of gotest in CI.

}