xds: eliminate target name dependency in XdsClient and LRS client (#7498)

This commit is contained in:
Chengyuan Zhang 2020-10-08 17:23:46 -07:00 committed by GitHub
parent 0203256171
commit df95acda2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 6 additions and 20 deletions

View File

@ -71,7 +71,6 @@ final class LoadReportClient {
private LrsStream lrsStream; private LrsStream lrsStream;
LoadReportClient( LoadReportClient(
String targetName,
LoadStatsManager loadStatsManager, LoadStatsManager loadStatsManager,
XdsChannel xdsChannel, XdsChannel xdsChannel,
Node node, Node node,
@ -87,7 +86,7 @@ final class LoadReportClient {
this.retryStopwatch = checkNotNull(stopwatchSupplier, "stopwatchSupplier").get(); this.retryStopwatch = checkNotNull(stopwatchSupplier, "stopwatchSupplier").get();
this.node = checkNotNull(node, "node").toBuilder() this.node = checkNotNull(node, "node").toBuilder()
.addClientFeatures("envoy.lrs.supports_send_all_clusters").build(); .addClientFeatures("envoy.lrs.supports_send_all_clusters").build();
logId = InternalLogId.allocate("lrs-client", targetName); logId = InternalLogId.allocate("lrs-client", null);
logger = XdsLogger.withLogId(logId); logger = XdsLogger.withLogId(logId);
logger.log(XdsLogLevel.INFO, "Created"); logger.log(XdsLogLevel.INFO, "Created");
} }

View File

@ -104,7 +104,6 @@ final class XdsClientImpl2 extends XdsClient {
private final MessagePrinter respPrinter = new MessagePrinter(); private final MessagePrinter respPrinter = new MessagePrinter();
private final InternalLogId logId; private final InternalLogId logId;
private final XdsLogger logger; private final XdsLogger logger;
private final String targetName; // TODO: delete me.
private final XdsChannel xdsChannel; private final XdsChannel xdsChannel;
private final SynchronizationContext syncContext; private final SynchronizationContext syncContext;
private final ScheduledExecutorService timeService; private final ScheduledExecutorService timeService;
@ -149,14 +148,12 @@ final class XdsClientImpl2 extends XdsClient {
private ScheduledHandle ldsRespTimer; private ScheduledHandle ldsRespTimer;
XdsClientImpl2( XdsClientImpl2(
String targetName,
XdsChannel channel, XdsChannel channel,
Node node, Node node,
SynchronizationContext syncContext, SynchronizationContext syncContext,
ScheduledExecutorService timeService, ScheduledExecutorService timeService,
BackoffPolicy.Provider backoffPolicyProvider, BackoffPolicy.Provider backoffPolicyProvider,
Supplier<Stopwatch> stopwatchSupplier) { Supplier<Stopwatch> stopwatchSupplier) {
this.targetName = checkNotNull(targetName, "targetName");
this.xdsChannel = checkNotNull(channel, "channel"); this.xdsChannel = checkNotNull(channel, "channel");
this.node = checkNotNull(node, "node"); this.node = checkNotNull(node, "node");
this.syncContext = checkNotNull(syncContext, "syncContext"); this.syncContext = checkNotNull(syncContext, "syncContext");
@ -344,7 +341,6 @@ final class XdsClientImpl2 extends XdsClient {
logger.log(XdsLogLevel.INFO, "Turning on load reporting"); logger.log(XdsLogLevel.INFO, "Turning on load reporting");
lrsClient = lrsClient =
new LoadReportClient( new LoadReportClient(
targetName,
loadStatsManager, loadStatsManager,
xdsChannel, xdsChannel,
node, node,

View File

@ -137,7 +137,6 @@ public final class XdsClientWrapperForServerSds {
timeService = SharedResourceHolder.get(timeServiceResource); timeService = SharedResourceHolder.get(timeServiceResource);
XdsClientImpl2 xdsClientImpl = XdsClientImpl2 xdsClientImpl =
new XdsClientImpl2( new XdsClientImpl2(
"",
channel, channel,
node, node,
createSynchronizationContext(), createSynchronizationContext(),

View File

@ -62,9 +62,9 @@ public final class XdsNameResolverProvider extends NameResolverProvider {
targetUri); targetUri);
String name = targetPath.substring(1); String name = targetPath.substring(1);
XdsClientPoolFactory xdsClientPoolFactory = XdsClientPoolFactory xdsClientPoolFactory =
new RefCountedXdsClientPoolFactory( new RefCountedXdsClientPoolFactory(args.getSynchronizationContext(),
name, args.getSynchronizationContext(), args.getScheduledExecutorService(), args.getScheduledExecutorService(), new ExponentialBackoffPolicy.Provider(),
new ExponentialBackoffPolicy.Provider(), GrpcUtil.STOPWATCH_SUPPLIER); GrpcUtil.STOPWATCH_SUPPLIER);
return new XdsNameResolver( return new XdsNameResolver(
name, args.getServiceConfigParser(), name, args.getServiceConfigParser(),
args.getSynchronizationContext(), xdsClientPoolFactory); args.getSynchronizationContext(), xdsClientPoolFactory);
@ -90,19 +90,16 @@ public final class XdsNameResolverProvider extends NameResolverProvider {
} }
static class RefCountedXdsClientPoolFactory implements XdsClientPoolFactory { static class RefCountedXdsClientPoolFactory implements XdsClientPoolFactory {
private final String serviceName;
private final SynchronizationContext syncContext; private final SynchronizationContext syncContext;
private final ScheduledExecutorService timeService; private final ScheduledExecutorService timeService;
private final BackoffPolicy.Provider backoffPolicyProvider; private final BackoffPolicy.Provider backoffPolicyProvider;
private final Supplier<Stopwatch> stopwatchSupplier; private final Supplier<Stopwatch> stopwatchSupplier;
RefCountedXdsClientPoolFactory( RefCountedXdsClientPoolFactory(
String serviceName,
SynchronizationContext syncContext, SynchronizationContext syncContext,
ScheduledExecutorService timeService, ScheduledExecutorService timeService,
BackoffPolicy.Provider backoffPolicyProvider, BackoffPolicy.Provider backoffPolicyProvider,
Supplier<Stopwatch> stopwatchSupplier) { Supplier<Stopwatch> stopwatchSupplier) {
this.serviceName = checkNotNull(serviceName, "serviceName");
this.syncContext = checkNotNull(syncContext, "syncContext"); this.syncContext = checkNotNull(syncContext, "syncContext");
this.timeService = checkNotNull(timeService, "timeService"); this.timeService = checkNotNull(timeService, "timeService");
this.backoffPolicyProvider = checkNotNull(backoffPolicyProvider, "backoffPolicyProvider"); this.backoffPolicyProvider = checkNotNull(backoffPolicyProvider, "backoffPolicyProvider");
@ -115,8 +112,7 @@ public final class XdsNameResolverProvider extends NameResolverProvider {
XdsClientFactory xdsClientFactory = new XdsClientFactory() { XdsClientFactory xdsClientFactory = new XdsClientFactory() {
@Override @Override
XdsClient createXdsClient() { XdsClient createXdsClient() {
return new XdsClientImpl2( return new XdsClientImpl2(channel, bootstrapInfo.getNode(), syncContext, timeService,
serviceName, channel, bootstrapInfo.getNode(), syncContext, timeService,
backoffPolicyProvider, stopwatchSupplier); backoffPolicyProvider, stopwatchSupplier);
} }
}; };

View File

@ -87,7 +87,6 @@ import org.mockito.MockitoAnnotations;
*/ */
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class LoadReportClientTest { public class LoadReportClientTest {
private static final String TARGET_NAME = "lrs-test.example.com";
// bootstrap node identifier // bootstrap node identifier
private static final EnvoyProtoData.Node NODE = private static final EnvoyProtoData.Node NODE =
EnvoyProtoData.Node.newBuilder() EnvoyProtoData.Node.newBuilder()
@ -185,7 +184,6 @@ public class LoadReportClientTest {
.thenReturn(TimeUnit.SECONDS.toNanos(2L), TimeUnit.SECONDS.toNanos(20L)); .thenReturn(TimeUnit.SECONDS.toNanos(2L), TimeUnit.SECONDS.toNanos(20L));
lrsClient = lrsClient =
new LoadReportClient( new LoadReportClient(
TARGET_NAME,
loadStatsManager, loadStatsManager,
new XdsChannel(channel, false), new XdsChannel(channel, false),
NODE, NODE,

View File

@ -120,7 +120,6 @@ import org.mockito.MockitoAnnotations;
*/ */
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class XdsClientImplTest2 { public class XdsClientImplTest2 {
private static final String TARGET_NAME = "hello.googleapis.com";
private static final String LDS_RESOURCE = "listener.googleapis.com"; private static final String LDS_RESOURCE = "listener.googleapis.com";
private static final String RDS_RESOURCE = "route-configuration.googleapis.com"; private static final String RDS_RESOURCE = "route-configuration.googleapis.com";
private static final String CDS_RESOURCE = "cluster.googleapis.com"; private static final String CDS_RESOURCE = "cluster.googleapis.com";
@ -277,7 +276,6 @@ public class XdsClientImplTest2 {
xdsClient = xdsClient =
new XdsClientImpl2( new XdsClientImpl2(
TARGET_NAME,
new XdsChannel(channel, /* useProtocolV3= */ true), new XdsChannel(channel, /* useProtocolV3= */ true),
EnvoyProtoData.Node.newBuilder().build(), EnvoyProtoData.Node.newBuilder().build(),
syncContext, syncContext,

View File

@ -196,7 +196,7 @@ public class XdsClientImplTestForListener {
cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()); cleanupRule.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
xdsClient = xdsClient =
new XdsClientImpl2("", new XdsChannel(channel, /* useProtocolV3= */ false), NODE, new XdsClientImpl2(new XdsChannel(channel, /* useProtocolV3= */ false), NODE,
syncContext, fakeClock.getScheduledExecutorService(), backoffPolicyProvider, syncContext, fakeClock.getScheduledExecutorService(), backoffPolicyProvider,
fakeClock.getStopwatchSupplier()); fakeClock.getStopwatchSupplier());
// Only the connection to management server is established, no RPC request is sent until at // Only the connection to management server is established, no RPC request is sent until at