Skip to content

Commit 348a7a4

Browse files
committed
Use InternalXdsAttributes for exposing ATTR_ADDRESS_NAME to outside xds package.
1 parent 1c6066e commit 348a7a4

10 files changed

+25
-45
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import io.grpc.xds.client.XdsClient;
5454
import io.grpc.xds.client.XdsLogger;
5555
import io.grpc.xds.client.XdsLogger.XdsLogLevel;
56-
import io.grpc.xds.internal.XdsInternalAttributes;
5756
import io.grpc.xds.internal.security.SecurityProtocolNegotiators;
5857
import io.grpc.xds.internal.security.SslContextProviderSupplier;
5958
import io.grpc.xds.orca.OrcaPerRequestUtil;
@@ -242,9 +241,9 @@ public Subchannel createSubchannel(CreateSubchannelArgs args) {
242241
.set(ATTR_CLUSTER_LOCALITY, localityAtomicReference);
243242
if (GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE", false)) {
244243
String hostname = args.getAddresses().get(0).getAttributes()
245-
.get(XdsInternalAttributes.ATTR_ADDRESS_NAME);
244+
.get(XdsAttributes.ATTR_ADDRESS_NAME);
246245
if (hostname != null) {
247-
attrsBuilder.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, hostname);
246+
attrsBuilder.set(XdsAttributes.ATTR_ADDRESS_NAME, hostname);
248247
}
249248
}
250249
args = args.toBuilder().setAddresses(addresses).setAttributes(attrsBuilder.build()).build();
@@ -440,7 +439,7 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
440439
result = PickResult.withSubchannel(result.getSubchannel(),
441440
result.getStreamTracerFactory(),
442441
result.getSubchannel().getAttributes().get(
443-
XdsInternalAttributes.ATTR_ADDRESS_NAME));
442+
XdsAttributes.ATTR_ADDRESS_NAME));
444443
}
445444
}
446445
return result;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import io.grpc.xds.client.Locality;
4848
import io.grpc.xds.client.XdsLogger;
4949
import io.grpc.xds.client.XdsLogger.XdsLogLevel;
50-
import io.grpc.xds.internal.XdsInternalAttributes;
5150
import java.net.InetSocketAddress;
5251
import java.net.SocketAddress;
5352
import java.util.ArrayList;
@@ -195,7 +194,7 @@ StatusOr<ClusterResolutionResult> edsUpdateToResult(
195194
.set(XdsAttributes.ATTR_LOCALITY_WEIGHT,
196195
localityLbInfo.localityWeight())
197196
.set(XdsAttributes.ATTR_SERVER_WEIGHT, weight)
198-
.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, endpoint.hostname())
197+
.set(XdsAttributes.ATTR_ADDRESS_NAME, endpoint.hostname())
199198
.build();
200199
EquivalentAddressGroup eag;
201200
if (config.isHttp11ProxyAvailable()) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ public final class InternalXdsAttributes {
3232
public static final Attributes.Key<String> ATTR_CLUSTER_NAME =
3333
XdsAttributes.ATTR_CLUSTER_NAME;
3434

35+
/** Name associated with individual address, if available (e.g., DNS name). */
36+
@EquivalentAddressGroup.Attr
37+
public static final Attributes.Key<String> ATTR_ADDRESS_NAME = XdsAttributes.ATTR_ADDRESS_NAME;
38+
3539
private InternalXdsAttributes() {}
3640
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ final class XdsAttributes {
8888
static final Attributes.Key<Long> ATTR_SERVER_WEIGHT =
8989
Attributes.Key.create("io.grpc.xds.XdsAttributes.serverWeight");
9090

91+
/** Name associated with individual address, if available (e.g., DNS name). */
92+
@EquivalentAddressGroup.Attr
93+
static final Attributes.Key<String> ATTR_ADDRESS_NAME =
94+
Attributes.Key.create("io.grpc.xds.XdsAttributes.addressName");
95+
9196
/**
9297
* Filter chain match for network filters.
9398
*/

xds/src/main/java/io/grpc/xds/internal/XdsInternalAttributes.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

xds/src/main/java/io/grpc/xds/internal/security/SecurityProtocolNegotiators.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import io.grpc.netty.ProtocolNegotiationEvent;
3434
import io.grpc.xds.EnvoyServerProtoData;
3535
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
36-
import io.grpc.xds.internal.XdsInternalAttributes;
36+
import io.grpc.xds.InternalXdsAttributes;
3737
import io.grpc.xds.internal.security.trust.CertificateUtils;
3838
import io.netty.channel.ChannelHandler;
3939
import io.netty.channel.ChannelHandlerAdapter;
@@ -151,7 +151,7 @@ public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
151151
return fallbackProtocolNegotiator.newHandler(grpcHandler);
152152
}
153153
return new ClientSecurityHandler(grpcHandler, localSslContextProviderSupplier,
154-
grpcHandler.getEagAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME));
154+
grpcHandler.getEagAttributes().get(InternalXdsAttributes.ATTR_ADDRESS_NAME));
155155
}
156156

