Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/src/main/java/io/grpc/EquivalentAddressGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public final class EquivalentAddressGroup {
@Attr
static final Attributes.Key<Long> ATTR_WEIGHT =
Attributes.Key.create("io.grpc.EquivalentAddressGroup.ATTR_WEIGHT");
/**
* Name associated with individual address, if available (e.g., DNS name).
*/
@Attr
static final Attributes.Key<String> ATTR_ADDRESS_NAME =
Attributes.Key.create("io.grpc.EquivalentAddressGroup.ATTR_ADDRESS_NAME");

private final List<SocketAddress> addrs;
private final Attributes attrs;
Expand Down
6 changes: 6 additions & 0 deletions api/src/main/java/io/grpc/InternalEquivalentAddressGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ private InternalEquivalentAddressGroup() {}
*/
public static final Attributes.Key<String> ATTR_BACKEND_SERVICE =
EquivalentAddressGroup.ATTR_BACKEND_SERVICE;

/**
* Name associated with individual address, if available (e.g., DNS name).
*/
public static final Attributes.Key<String> ATTR_ADDRESS_NAME =

@ejona86 ejona86 Sep 24, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this exist? Can't all callers of this use EquivalentAddressGroup directly?

The point of this class is if there's something we don't want to make public API. So it would be useful if the attribute wasn't in EAG at all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in the follow-up: #13076

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nm. I failed to notice it wasn't public in EAG.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then you also said

So it would be useful if the attribute wasn't in EAG at all.

So we can keep it in internal only. What problem will it have?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What purpose does it serve defining in EAG at all?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When building with Bazel, we use a two-stage build and build Internal* files separately. So if this attribute was used in io.grpc itself, it can't use the Internal* copy. In this case it isn't used in io.grpc at all so it really doesn't matter, but the normal pattern is to just make Internal* accessors so it could be used in io.grpc.

EquivalentAddressGroup.ATTR_ADDRESS_NAME;
}
3 changes: 1 addition & 2 deletions xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import io.grpc.xds.client.Locality;
import io.grpc.xds.client.XdsLogger;
import io.grpc.xds.client.XdsLogger.XdsLogLevel;
import io.grpc.xds.internal.XdsInternalAttributes;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
Expand Down Expand Up @@ -417,7 +416,7 @@ StatusOr<ClusterResolutionResult> edsUpdateToResult(
.set(io.grpc.xds.XdsAttributes.ATTR_LOCALITY_WEIGHT,
localityLbInfo.localityWeight())
.set(io.grpc.xds.XdsAttributes.ATTR_SERVER_WEIGHT, weight)
.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, endpoint.hostname())
.set(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME, endpoint.hostname())
.set(AddressFilter.PATH_CHAIN_KEY, pathChain)
.build();
EquivalentAddressGroup eag;
Expand Down
4 changes: 2 additions & 2 deletions xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.grpc.ConnectivityState;
import io.grpc.ConnectivityStateInfo;
import io.grpc.EquivalentAddressGroup;
import io.grpc.InternalEquivalentAddressGroup;
import io.grpc.InternalLogId;
import io.grpc.LoadBalancer;
import io.grpc.Metadata;
Expand All @@ -53,7 +54,6 @@
import io.grpc.xds.client.XdsClient;
import io.grpc.xds.client.XdsLogger;
import io.grpc.xds.client.XdsLogger.XdsLogLevel;
import io.grpc.xds.internal.XdsInternalAttributes;
import io.grpc.xds.internal.security.SecurityProtocolNegotiators;
import io.grpc.xds.internal.security.SslContextProviderSupplier;
import io.grpc.xds.orca.OrcaPerRequestUtil;
Expand Down Expand Up @@ -240,7 +240,7 @@ public Subchannel createSubchannel(CreateSubchannelArgs args) {
.set(ATTR_CLUSTER_LOCALITY, localityAtomicReference);
if (GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE", false)) {
String hostname = args.getAddresses().get(0).getAttributes()
.get(XdsInternalAttributes.ATTR_ADDRESS_NAME);
.get(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME);
if (hostname != null) {
attrsBuilder.set(ATTR_SUBCHANNEL_ADDRESS_NAME, hostname);
}
Expand Down
27 changes: 0 additions & 27 deletions xds/src/main/java/io/grpc/xds/internal/XdsInternalAttributes.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.base.Strings;
import io.grpc.Attributes;
import io.grpc.Grpc;
import io.grpc.InternalEquivalentAddressGroup;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.ObjectPool;
import io.grpc.netty.GrpcHttp2ConnectionHandler;
Expand All @@ -32,7 +33,6 @@
import io.grpc.netty.ProtocolNegotiationEvent;
import io.grpc.xds.EnvoyServerProtoData;
import io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext;
import io.grpc.xds.internal.XdsInternalAttributes;
import io.grpc.xds.internal.security.trust.CertificateUtils;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
Expand Down Expand Up @@ -150,7 +150,7 @@ public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
return fallbackProtocolNegotiator.newHandler(grpcHandler);
}
return new ClientSecurityHandler(grpcHandler, localSslContextProviderSupplier,
grpcHandler.getEagAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME));
grpcHandler.getEagAttributes().get(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.grpc.ConnectivityStateInfo;
import io.grpc.EquivalentAddressGroup;
import io.grpc.InsecureChannelCredentials;
import io.grpc.InternalEquivalentAddressGroup;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.CreateSubchannelArgs;
import io.grpc.LoadBalancer.FixedResultPicker;
Expand Down Expand Up @@ -81,7 +82,6 @@
import io.grpc.xds.client.Stats.ClusterStats;
import io.grpc.xds.client.Stats.UpstreamLocalityStats;
import io.grpc.xds.client.XdsClient;
import io.grpc.xds.internal.XdsInternalAttributes;
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
import io.grpc.xds.internal.security.SecurityProtocolNegotiators;
import io.grpc.xds.internal.security.SslContextProvider;
Expand Down Expand Up @@ -917,7 +917,7 @@ public void endpointAddressesAttachedWithClusterName() {
assertThat(subchannel.getAttributes().get(ATTR_SUBCHANNEL_ADDRESS_NAME)).isEqualTo(
"authority-host-name");
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
assertThat(eag.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME))
assertThat(eag.getAttributes().get(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME))
.isEqualTo("authority-host-name");
}

