Skip to content

Commit 4a0f707

Browse files
committed
xds: Avoid depending on io.grpc.xds.Internal* classes
Internal* classes should generally be accessors that are used outside of the package/project. Only one attribute was used outside of xds, so leave only that one attribute in InternalXdsAttributes. One attribute was used by the internal.security package, so move the definition to the same package to reduce the circular dependencies.
1 parent 1cf1927 commit 4a0f707

20 files changed

+190
-158
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
8888
}
8989
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
9090
this.resolvedAddresses = resolvedAddresses;
91-
xdsClientPool = resolvedAddresses.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL);
91+
xdsClientPool = resolvedAddresses.getAttributes().get(XdsAttributes.XDS_CLIENT_POOL);
9292
xdsClient = xdsClientPool.getObject();
9393
CdsConfig config = (CdsConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
9494
logger.log(XdsLogLevel.INFO, "Config: {0}", config);

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import io.grpc.xds.client.XdsClient;
5353
import io.grpc.xds.client.XdsLogger;
5454
import io.grpc.xds.client.XdsLogger.XdsLogLevel;
55+
import io.grpc.xds.internal.security.SecurityProtocolNegotiators;
5556
import io.grpc.xds.internal.security.SslContextProviderSupplier;
5657
import io.grpc.xds.orca.OrcaPerRequestUtil;
5758
import io.grpc.xds.orca.OrcaPerRequestUtil.OrcaPerRequestReportListener;
@@ -114,12 +115,12 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
114115
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
115116
Attributes attributes = resolvedAddresses.getAttributes();
116117
if (xdsClientPool == null) {
117-
xdsClientPool = attributes.get(InternalXdsAttributes.XDS_CLIENT_POOL);
118+
xdsClientPool = attributes.get(XdsAttributes.XDS_CLIENT_POOL);
118119
assert xdsClientPool != null;
119120
xdsClient = xdsClientPool.getObject();
120121
}
121122
if (callCounterProvider == null) {
122-
callCounterProvider = attributes.get(InternalXdsAttributes.CALL_COUNTER_PROVIDER);
123+
callCounterProvider = attributes.get(XdsAttributes.CALL_COUNTER_PROVIDER);
123124
}
124125

125126
ClusterImplConfig config =
@@ -236,9 +237,9 @@ public Subchannel createSubchannel(CreateSubchannelArgs args) {
236237
.set(ATTR_CLUSTER_LOCALITY, localityAtomicReference);
237238
if (GrpcUtil.getFlag("GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE", false)) {
238239
String hostname = args.getAddresses().get(0).getAttributes()
239-
.get(InternalXdsAttributes.ATTR_ADDRESS_NAME);
240+
.get(XdsAttributes.ATTR_ADDRESS_NAME);
240241
if (hostname != null) {
241-
attrsBuilder.set(InternalXdsAttributes.ATTR_ADDRESS_NAME, hostname);
242+
attrsBuilder.set(XdsAttributes.ATTR_ADDRESS_NAME, hostname);
242243
}
243244
}
244245
args = args.toBuilder().setAddresses(addresses).setAttributes(attrsBuilder.build()).build();
@@ -287,10 +288,10 @@ private List<EquivalentAddressGroup> withAdditionalAttributes(
287288
List<EquivalentAddressGroup> newAddresses = new ArrayList<>();
288289
for (EquivalentAddressGroup eag : addresses) {
289290
Attributes.Builder attrBuilder = eag.getAttributes().toBuilder().set(
290-
InternalXdsAttributes.ATTR_CLUSTER_NAME, cluster);
291+
XdsAttributes.ATTR_CLUSTER_NAME, cluster);
291292
if (sslContextProviderSupplier != null) {
292293
attrBuilder.set(
293-
InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
294+
SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
294295
sslContextProviderSupplier);
295296
}
296297
newAddresses.add(new EquivalentAddressGroup(eag.getAddresses(), attrBuilder.build()));
@@ -299,8 +300,8 @@ private List<EquivalentAddressGroup> withAdditionalAttributes(
299300
}
300301

301302
private ClusterLocality createClusterLocalityFromAttributes(Attributes addressAttributes) {
302-
Locality locality = addressAttributes.get(InternalXdsAttributes.ATTR_LOCALITY);
303-
String localityName = addressAttributes.get(InternalXdsAttributes.ATTR_LOCALITY_NAME);
303+
Locality locality = addressAttributes.get(XdsAttributes.ATTR_LOCALITY);
304+
String localityName = addressAttributes.get(XdsAttributes.ATTR_LOCALITY_NAME);
304305

305306
// Endpoint addresses resolved by ClusterResolverLoadBalancer should always contain
306307
// attributes with its locality, including endpoints in LOGICAL_DNS clusters.
@@ -431,7 +432,7 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
431432
result = PickResult.withSubchannel(result.getSubchannel(),
432433
result.getStreamTracerFactory(),
433434
result.getSubchannel().getAttributes().get(
434-
InternalXdsAttributes.ATTR_ADDRESS_NAME));
435+
XdsAttributes.ATTR_ADDRESS_NAME));
435436
}
436437
}
437438
return result;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
119119
public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
120120
logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
121121
if (xdsClientPool == null) {
122-
xdsClientPool = resolvedAddresses.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL);
122+
xdsClientPool = resolvedAddresses.getAttributes().get(XdsAttributes.XDS_CLIENT_POOL);
123123
xdsClient = xdsClientPool.getObject();
124124
}
125125
ClusterResolverConfig config =
@@ -423,12 +423,12 @@ public void run() {
423423
String localityName = localityName(locality);
424424
Attributes attr =
425425
endpoint.eag().getAttributes().toBuilder()
426-
.set(InternalXdsAttributes.ATTR_LOCALITY, locality)
427-
.set(InternalXdsAttributes.ATTR_LOCALITY_NAME, localityName)
428-
.set(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT,
426+
.set(XdsAttributes.ATTR_LOCALITY, locality)
427+
.set(XdsAttributes.ATTR_LOCALITY_NAME, localityName)
428+
.set(XdsAttributes.ATTR_LOCALITY_WEIGHT,
429429
localityLbInfo.localityWeight())
430-
.set(InternalXdsAttributes.ATTR_SERVER_WEIGHT, weight)
431-
.set(InternalXdsAttributes.ATTR_ADDRESS_NAME, endpoint.hostname())
430+
.set(XdsAttributes.ATTR_SERVER_WEIGHT, weight)
431+
.set(XdsAttributes.ATTR_ADDRESS_NAME, endpoint.hostname())
432432
.build();
433433
EquivalentAddressGroup eag = new EquivalentAddressGroup(
434434
endpoint.eag().getAddresses(), attr);
@@ -630,9 +630,9 @@ public void run() {
630630
// to handle such it.
631631
String localityName = localityName(LOGICAL_DNS_CLUSTER_LOCALITY);
632632
Attributes attr = eag.getAttributes().toBuilder()
633-
.set(InternalXdsAttributes.ATTR_LOCALITY, LOGICAL_DNS_CLUSTER_LOCALITY)
634-
.set(InternalXdsAttributes.ATTR_LOCALITY_NAME, localityName)
635-
.set(InternalXdsAttributes.ATTR_ADDRESS_NAME, dnsHostName)
633+
.set(XdsAttributes.ATTR_LOCALITY, LOGICAL_DNS_CLUSTER_LOCALITY)
634+
.set(XdsAttributes.ATTR_LOCALITY_NAME, localityName)
635+
.set(XdsAttributes.ATTR_ADDRESS_NAME, dnsHostName)
636636
.build();
637637
eag = new EquivalentAddressGroup(eag.getAddresses(), attr);
638638
eag = AddressFilter.setPathFilter(eag, Arrays.asList(priorityName, localityName));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package io.grpc.xds;
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
20-
import static io.grpc.xds.InternalXdsAttributes.ATTR_DRAIN_GRACE_NANOS;
21-
import static io.grpc.xds.InternalXdsAttributes.ATTR_FILTER_CHAIN_SELECTOR_MANAGER;
20+
import static io.grpc.xds.XdsAttributes.ATTR_DRAIN_GRACE_NANOS;
21+
import static io.grpc.xds.XdsAttributes.ATTR_FILTER_CHAIN_SELECTOR_MANAGER;
2222
import static io.grpc.xds.XdsServerWrapper.ATTR_SERVER_ROUTING_CONFIG;
2323
import static io.grpc.xds.internal.security.SecurityProtocolNegotiators.ATTR_SERVER_SSL_CONTEXT_PROVIDER_SUPPLIER;
2424

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public ClientInterceptor buildClientInterceptor(FilterConfig config,
106106
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
107107
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
108108

109-
/*String clusterName = callOptions.getOption(InternalXdsAttributes.ATTR_CLUSTER_NAME);
109+
/*String clusterName = callOptions.getOption(XdsAttributes.ATTR_CLUSTER_NAME);
110110
if (clusterName == null) {
111111
return next.newCall(method, callOptions);
112112
}*/
Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 The gRPC Authors
2+
* Copyright 2024 The gRPC Authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,96 +18,19 @@
1818

1919
import io.grpc.Attributes;
2020
import io.grpc.EquivalentAddressGroup;
21-
import io.grpc.Grpc;
2221
import io.grpc.Internal;
23-
import io.grpc.NameResolver;
24-
import io.grpc.internal.ObjectPool;
25-
import io.grpc.xds.XdsNameResolverProvider.CallCounterProvider;
26-
import io.grpc.xds.client.Locality;
27-
import io.grpc.xds.client.XdsClient;
28-
import io.grpc.xds.internal.security.SslContextProviderSupplier;
2922

3023
/**
3124
* Internal attributes used for xDS implementation. Do not use.
3225
*/
3326
@Internal
3427
public final class InternalXdsAttributes {
35-
36-
// TODO(sanjaypujare): move to xds internal package.
37-
/** Attribute key for SslContextProviderSupplier (used from client) for a subchannel. */
38-
@Grpc.TransportAttr
39-
public static final Attributes.Key<SslContextProviderSupplier>
40-
ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER =
41-
Attributes.Key.create("io.grpc.xds.internal.security.SslContextProviderSupplier");
42-
43-
/**
44-
* Attribute key for passing around the XdsClient object pool across NameResolver/LoadBalancers.
45-
*/
46-
@NameResolver.ResolutionResultAttr
47-
static final Attributes.Key<ObjectPool<XdsClient>> XDS_CLIENT_POOL =
48-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.xdsClientPool");
49-
50-
/**
51-
* Attribute key for obtaining the global provider that provides atomics for aggregating
52-
* outstanding RPCs sent to each cluster.
53-
*/
54-
@NameResolver.ResolutionResultAttr
55-
static final Attributes.Key<CallCounterProvider> CALL_COUNTER_PROVIDER =
56-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.callCounterProvider");
57-
58-
/**
59-
* Map from localities to their weights.
60-
*/
61-
@NameResolver.ResolutionResultAttr
62-
static final Attributes.Key<Integer> ATTR_LOCALITY_WEIGHT =
63-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.localityWeight");
64-
6528
/**
6629
* Name of the cluster that provides this EquivalentAddressGroup.
6730
*/
68-
@Internal
6931
@EquivalentAddressGroup.Attr
7032
public static final Attributes.Key<String> ATTR_CLUSTER_NAME =
71-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.clusterName");
72-
73-
/**
74-
* The locality that this EquivalentAddressGroup is in.
75-
*/
76-
@EquivalentAddressGroup.Attr
77-
static final Attributes.Key<Locality> ATTR_LOCALITY =
78-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.locality");
79-
80-
/**
81-
* The name of the locality that this EquivalentAddressGroup is in.
82-
*/
83-
@EquivalentAddressGroup.Attr
84-
static final Attributes.Key<String> ATTR_LOCALITY_NAME =
85-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.localityName");
86-
87-
/**
88-
* Endpoint weight for load balancing purposes.
89-
*/
90-
@EquivalentAddressGroup.Attr
91-
static final Attributes.Key<Long> ATTR_SERVER_WEIGHT =
92-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.serverWeight");
93-
94-
/** Name associated with individual address, if available (e.g., DNS name). */
95-
@EquivalentAddressGroup.Attr
96-
static final Attributes.Key<String> ATTR_ADDRESS_NAME =
97-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.addressName");
98-
99-
/**
100-
* Filter chain match for network filters.
101-
*/
102-
@Grpc.TransportAttr
103-
static final Attributes.Key<FilterChainSelectorManager>
104-
ATTR_FILTER_CHAIN_SELECTOR_MANAGER = Attributes.Key.create(
105-
"io.grpc.xds.InternalXdsAttributes.filterChainSelectorManager");
106-
107-
/** Grace time to use when draining. Null for an infinite grace time. */
108-
@Grpc.TransportAttr
109-
static final Attributes.Key<Long> ATTR_DRAIN_GRACE_NANOS =
110-
Attributes.Key.create("io.grpc.xds.InternalXdsAttributes.drainGraceTime");
33+
XdsAttributes.ATTR_CLUSTER_NAME;
11134

11235
private InternalXdsAttributes() {}
11336
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
102102
Map<EquivalentAddressGroup, Long> serverWeights = new HashMap<>();
103103
long totalWeight = 0L;
104104
for (EquivalentAddressGroup eag : addrList) {
105-
Long weight = eag.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT);
105+
Long weight = eag.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT);
106106
// Support two ways of server weighing: either multiple instances of the same address
107107
// or each address contains a per-address weight attribute. If a weight is not provided,
108108
// each occurrence of the address will be counted a weight value of one.
@@ -241,7 +241,7 @@ private Status validateAddrList(List<EquivalentAddressGroup> addrList) {
241241

242242
long totalWeight = 0;
243243
for (EquivalentAddressGroup eag : addrList) {
244-
Long weight = eag.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT);
244+
Long weight = eag.getAttributes().get(XdsAttributes.ATTR_SERVER_WEIGHT);
245245

246246
if (weight == null) {
247247
weight = 1L;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
7474
Map<String, Integer> localityWeights = new HashMap<>();
7575
for (EquivalentAddressGroup eag : resolvedAddresses.getAddresses()) {
7676
Attributes eagAttrs = eag.getAttributes();
77-
String locality = eagAttrs.get(InternalXdsAttributes.ATTR_LOCALITY_NAME);
78-
Integer localityWeight = eagAttrs.get(InternalXdsAttributes.ATTR_LOCALITY_WEIGHT);
77+
String locality = eagAttrs.get(XdsAttributes.ATTR_LOCALITY_NAME);
78+
Integer localityWeight = eagAttrs.get(XdsAttributes.ATTR_LOCALITY_WEIGHT);
7979

8080
if (locality == null) {
8181
Status unavailableStatus = Status.UNAVAILABLE.withDescription(
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright 2019 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.xds;
18+
19+
import io.grpc.Attributes;
20+
import io.grpc.EquivalentAddressGroup;
21+
import io.grpc.Grpc;
22+
import io.grpc.NameResolver;
23+
import io.grpc.internal.ObjectPool;
24+
import io.grpc.xds.XdsNameResolverProvider.CallCounterProvider;
25+
import io.grpc.xds.client.Locality;
26+
import io.grpc.xds.client.XdsClient;
27+
28+
/**
29+
* Attributes used for xDS implementation.
30+
*/
31+
final class XdsAttributes {
32+
/**
33+
* Attribute key for passing around the XdsClient object pool across NameResolver/LoadBalancers.
34+
*/
35+
@NameResolver.ResolutionResultAttr
36+
static final Attributes.Key<ObjectPool<XdsClient>> XDS_CLIENT_POOL =
37+
Attributes.Key.create("io.grpc.xds.XdsAttributes.xdsClientPool");
38+
39+
/**
40+
* Attribute key for obtaining the global provider that provides atomics for aggregating
41+
* outstanding RPCs sent to each cluster.
42+
*/
43+
@NameResolver.ResolutionResultAttr
44+
static final Attributes.Key<CallCounterProvider> CALL_COUNTER_PROVIDER =
45+
Attributes.Key.create("io.grpc.xds.XdsAttributes.callCounterProvider");
46+
47+
/**
48+
* Map from localities to their weights.
49+
*/
50+
@NameResolver.ResolutionResultAttr
51+
static final Attributes.Key<Integer> ATTR_LOCALITY_WEIGHT =
52+
Attributes.Key.create("io.grpc.xds.XdsAttributes.localityWeight");
53+
54+
/**
55+
* Name of the cluster that provides this EquivalentAddressGroup.
56+
*/
57+
@EquivalentAddressGroup.Attr
58+
public static final Attributes.Key<String> ATTR_CLUSTER_NAME =
59+
Attributes.Key.create("io.grpc.xds.XdsAttributes.clusterName");
60+
61+
/**
62+
* The locality that this EquivalentAddressGroup is in.
63+
*/
64+
@EquivalentAddressGroup.Attr
65+
static final Attributes.Key<Locality> ATTR_LOCALITY =
66+
Attributes.Key.create("io.grpc.xds.XdsAttributes.locality");
67+
68+
/**
69+
* The name of the locality that this EquivalentAddressGroup is in.
70+
*/
71+
@EquivalentAddressGroup.Attr
72+
static final Attributes.Key<String> ATTR_LOCALITY_NAME =
73+
Attributes.Key.create("io.grpc.xds.XdsAttributes.localityName");
74+
75+
/**
76+
* Endpoint weight for load balancing purposes.
77+
*/
78+
@EquivalentAddressGroup.Attr
79+
static final Attributes.Key<Long> ATTR_SERVER_WEIGHT =
80+
Attributes.Key.create("io.grpc.xds.XdsAttributes.serverWeight");
81+
82+
/** Name associated with individual address, if available (e.g., DNS name). */
83+
@EquivalentAddressGroup.Attr
84+
static final Attributes.Key<String> ATTR_ADDRESS_NAME =
85+
Attributes.Key.create("io.grpc.xds.XdsAttributes.addressName");
86+
87+
/**
88+
* Filter chain match for network filters.
89+
*/
90+
@Grpc.TransportAttr
91+
static final Attributes.Key<FilterChainSelectorManager>
92+
ATTR_FILTER_CHAIN_SELECTOR_MANAGER = Attributes.Key.create(
93+
"io.grpc.xds.XdsAttributes.filterChainSelectorManager");
94+
95+
/** Grace time to use when draining. Null for an infinite grace time. */
96+
@Grpc.TransportAttr
97+
static final Attributes.Key<Long> ATTR_DRAIN_GRACE_NANOS =
98+
Attributes.Key.create("io.grpc.xds.XdsAttributes.drainGraceTime");
99+
100+
private XdsAttributes() {}
101+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ private void updateResolutionResult() {
307307
ConfigOrError parsedServiceConfig = serviceConfigParser.parseServiceConfig(rawServiceConfig);
308308
Attributes attrs =
309309
Attributes.newBuilder()
310-
.set(InternalXdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
311-
.set(InternalXdsAttributes.CALL_COUNTER_PROVIDER, callCounterProvider)
310+
.set(XdsAttributes.XDS_CLIENT_POOL, xdsClientPool)
311+
.set(XdsAttributes.CALL_COUNTER_PROVIDER, callCounterProvider)
312312
.set(InternalConfigSelector.KEY, configSelector)
313313
.build();
314314
ResolutionResult result =

0 commit comments

Comments
 (0)