Skip to content

Commit

Permalink
Fix agent consul forwarder discovery
Browse files Browse the repository at this point in the history
Prefer usage of service host qhen available. With IP per container, it is not relevant to use the node host.
  • Loading branch information
w.montaz committed Jul 22, 2024
1 parent c189855 commit 25bb5c8
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,20 @@ private List<HealthService> getHealthyEndPoints() {
@Override
public void establishConnection() {
for (; ; ) {
List<HealthService> nodes = getHealthyEndPoints();
List<HealthService> healthServices = getHealthyEndPoints();

HealthService electedNode = nodes.get(ThreadLocalRandom.current().nextInt(nodes.size()));
HealthService randomHealthyService = healthServices.get(ThreadLocalRandom.current().nextInt(healthServices.size()));

String host = electedNode.getNode().getAddress();
Integer port = electedNode.getService().getPort();
String nodeHost = randomHealthyService.getNode().getAddress();
String serviceHost = randomHealthyService.getService().getAddress();

String host;
if (serviceHost.isEmpty()) {
host = nodeHost;
} else {
host = serviceHost;
}
Integer port = randomHealthyService.getService().getPort();

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("will use forwarder at " + host + ":" + port);
Expand Down

0 comments on commit 25bb5c8

Please sign in to comment.