Skip to content

Commit 7a07752

Browse files
committed
xds: Use separate key for ATTR_ADDRESS_NAME on a subchannel
XdsInternalAttributes.ATTR_ADDRESS_NAME is annotated with `@EquivalentAddressGroup.Attr`, so it should only be used in the EAG.
1 parent 2b9509e commit 7a07752

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ final class ClusterImplLoadBalancer extends LoadBalancer {
8787

8888
private static final Attributes.Key<AtomicReference<ClusterLocality>> ATTR_CLUSTER_LOCALITY =
8989
Attributes.Key.create("io.grpc.xds.ClusterImplLoadBalancer.clusterLocality");
90+
@VisibleForTesting
91+
static final Attributes.Key<String> ATTR_SUBCHANNEL_ADDRESS_NAME =
92+
Attributes.Key.create("io.grpc.xds.ClusterImplLoadBalancer.addressName");
9093

9194
private final XdsLogger logger;
9295
private final Helper helper;
@@ -243,7 +246,7 @@ public Subchannel createSubchannel(CreateSubchannelArgs args) {
243246
String hostname = args.getAddresses().get(0).getAttributes()
244247
.get(XdsInternalAttributes.ATTR_ADDRESS_NAME);
245248
if (hostname != null) {
246-
attrsBuilder.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, hostname);
249+
attrsBuilder.set(ATTR_SUBCHANNEL_ADDRESS_NAME, hostname);
247250
}
248251
}
249252
args = args.toBuilder().setAddresses(addresses).setAttributes(attrsBuilder.build()).build();
@@ -442,8 +445,7 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
442445
&& args.getCallOptions().getOption(XdsNameResolver.AUTO_HOST_REWRITE_KEY)) {
443446
result = PickResult.withSubchannel(result.getSubchannel(),
444447
result.getStreamTracerFactory(),
445-
result.getSubchannel().getAttributes().get(
446-
XdsInternalAttributes.ATTR_ADDRESS_NAME));
448+
result.getSubchannel().getAttributes().get(ATTR_SUBCHANNEL_ADDRESS_NAME));
447449
}
448450
}
449451
return result;

xds/src/test/java/io/grpc/xds/ClusterImplLoadBalancerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.Preconditions.checkNotNull;
2020
import static com.google.common.truth.Truth.assertThat;
2121
import static com.google.common.truth.Truth.assertWithMessage;
22+
import static io.grpc.xds.ClusterImplLoadBalancer.ATTR_SUBCHANNEL_ADDRESS_NAME;
2223
import static io.grpc.xds.XdsNameResolver.AUTO_HOST_REWRITE_KEY;
2324
import static org.mockito.ArgumentMatchers.anyInt;
2425
import static org.mockito.Mockito.mock;
@@ -909,7 +910,7 @@ public void endpointAddressesAttachedWithClusterName() {
909910
new FixedResultPicker(PickResult.withSubchannel(subchannel)));
910911
}
911912
});
912-
assertThat(subchannel.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME)).isEqualTo(
913+
assertThat(subchannel.getAttributes().get(ATTR_SUBCHANNEL_ADDRESS_NAME)).isEqualTo(
913914
"authority-host-name");
914915
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
915916
assertThat(eag.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME))
@@ -961,7 +962,7 @@ public void endpointAddressesAttachedWithClusterName() {
961962
}
962963
});
963964
// Sub Channel wrapper args won't have the address name although addresses will.
964-
assertThat(subchannel.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME)).isNull();
965+
assertThat(subchannel.getAttributes().get(ATTR_SUBCHANNEL_ADDRESS_NAME)).isNull();
965966
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
966967
assertThat(eag.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME))
967968
.isEqualTo("authority-host-name");

0 commit comments

Comments
 (0)