From 79c5cae70422159b0fb84290aa66b103465eaef8 Mon Sep 17 00:00:00 2001 From: sakulali Date: Mon, 6 Nov 2023 20:35:44 +0800 Subject: [PATCH 1/2] [receiver/kafkametrics] Using unique container networks and container names to attempt to fix flaky tests Signed-off-by: sakulali --- .../kafkametricsreceiver-flaky-test.yaml | 27 +++++++++++++++++++ receiver/kafkametricsreceiver/go.mod | 2 +- .../kafkametricsreceiver/integration_test.go | 20 ++++++++------ 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100755 .chloggen/kafkametricsreceiver-flaky-test.yaml diff --git a/.chloggen/kafkametricsreceiver-flaky-test.yaml b/.chloggen/kafkametricsreceiver-flaky-test.yaml new file mode 100755 index 000000000000..a69df9bf9100 --- /dev/null +++ b/.chloggen/kafkametricsreceiver-flaky-test.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'bug_fix' + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: kafkametricsreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Using unique container networks and container names to attempt to fix flaky tests. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [26293] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/receiver/kafkametricsreceiver/go.mod b/receiver/kafkametricsreceiver/go.mod index 50c3075b5dfe..6da6e7864dfd 100644 --- a/receiver/kafkametricsreceiver/go.mod +++ b/receiver/kafkametricsreceiver/go.mod @@ -5,6 +5,7 @@ go 1.20 require ( github.com/IBM/sarama v1.41.3 github.com/google/go-cmp v0.6.0 + github.com/google/uuid v1.4.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka v0.88.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.88.0 @@ -44,7 +45,6 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/uuid v1.4.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect diff --git a/receiver/kafkametricsreceiver/integration_test.go b/receiver/kafkametricsreceiver/integration_test.go index d946e72a135e..dcaa40511588 100644 --- a/receiver/kafkametricsreceiver/integration_test.go +++ b/receiver/kafkametricsreceiver/integration_test.go @@ -11,6 +11,7 @@ import ( "testing" "time" + "github.com/google/uuid" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" "go.opentelemetry.io/collector/component" @@ -20,13 +21,16 @@ import ( ) const ( - networkName = "kafka-network" kafkaPort = "9092" zookeeperPort = "2181" - zookeeperHost = "zookeeper" ) func TestIntegration(t *testing.T) { + uid := fmt.Sprintf("-%s", uuid.NewString()) + networkName := "kafka-network" + uid + zkContainerName := "zookeeper" + uid + kafkaContainerName := "kafka" + uid + scraperinttest.NewIntegrationTest( NewFactory(), scraperinttest.WithNetworkRequest( @@ -37,10 +41,10 @@ func TestIntegration(t *testing.T) { ), scraperinttest.WithContainerRequest( testcontainers.ContainerRequest{ - Name: "zookeeper", + Name: zkContainerName, Image: "ubuntu/zookeeper:3.1-22.04_beta", Networks: []string{networkName}, - Hostname: zookeeperHost, + Hostname: zkContainerName, ExposedPorts: []string{zookeeperPort}, WaitingFor: wait.ForAll( wait.ForListeningPort(zookeeperPort).WithStartupTimeout(2 * time.Minute), @@ -48,12 +52,12 @@ func TestIntegration(t *testing.T) { }), scraperinttest.WithContainerRequest( testcontainers.ContainerRequest{ - Name: "kafka", + Name: kafkaContainerName, Image: "ubuntu/kafka:3.1-22.04_beta", Networks: []string{networkName}, ExposedPorts: []string{kafkaPort}, Env: map[string]string{ - "ZOOKEEPER_HOST": zookeeperHost, + "ZOOKEEPER_HOST": zkContainerName, "ZOOKEEPER_PORT": zookeeperPort, }, WaitingFor: wait.ForAll( @@ -65,8 +69,8 @@ func TestIntegration(t *testing.T) { rCfg := cfg.(*Config) rCfg.CollectionInterval = 5 * time.Second rCfg.Brokers = []string{fmt.Sprintf("%s:%s", - ci.HostForNamedContainer(t, "kafka"), - ci.MappedPortForNamedContainer(t, "kafka", kafkaPort))} + ci.HostForNamedContainer(t, kafkaContainerName), + ci.MappedPortForNamedContainer(t, kafkaContainerName, kafkaPort))} rCfg.Scrapers = []string{"brokers", "consumers", "topics"} }), // scraperinttest.WriteExpected(), // TODO remove From 32d51d16e15d1f0d52b43c9f2245f94f9000727d Mon Sep 17 00:00:00 2001 From: sakulali Date: Mon, 6 Nov 2023 23:29:26 +0800 Subject: [PATCH 2/2] chore: remove change log since this is only a test fix and doesn't have user-facing impact Signed-off-by: sakulali --- .../kafkametricsreceiver-flaky-test.yaml | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100755 .chloggen/kafkametricsreceiver-flaky-test.yaml diff --git a/.chloggen/kafkametricsreceiver-flaky-test.yaml b/.chloggen/kafkametricsreceiver-flaky-test.yaml deleted file mode 100755 index a69df9bf9100..000000000000 --- a/.chloggen/kafkametricsreceiver-flaky-test.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# Use this changelog template to create an entry for release notes. - -# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: 'bug_fix' - -# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) -component: kafkametricsreceiver - -# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Using unique container networks and container names to attempt to fix flaky tests. - -# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -issues: [26293] - -# (Optional) One or more lines of additional information to render under the primary note. -# These lines will be padded with 2 spaces and then inserted directly into the document. -# Use pipe (|) for multiline entries. -subtext: - -# If your change doesn't affect end users or the exported elements of any package, -# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. -# Optional: The change log or logs in which this entry should be included. -# e.g. '[user]' or '[user, api]' -# Include 'user' if the change is relevant to end users. -# Include 'api' if there is a change to a library API. -# Default: '[user]' -change_logs: []