mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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 <container-name>:9092, so a client that bootstrapped from the IP was handed that name by the first Metadata response anyway. GetBootstrapBrokers now returns <container-name>:9092.
This commit is contained in:
1 parent
246d82ec57
commit
7a682dcd00
3 files changed
+17
-14
No files matched your search
@@ -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 `<container-name>:9092,<hostname>:<host port>` 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 `<container-name>:9092,<hostname>:<host port>` instead of `<container-name>: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:<port>`.
|
||||
- Floci in a container: the broker has two listeners. `internal` (9092) advertises `<container-name>: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 `<bootstrap-hostname or localhost>:<port>` for clients on the Docker host. `GetBootstrapBrokers` returns the Docker-network address. When `FLOCI_SERVICES_MSK_BOOTSTRAP_HOSTNAME` is set, it returns both listeners, `<container-name>:9092,<hostname>:<port>`: 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 `<container-name>: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 `<bootstrap-hostname or localhost>:<port>` for clients on the Docker host. `GetBootstrapBrokers` returns `<container-name>: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, `<container-name>:9092,<hostname>:<port>`: 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.
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user