From 7a682dcd00280797ecb0cde1437b5d73d62c8357 Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Sat, 14 Nov 2026 23:04:43 -0400 Subject: [PATCH] fix(msk): report the broker's advertised hostname from GetBootstrapBrokers (#8404) With Floci in a container and no bootstrap hostname configured, GetBootstrapBrokers returned the broker container's IP, a bare address where AWS returns broker hostnames. The broker's internal listener already advertises :9092, so a client that bootstrapped from the IP was handed that name by the first Metadata response anyway. GetBootstrapBrokers now returns :9092. --- docs/services/msk.md | 4 ++-- .../aws/services/msk/RedpandaManager.java | 20 ++++++++++--------- .../aws/services/msk/RedpandaManagerTest.java | 7 ++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/docs/services/msk.md b/docs/services/msk.md index 8b5f1567eb..780682bb5f 100644 --- a/docs/services/msk.md +++ b/docs/services/msk.md @@ -41,7 +41,7 @@ Floci emulates Amazon MSK by orchestrating **Redpanda** containers. This provide | `FLOCI_SERVICES_MSK_KAFKA_HOST_PORT_BASE` | `9300` | First host port a broker's Kafka listener can be published on | | `FLOCI_SERVICES_MSK_KAFKA_HOST_PORT_MAX` | `9399` | Last host port a broker's Kafka listener can be published on | | `FLOCI_SERVICES_MSK_SCRAM_RECONCILIATION_INTERVAL_MS` | `5000` | SCRAM secret reconciliation interval (ms) | -| `FLOCI_SERVICES_MSK_BOOTSTRAP_HOSTNAME` | _(unset)_ | Floci in a container only: hostname the host listener advertises, and when set, `GetBootstrapBrokers` returns `:9092,:` instead of the Docker-network address | +| `FLOCI_SERVICES_MSK_BOOTSTRAP_HOSTNAME` | _(unset)_ | Floci in a container only: hostname the host listener advertises, and when set, `GetBootstrapBrokers` returns `:9092,:` instead of `:9092` alone | ## How it works @@ -49,7 +49,7 @@ When `mock` is set to `false` (default), Floci uses the Docker API to start a Re - **Networking**: Kafka clients connect to whatever address the broker advertises, so the advertised address has to be reachable from the client. - Floci on the host: the Kafka API (9092) is published on a host port from the `kafka-host-port` range and advertised as `localhost:`. - - Floci in a container: the broker has two listeners. `internal` (9092) advertises `:9092` for containers on the same Docker network. `host` (9093) is published on a host port from the `kafka-host-port` range and advertised as `:` for clients on the Docker host. `GetBootstrapBrokers` returns the Docker-network address. When `FLOCI_SERVICES_MSK_BOOTSTRAP_HOSTNAME` is set, it returns both listeners, `:9092,:`: a client connects through whichever entry it can reach, and the broker then advertises that listener's address. The two entries are two listeners on the same broker, not two brokers. + - Floci in a container: the broker has two listeners. `internal` (9092) advertises `:9092` for containers on the same Docker network. `host` (9093) is published on a host port from the `kafka-host-port` range and advertised as `:` for clients on the Docker host. `GetBootstrapBrokers` returns `:9092`, the address the internal listener advertises, so a client gets a hostname as it does from AWS rather than a container IP. When `FLOCI_SERVICES_MSK_BOOTSTRAP_HOSTNAME` is set, it returns both listeners, `:9092,:`: a client connects through whichever entry it can reach, and the broker then advertises that listener's address. The two entries are two listeners on the same broker, not two brokers. - **Persistence**: Each cluster gets a named Docker volume (`floci-aws-msk-{volumeId}`). In memory mode the volume is removed on cluster delete; in persistent modes it is retained unless `FLOCI_STORAGE_PRUNE_VOLUMES_ON_DELETE=true`. - **Readiness**: The cluster state transitions to `ACTIVE` once the Redpanda `/ready` endpoint is reachable. diff --git a/src/main/java/io/floci/aws/services/msk/RedpandaManager.java b/src/main/java/io/floci/aws/services/msk/RedpandaManager.java index 49077d1026..fceeaa3728 100644 --- a/src/main/java/io/floci/aws/services/msk/RedpandaManager.java +++ b/src/main/java/io/floci/aws/services/msk/RedpandaManager.java @@ -179,16 +179,18 @@ public class RedpandaManager { if (inContainer) { hostListenerPorts.put(clusterIdentityKey(cluster), kafkaHostPort); - // GetBootstrapBrokers reports the Docker-network address unless the host listener - // was asked for explicitly, which keeps sibling containers working by default. When - // it was, both listeners are listed: a client connects through whichever entry it can - // reach, and the broker then advertises that listener's address. The container name - // (not its IP) fails fast on the host, where it does not resolve, while an unroutable - // IP would wait for a connect timeout. It goes first for callers that read only the - // first entry. + // GetBootstrapBrokers reports the internal listener by the name the broker advertises + // for it, a hostname as on AWS: a client that bootstrapped from the container IP would + // be handed that name by the first Metadata response anyway. When the host listener + // was asked for explicitly, both listeners are listed: a client connects through + // whichever entry it can reach, and the broker then advertises that listener's + // address. The container name fails fast on the host, where it does not resolve, + // while an unroutable IP would wait for a connect timeout. It goes first for callers + // that read only the first entry. + String internalListenerAddr = containerName + ":" + KAFKA_PORT; cluster.setBootstrapBrokers(explicitBootstrapHostname().isPresent() - ? containerName + ":" + KAFKA_PORT + "," + hostListenerAddr - : kafkaEndpoint.host() + ":" + kafkaEndpoint.port()); + ? internalListenerAddr + "," + hostListenerAddr + : internalListenerAddr); LOG.infov("Redpanda host listener for MSK cluster {0} published at {1}", cluster.getClusterName(), hostListenerAddr); } else { diff --git a/src/test/java/io/floci/aws/services/msk/RedpandaManagerTest.java b/src/test/java/io/floci/aws/services/msk/RedpandaManagerTest.java index c683d861f0..a0f17e6f3c 100644 --- a/src/test/java/io/floci/aws/services/msk/RedpandaManagerTest.java +++ b/src/test/java/io/floci/aws/services/msk/RedpandaManagerTest.java @@ -466,8 +466,9 @@ class RedpandaManagerTest { assertFalse(Files.exists(tempDir.resolve("msk").resolve("test-cluster")), "container mode must not create host directories from inside the emulator container"); - assertEquals("172.18.0.5:9092", cluster.getBootstrapBrokers(), - "without a bootstrap hostname, GetBootstrapBrokers keeps the Docker-network address"); + assertEquals("floci-aws-msk-abc123:9092", cluster.getBootstrapBrokers(), + "without a bootstrap hostname, GetBootstrapBrokers names the internal listener the way the " + + "broker advertises it, not by the container IP"); } @Test @@ -513,7 +514,7 @@ class RedpandaManagerTest { int flagIndex = spec.cmd().indexOf("--advertise-kafka-addr"); assertEquals("internal://floci-aws-msk-abc123:9092,host://localhost:9305", spec.cmd().get(flagIndex + 1)); - assertEquals("172.18.0.8:9092", cluster.getBootstrapBrokers()); + assertEquals("floci-aws-msk-abc123:9092", cluster.getBootstrapBrokers()); } @Test