Expand Down Expand Up @@ -968,7 +968,7 @@ public void endpointAddressesAttachedWithClusterName() {
// Sub Channel wrapper args won't have the address name although addresses will.
assertThat(subchannel.getAttributes().get(ATTR_SUBCHANNEL_ADDRESS_NAME)).isNull();
for (EquivalentAddressGroup eag : subchannel.getAllAddresses()) {
assertThat(eag.getAttributes().get(XdsInternalAttributes.ATTR_ADDRESS_NAME))
assertThat(eag.getAttributes().get(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME))
.isEqualTo("authority-host-name");
}

Expand Down Expand Up @@ -1123,7 +1123,7 @@ public String toString() {
// Unique but arbitrary string
.set(EquivalentAddressGroup.ATTR_LOCALITY_NAME, locality.toString());
if (authorityHostname != null) {
attributes.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, authorityHostname);
attributes.set(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME, authorityHostname);
}
EquivalentAddressGroup eag = new EquivalentAddressGroup(new FakeSocketAddress(name),
attributes.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
import io.grpc.xds.client.Bootstrapper.ServerInfo;
import io.grpc.xds.client.LoadStatsManager2;
import io.grpc.xds.client.XdsClient;
import io.grpc.xds.internal.XdsInternalAttributes;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.ArrayList;
Expand Down Expand Up @@ -428,7 +427,7 @@ public void edsClustersEndpointHostname_addedToAddressAttribute() {

assertThat(
childBalancer.addresses.get(0).getAttributes()
.get(XdsInternalAttributes.ATTR_ADDRESS_NAME)).isEqualTo("hostname1");
.get(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME)).isEqualTo("hostname1");
}

@Test
Expand Down Expand Up @@ -931,7 +930,7 @@ public void onlyLogicalDnsCluster_endpointsResolved() {
assertThat(childBalancer.addresses.get(0).getAttributes()
.get(InternalEquivalentAddressGroup.ATTR_BACKEND_SERVICE)).isEqualTo(CLUSTER);
assertThat(childBalancer.addresses.get(0).getAttributes()
.get(XdsInternalAttributes.ATTR_ADDRESS_NAME)).isEqualTo(DNS_HOST_NAME + ":9000");
.get(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME)).isEqualTo(DNS_HOST_NAME + ":9000");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.grpc.Grpc;
import io.grpc.InsecureChannelCredentials;
import io.grpc.InsecureServerCredentials;
import io.grpc.InternalEquivalentAddressGroup;
import io.grpc.ManagedChannelBuilder;
import io.grpc.NameResolver;
import io.grpc.NameResolverProvider;
Expand Down Expand Up @@ -71,7 +72,6 @@
import io.grpc.xds.client.Bootstrapper;
import io.grpc.xds.client.CommonBootstrapperTestUtils;
import io.grpc.xds.internal.Matchers.HeaderMatcher;
import io.grpc.xds.internal.XdsInternalAttributes;
import io.grpc.xds.internal.security.CommonTlsContextTestsUtil;
import io.grpc.xds.internal.security.SecurityProtocolNegotiators;
import io.grpc.xds.internal.security.SslContextProviderSupplier;
Expand Down Expand Up @@ -843,7 +843,8 @@ private SimpleServiceGrpc.SimpleServiceBlockingStub getBlockingStub(
upstreamTlsContext, tlsContextManagerForClient))
: Attributes.newBuilder();
if (addrNameAttribute != null) {
sslContextAttributesBuilder.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, addrNameAttribute);
sslContextAttributesBuilder.set(
InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME, addrNameAttribute);
}
sslContextAttributes = sslContextAttributesBuilder.build();
fakeNameResolverFactory.setServers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.grpc.Attributes;
import io.grpc.ChannelLogger;
import io.grpc.ChannelLogger.ChannelLogLevel;
import io.grpc.InternalEquivalentAddressGroup;
import io.grpc.internal.FakeClock;
import io.grpc.internal.TestUtils.NoopChannelLogger;
import io.grpc.netty.GrpcHttp2ConnectionHandler;
Expand All @@ -50,7 +51,6 @@
import io.grpc.xds.TlsContextManager;
import io.grpc.xds.client.Bootstrapper;
import io.grpc.xds.client.CommonBootstrapperTestUtils;
import io.grpc.xds.internal.XdsInternalAttributes;
import io.grpc.xds.internal.security.SecurityProtocolNegotiators.ClientSecurityHandler;
import io.grpc.xds.internal.security.SecurityProtocolNegotiators.ClientSecurityProtocolNegotiator;
import io.grpc.xds.internal.security.certprovider.CommonCertProviderTestUtils;
Expand Down Expand Up @@ -165,7 +165,7 @@ public void clientSecurityProtocolNegotiator_autoHostSni_hostnamePassedToClientS
Attributes.newBuilder()
.set(SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
new SslContextProviderSupplier(upstreamTlsContext, mockTlsContextManager))
.set(XdsInternalAttributes.ATTR_ADDRESS_NAME, FAKE_AUTHORITY)
.set(InternalEquivalentAddressGroup.ATTR_ADDRESS_NAME, FAKE_AUTHORITY)
.build());
ChannelHandler newHandler = pn.newHandler(mockHandler);
assertThat(newHandler).isNotNull();
Expand Down
Loading