157157
@Override

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,10 +812,10 @@ public void endpointAddressesAttachedWithClusterName() {
812812
new FixedResultPicker(PickResult.withSubchannel(subchannel)));
813813
}
814814
});
815-
assertThat(subchannel.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME)).isEqualTo(
815+
assertThat(subchannel.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo(
816816
"authority-host-name");
817817
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
818-
assertThat(eag.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME))
818+
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME))
819819
.isEqualTo("authority-host-name");
820820
}
821821

@@ -864,9 +864,9 @@ public void endpointAddressesAttachedWithClusterName() {
864864
}
865865
});
866866
// Sub Channel wrapper args won't have the address name although addresses will.
867-
assertThat(subchannel.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME)).isNull();
867+
assertThat(subchannel.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME)).isNull();
868868
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
869-
assertThat(eag.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME))
869+
assertThat(eag.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME))
870870
.isEqualTo("authority-host-name");
871871
}
872872

@@ -1020,7 +1020,7 @@ public String toString() {
10201020
// Unique but arbitrary string
10211021
.set(EquivalentAddressGroup.ATTR_LOCALITY_NAME, locality.toString());
10221022
if (authorityHostname != null) {
1023-
attributes.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, authorityHostname);
1023+
attributes.set(XdsAttributes.ATTR_ADDRESS_NAME, authorityHostname);
10241024
}
10251025
EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress(name),
10261026
attributes.build());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public void edsClustersEndpointHostname_addedToAddressAttribute() {
409409

410410
assertThat(
411411
childBalancer.addresses.get(0).getAttributes()
412-
.get(XdsInternalAttributes.ATTR_ADDRESS_NAME)).isEqualTo("hostname1");
412+
.get(XdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo("hostname1");
413413
}
414414

415415
@Test
@@ -898,7 +898,7 @@ public void onlyLogicalDnsCluster_endpointsResolved() {
898898
newInetSocketAddress("127.0.2.1", 9000), newInetSocketAddress("127.0.2.2", 9000)))),
899899
childBalancer.addresses);
900900
assertThat(childBalancer.addresses.get(0).getAttributes()
901-
.get(XdsInternalAttributes.ATTR_ADDRESS_NAME)).isEqualTo(DNS_HOST_NAME + ":9000");
901+
.get(XdsAttributes.ATTR_ADDRESS_NAME)).isEqualTo(DNS_HOST_NAME + ":9000");
902902
}
903903

904904
@Test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ private SimpleServiceGrpc.SimpleServiceBlockingStub getBlockingStub(
840840
upstreamTlsContext, tlsContextManagerForClient))
841841
: Attributes.newBuilder();
842842
if (addrNameAttribute != null) {
843-
sslContextAttributesBuilder.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, addrNameAttribute);
843+
sslContextAttributesBuilder.set(XdsAttributes.ATTR_ADDRESS_NAME, addrNameAttribute);
844844
}
845845
sslContextAttributes = sslContextAttributesBuilder.build();
846846
fakeNameResolverFactory.setServers(

xds/src/test/java/io/grpc/xds/internal/security/SecurityProtocolNegotiatorsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import io.grpc.netty.ProtocolNegotiationEvent;
4949
import io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext;
5050
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
51-
import io.grpc.xds.TlsContextManager;
51+
import io.grpc.xds.InternalXdsAttributes;import io.grpc.xds.TlsContextManager;
5252
import io.grpc.xds.client.Bootstrapper;
5353
import io.grpc.xds.client.CommonBootstrapperTestUtils;
5454
import io.grpc.xds.internal.XdsInternalAttributes;
@@ -169,7 +169,7 @@ public void clientSecurityProtocolNegotiatorNewHandler_autoHostSni_hostnameIsPas
169169
Attributes.newBuilder()
170170
.set(SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
171171
new SslContextProviderSupplier(upstreamTlsContext, mockTlsContextManager))
172-
.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, FAKE_AUTHORITY)
172+
.set(InternalXdsAttributes.ATTR_ADDRESS_NAME, FAKE_AUTHORITY)
173173
.build());
174174
ChannelHandler newHandler = pn.newHandler(mockHandler);
175175
assertThat(newHandler).isNotNull();

0 commit comments

Comments
 (0)