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/kafkametrics] Using unique container networks and container names and attempt to fix flaky tests #28903

Merged
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
2 changes: 1 addition & 1 deletion receiver/kafkametricsreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions receiver/kafkametricsreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand All @@ -37,23 +41,23 @@ 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),
),
}),
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(
Expand All @@ -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
Expand Down
Loading