Skip to content

Commit

Permalink
Introduce new config to randomly pick the xDS server host (#972)
Browse files Browse the repository at this point in the history
* Introduce new config to randomly pick the xDS server host

Instead of using the default "pick_first" policy, which always picks the first
IP address returned by DNS, "round_robin" will pick a random starting point in
the list of IPs. This will fix the very lopsided load seen on the xDS servers.

* Make policy configurable

* Bump version, update changelog

* Add log, update changelog
  • Loading branch information
PapaCharlie authored Jan 30, 2024
1 parent b46fed4 commit 46d142b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and what APIs have changed, if applicable.

## [Unreleased]

## [29.49.9] - 2024-01-26
- Introduce new config to randomly pick the xDS server host

## [29.49.8] - 2024-01-19
- add WIRE_COMPATIBLE compatility checker mode.

Expand Down Expand Up @@ -5618,7 +5621,8 @@ patch operations can re-use these classes for generating patch messages.

## [0.14.1]

[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.49.8...master
[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.49.9...master
[29.49.9]: https://github.com/linkedin/rest.li/compare/v29.49.8...v29.49.9
[29.49.8]: https://github.com/linkedin/rest.li/compare/v29.49.7...v29.49.8
[29.49.7]: https://github.com/linkedin/rest.li/compare/v29.49.6...v29.49.7
[29.49.6]: https://github.com/linkedin/rest.li/compare/v29.49.5...v29.49.6
Expand Down
44 changes: 41 additions & 3 deletions d2/src/main/java/com/linkedin/d2/xds/XdsChannelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,12 +30,40 @@ public class XdsChannelFactory
{
private static final Logger _log = LoggerFactory.getLogger(XdsChannelFactory.class);

public static final String ROUND_ROBIN_POLICY = "round_robin";

private final SslContext _sslContext;
private final String _xdsServerUri;
@Nullable
private final String _defaultLoadBalancingPolicy;

/**
* Invokes alternative constructor with {@code defaultLoadBalancingPolicy} as {@value ROUND_ROBIN_POLICY}.
*/
public XdsChannelFactory(SslContext sslContext, String xdsServerUri)
{
this(sslContext, xdsServerUri, ROUND_ROBIN_POLICY);
}

public XdsChannelFactory(SslContext sslContext, String xdsServerUri) {
/**
* @param sslContext The sslContext to use. If {@code null}, SSL will not be used when connecting to
* the xDS server.
* @param xdsServerUri The address of the xDS server. Can be an IP address or a domain with multiple
* underlying A/AAAA records.
* @param defaultLoadBalancingPolicy If provided, changes the default load balancing policy on the builder to the
* given policy (see
* {@link io.grpc.ManagedChannelBuilder#defaultLoadBalancingPolicy(String)}).
* @see <a href="https://daniel.haxx.se/blog/2012/01/03/getaddrinfo-with-round-robin-dns-and-happy-eyeballs/"/>
* Details on IPv6 routing.
*/
public XdsChannelFactory(
@Nullable SslContext sslContext,
String xdsServerUri,
@Nullable String defaultLoadBalancingPolicy)
{
_sslContext = sslContext;
_xdsServerUri = xdsServerUri;
_defaultLoadBalancingPolicy = defaultLoadBalancingPolicy;
}

public ManagedChannel createChannel()
Expand All @@ -46,13 +75,22 @@ public ManagedChannel createChannel()
}

NettyChannelBuilder builder = NettyChannelBuilder.forTarget(_xdsServerUri);
if (_defaultLoadBalancingPolicy != null)
{
_log.info("Applying custom load balancing policy for xDS channel: {}", _defaultLoadBalancingPolicy);
builder = builder.defaultLoadBalancingPolicy(_defaultLoadBalancingPolicy);
}

if (_sslContext != null) {
if (_sslContext != null)
{
builder.sslContext(_sslContext);
} else {
}
else
{
builder.usePlaintext();
}


return builder.keepAliveTime(5, TimeUnit.MINUTES)
// No proxy wanted here; the default proxy detector can mistakenly detect forwarded ports as proxies.
.proxyDetector(GrpcUtil.NOOP_PROXY_DETECTOR)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=29.49.8
version=29.49.9
group=com.linkedin.pegasus
org.gradle.configureondemand=true
org.gradle.parallel=true
Expand Down

0 comments on commit 46d142b

Please sign in to comment.