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(modules.kafka): Use broker container IP instead of host IP for advertised broker listener #1989

Merged
merged 10 commits into from May 8, 2024

Conversation

khartld
Copy link
Contributor

@khartld khartld commented Dec 8, 2023

What does this PR do?

This PR changes the advertised broker ip from being the host ip to container ip. Port 9092 is not exposed to the host, so we can not connect to it via host IP, but need to use the broker container IP.
The current setup works with a normal desktop setup, because there the returned host IP is "localhost".

Alternatively, it should also be sufficient to hardcode the advertised broker as "localhost", because there is only 1 broker that needs to be able to connect to itself.

Why is it important?

This makes it possible to use the Kafka module inside another Docker container or other setups where Host() does not return "localhost". This enables the use of this module in CI/CD pipelines that run in Docker.

Currently it leads to errors in the TransactionCoordinator:
WARN [TransactionCoordinator id=1] Connection to node 1 (/172.17.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

Related issues

How to test this PR

After starting a Kafka container using the Kafka module, the KAFKA_ADVERTISED_LISTENERS should contain the kafka container ip.

E.g.
the /usr/sbin/testcontainers_start.sh script should contain the following value:

export KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:51702,BROKER://172.17.0.6:9092

@khartld khartld requested a review from a team as a code owner December 8, 2023 14:15
Copy link

netlify bot commented Dec 8, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit f4991ba
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/663b16229b5898000892fbcc
😎 Deploy Preview https://deploy-preview-1989--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

mdelapenya
mdelapenya previously approved these changes Dec 11, 2023
Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM! Although I'd like to have @eddumelendez 's eyes on this one too before merging.

Thanks for your time in any case, will merge it once the review and the CI pass.

@mdelapenya mdelapenya self-assigned this Dec 11, 2023
@mdelapenya mdelapenya added the bug An issue with the library label Dec 11, 2023
port 9092 is not exposed to the host, so we can not connect to it via host ip, but need to use the broker container ip
@khartld
Copy link
Contributor Author

khartld commented Mar 15, 2024

@mdelapenya @eddumelendez
what do you think about merging this? :)

@mdelapenya
Copy link
Collaborator

@eddumelendez, as our kafka expert, what are your thoughts on this?

container.go Outdated Show resolved Hide resolved
* main: (44 commits)
  feat: expose JSON representation of a container with Inspect (testcontainers#2534)
  chore(deps): bump test-summary action to v2.3 (testcontainers#2535)
  chore(deps): bump jinja2 from 3.1.3 to 3.1.4 (testcontainers#2533)
  Update devcontainer image (testcontainers#2531)
  chore(influxdb): include more characters in wait for log regex (testcontainers#2532)
  fix(compose): avoid race conditions when caching services (testcontainers#2528)
  chore(deps): bump golangci/golangci-lint-action from 3.7.0 to 5.1.0 (testcontainers#2525)
  chore(deps): bump mkdocs-material from 8.2.7 to 9.1.21 (testcontainers#2524)
  chore(compose): return error in options (testcontainers#2520)
  chore(deps): bump github.com/compose-spec/compose-go/v2 from v2.0.0-rc8 to v2.1.0 (testcontainers#2519)
  chore(deps): bump github.com/containerd/containerd from 1.7.12 to 1.7.15 (testcontainers#2517)
  break: return error from Customize request option (testcontainers#2267)
  fix: wrong copy paste (testcontainers#2515)
  docs: add documentation for Exec method (testcontainers#2451)
  docs: document the SSHd tunnel (testcontainers#2514)
  fix: enhance host configuration port binding (testcontainers#2512)
  feat: forward host ports to a container using an SSH tunnel (testcontainers#2471)
  Update follow_logs.md with adding missing package (testcontainers#2513)
  fix: don't retry on permanent APIClient errors (testcontainers#2506)
  feat: support overriding the default recreate options for compose (testcontainers#2511)
  ...
@mdelapenya
Copy link
Collaborator

mdelapenya commented May 7, 2024

@khartld I went ahead and resolved conflicts and rebased your PR with main, as we already merged #2534

Please let us know what you think

Thanks!

@khartld
Copy link
Contributor Author

khartld commented May 8, 2024

@mdelapenya looks good, thanks :)

@mdelapenya mdelapenya merged commit de893e1 into testcontainers:main May 8, 2024
104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants