mirror of https://github.com/grpc/grpc-java.git
xds: filter EDS localities with clarified specifications (#6874)
Fix logic of filtering localites in EDS responses: - Each LocalityLbEndpoints message is allowed to contain 0 LbEndpoints. - LocalityLbEndpoints without or with 0 weight are ignored. - NACK responses with sparse locality priorities.
This commit is contained in:
parent
e081f414a7
commit
68391e4d1b
|
|
@ -622,8 +622,7 @@ interface LocalityStore {
|
||||||
&& !localityLbInfo.childBalancer.canHandleEmptyAddressListFromNameResolution()) {
|
&& !localityLbInfo.childBalancer.canHandleEmptyAddressListFromNameResolution()) {
|
||||||
localityLbInfo.childBalancer.handleNameResolutionError(
|
localityLbInfo.childBalancer.handleNameResolutionError(
|
||||||
Status.UNAVAILABLE.withDescription(
|
Status.UNAVAILABLE.withDescription(
|
||||||
"No healthy address available from EDS update '" + localityLbEndpoints
|
"Locality " + locality + " has no healthy endpoint"));
|
||||||
+ "' for locality '" + locality + "'"));
|
|
||||||
} else {
|
} else {
|
||||||
localityLbInfo.childBalancer
|
localityLbInfo.childBalancer
|
||||||
.handleResolvedAddresses(ResolvedAddresses.newBuilder()
|
.handleResolvedAddresses(ResolvedAddresses.newBuilder()
|
||||||
|
|
|
||||||
|
|
@ -1173,18 +1173,23 @@ final class XdsClientImpl extends XdsClient {
|
||||||
errorMessage = "ClusterLoadAssignment " + clusterName + " : no locality endpoints.";
|
errorMessage = "ClusterLoadAssignment " + clusterName + " : no locality endpoints.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Set<Integer> priorities = new HashSet<>();
|
||||||
// The policy.disable_overprovisioning field must be set to true.
|
int maxPriority = -1;
|
||||||
// TODO(chengyuanzhang): temporarily not requiring this field to be set, should push
|
|
||||||
// server implementors to do this or TBD with design.
|
|
||||||
|
|
||||||
for (io.envoyproxy.envoy.api.v2.endpoint.LocalityLbEndpoints localityLbEndpoints
|
for (io.envoyproxy.envoy.api.v2.endpoint.LocalityLbEndpoints localityLbEndpoints
|
||||||
: assignment.getEndpointsList()) {
|
: assignment.getEndpointsList()) {
|
||||||
// The lb_endpoints field for LbEndpoint must contain at least one entry.
|
// Filter out localities without or with 0 weight.
|
||||||
if (localityLbEndpoints.getLbEndpointsCount() == 0) {
|
if (!localityLbEndpoints.hasLoadBalancingWeight()
|
||||||
errorMessage = "ClusterLoadAssignment " + clusterName + " : locality with no endpoint.";
|
|| localityLbEndpoints.getLoadBalancingWeight().getValue() < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int localityPriority = localityLbEndpoints.getPriority();
|
||||||
|
if (localityPriority < 0) {
|
||||||
|
errorMessage =
|
||||||
|
"ClusterLoadAssignment " + clusterName + " : locality with negative priority.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
maxPriority = Math.max(maxPriority, localityPriority);
|
||||||
|
priorities.add(localityPriority);
|
||||||
// The endpoint field of each lb_endpoints must be set.
|
// The endpoint field of each lb_endpoints must be set.
|
||||||
// Inside of it: the address field must be set.
|
// Inside of it: the address field must be set.
|
||||||
for (io.envoyproxy.envoy.api.v2.endpoint.LbEndpoint lbEndpoint
|
for (io.envoyproxy.envoy.api.v2.endpoint.LbEndpoint lbEndpoint
|
||||||
|
|
@ -1207,6 +1212,10 @@ final class XdsClientImpl extends XdsClient {
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (priorities.size() != maxPriority + 1) {
|
||||||
|
errorMessage = "ClusterLoadAssignment " + clusterName + " : sparse priorities.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
for (io.envoyproxy.envoy.api.v2.ClusterLoadAssignment.Policy.DropOverload dropOverload
|
for (io.envoyproxy.envoy.api.v2.ClusterLoadAssignment.Policy.DropOverload dropOverload
|
||||||
: assignment.getPolicy().getDropOverloadsList()) {
|
: assignment.getPolicy().getDropOverloadsList()) {
|
||||||
updateBuilder.addDropPolicy(DropOverload.fromEnvoyProtoDropOverload(dropOverload));
|
updateBuilder.addDropPolicy(DropOverload.fromEnvoyProtoDropOverload(dropOverload));
|
||||||
|
|
|
||||||
|
|
@ -2132,7 +2132,7 @@ public class XdsClientImplTest {
|
||||||
buildLocalityLbEndpoints("region2", "zone2", "subzone2",
|
buildLocalityLbEndpoints("region2", "zone2", "subzone2",
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
buildLbEndpoint("192.168.234.52", 8888, HealthStatus.UNKNOWN, 5)),
|
buildLbEndpoint("192.168.234.52", 8888, HealthStatus.UNKNOWN, 5)),
|
||||||
6, 1)),
|
6, 0)),
|
||||||
ImmutableList.<ClusterLoadAssignment.Policy.DropOverload>of())));
|
ImmutableList.<ClusterLoadAssignment.Policy.DropOverload>of())));
|
||||||
|
|
||||||
response = buildDiscoveryResponse("1", clusterLoadAssignments,
|
response = buildDiscoveryResponse("1", clusterLoadAssignments,
|
||||||
|
|
@ -2158,7 +2158,7 @@ public class XdsClientImplTest {
|
||||||
new LocalityLbEndpoints(
|
new LocalityLbEndpoints(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
new LbEndpoint("192.168.234.52", 8888,
|
new LbEndpoint("192.168.234.52", 8888,
|
||||||
5, true)), 6, 1));
|
5, true)), 6, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2311,7 +2311,7 @@ public class XdsClientImplTest {
|
||||||
buildLocalityLbEndpoints("region2", "zone2", "subzone2",
|
buildLocalityLbEndpoints("region2", "zone2", "subzone2",
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
buildLbEndpoint("192.168.312.6", 443, HealthStatus.HEALTHY, 1)),
|
buildLbEndpoint("192.168.312.6", 443, HealthStatus.HEALTHY, 1)),
|
||||||
6, 1)),
|
6, 0)),
|
||||||
ImmutableList.<Policy.DropOverload>of())));
|
ImmutableList.<Policy.DropOverload>of())));
|
||||||
|
|
||||||
response = buildDiscoveryResponse("1", clusterLoadAssignments,
|
response = buildDiscoveryResponse("1", clusterLoadAssignments,
|
||||||
|
|
@ -2336,7 +2336,7 @@ public class XdsClientImplTest {
|
||||||
new LocalityLbEndpoints(
|
new LocalityLbEndpoints(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
new LbEndpoint("192.168.312.6", 443, 1, true)),
|
new LbEndpoint("192.168.312.6", 443, 1, true)),
|
||||||
6, 1));
|
6, 0));
|
||||||
|
|
||||||
// Cancel one of the watcher.
|
// Cancel one of the watcher.
|
||||||
xdsClient.cancelEndpointDataWatch("cluster-foo.googleapis.com", watcher1);
|
xdsClient.cancelEndpointDataWatch("cluster-foo.googleapis.com", watcher1);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue