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

Support ability to connect to specific kafka cluster node hostname #633

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ private void doConnectionBegin(
.destination(host)
.sourcePort(0)
.destinationPort(port)))
.infos(i -> i.item(ii -> ii.authority(host)))
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be coming from ProxyBeginEx info authority, not host, and address key for shared connections should include authority in addition to host and port, agree?

Otherwise, two streams differing only by authority would be treated as equal, even though their TLS handshakes would have a different sni.

.build()
.sizeof());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public KafkaClientFactory(
config, context, bindings::get, accountant::supplyDebitor);

final KafkaClientGroupFactory clientGroupFactory = new KafkaClientGroupFactory(
config, context, bindings::get, accountant::supplyDebitor, signaler, streamFactory, resolveSasl);
config, context, bindings::get, accountant::supplyDebitor, signaler, streamFactory, resolveSasl, supplyClientRoute);

final KafkaClientFetchFactory clientFetchFactory = new KafkaClientFetchFactory(
config, context, bindings::get, accountant::supplyDebitor, supplyClientRoute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,7 @@ else if (nextOffset == OFFSET_LIVE || nextOffset == OFFSET_HISTORICAL)
.destination(broker.host)
.sourcePort(0)
.destinationPort(broker.port)))
.infos(i -> i.item(ii -> ii.authority(broker.host)))
.build()
.sizeof());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ public final class KafkaClientGroupFactory extends KafkaClientSaslHandshaker imp
private final Signaler signaler;
private final BindingHandler streamFactory;
private final UnaryOperator<KafkaSaslConfig> resolveSasl;
private final LongFunction<KafkaClientRoute> supplyClientRoute;
private final LongFunction<KafkaBindingConfig> supplyBinding;
private final Supplier<String> supplyInstanceId;
private final LongFunction<BudgetDebitor> supplyDebitor;
Expand All @@ -298,7 +299,8 @@ public KafkaClientGroupFactory(
LongFunction<BudgetDebitor> supplyDebitor,
Signaler signaler,
BindingHandler streamFactory,
UnaryOperator<KafkaSaslConfig> resolveSasl)
UnaryOperator<KafkaSaslConfig> resolveSasl,
LongFunction<KafkaClientRoute> supplyClientRoute)
{
super(config, context);
this.rebalanceTimeout = config.clientGroupRebalanceTimeout();
Expand All @@ -315,6 +317,7 @@ public KafkaClientGroupFactory(
this.signaler = signaler;
this.streamFactory = streamFactory;
this.resolveSasl = resolveSasl;
this.supplyClientRoute = supplyClientRoute;
this.instanceIds = new Long2ObjectHashMap<>();
this.groupStreams = new Object2ObjectHashMap<>();
this.configs = new LinkedHashMap<>();
Expand Down Expand Up @@ -2702,8 +2705,26 @@ private void doNetworkBegin(

state = KafkaState.openingInitial(state);

Consumer<OctetsFW.Builder> extension = EMPTY_EXTENSION;

final KafkaClientRoute clientRoute = supplyClientRoute.apply(routedId);
final KafkaBrokerInfo broker = clientRoute.brokers.get(Long.parseLong(delegate.nodeId));
if (broker != null)
{
extension = e -> e.set((b, o, l) -> proxyBeginExRW.wrap(b, o, l)
.typeId(proxyTypeId)
.address(a -> a.inet(i -> i.protocol(p -> p.set(STREAM))
.source("0.0.0.0")
.destination(broker.host)
.sourcePort(0)
.destinationPort(broker.port)))
.infos(i -> i.item(ii -> ii.authority(broker.host)))
.build()
.sizeof());
}

network = newStream(this::onNetwork, originId, routedId, initialId, initialSeq, initialAck, initialMax,
traceId, authorization, affinity, EMPTY_EXTENSION);
traceId, authorization, affinity, extension);
}

@Override
Expand Down Expand Up @@ -3470,6 +3491,7 @@ private void doNetworkBegin(
.destination(delegate.host)
.sourcePort(0)
.destinationPort(delegate.port)))
.infos(i -> i.item(ii -> ii.authority(delegate.host)))
.build()
.sizeof());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,7 @@ private void doNetworkBegin(
.destination(broker.host)
.sourcePort(0)
.destinationPort(broker.port)))
.infos(i -> i.item(ii -> ii.authority(broker.host)))
.build()
.sizeof());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public SSLEngine newClientEngine(
engine.setUseClientMode(true);

List<String> sni = options.sni;
if (sni == null && beginEx != null)
if (beginEx != null)
{
ProxyInfoFW info = beginEx.infos().matchFirst(a -> a.kind() == AUTHORITY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -98,6 +98,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -112,6 +112,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -70,6 +70,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -70,6 +70,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -70,6 +70,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -70,6 +70,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -70,6 +70,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -70,6 +70,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -70,6 +70,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ write zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ write 97 # size

accepted

read zilla:begin.ext ${proxy:beginEx()
read zilla:begin.ext ${proxy:matchBeginEx()
.typeId(zilla:id("proxy"))
.addressInet()
.protocol("stream")
Expand All @@ -70,6 +70,9 @@ read zilla:begin.ext ${proxy:beginEx()
.sourcePort(0)
.destinationPort(9092)
.build()
.info()
.authority("broker1.example.com")
.build()
.build()}

connected
Expand Down
Loading