use of io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method handleEdsResource_ignoreLocalitiesWithNoHealthyEndpoints.
@Test
public void handleEdsResource_ignoreLocalitiesWithNoHealthyEndpoints() {
ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(edsDiscoveryMechanism1), roundRobin);
deliverLbConfig(config);
EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
LocalityLbEndpoints localityLbEndpoints1 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint1, 100, false)), 10, /* localityWeight */
1);
LocalityLbEndpoints localityLbEndpoints2 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint2, 100, true)), 10, /* localityWeight */
1);
String priority = CLUSTER1 + "[priority1]";
xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, ImmutableMap.of(locality1, localityLbEndpoints1, locality2, localityLbEndpoints2));
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
PriorityChildConfig priorityChildConfig = priorityLbConfig.childConfigs.get(priority);
ClusterImplConfig clusterImplConfig = (ClusterImplConfig) priorityChildConfig.policySelection.getConfig();
WeightedTargetConfig weightedTargetConfig = (WeightedTargetConfig) clusterImplConfig.childPolicy.getConfig();
assertThat(weightedTargetConfig.targets.keySet()).containsExactly(locality2.toString());
}
use of io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method edsClustersWithRingHashEndpointLbPolicy.
@Test
public void edsClustersWithRingHashEndpointLbPolicy() {
ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(edsDiscoveryMechanism1), ringHash);
deliverLbConfig(config);
assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1);
assertThat(childBalancers).isEmpty();
// One priority with two localities of different weights.
EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
EquivalentAddressGroup endpoint3 = makeAddress("endpoint-addr-3");
LocalityLbEndpoints localityLbEndpoints1 = LocalityLbEndpoints.create(Arrays.asList(LbEndpoint.create(endpoint1, 0, /* loadBalancingWeight */
true), LbEndpoint.create(endpoint2, 0, /* loadBalancingWeight */
true)), 10, /* localityWeight */
1);
LocalityLbEndpoints localityLbEndpoints2 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint3, 60, /* loadBalancingWeight */
true)), 50, /* localityWeight */
1);
xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, ImmutableMap.of(locality1, localityLbEndpoints1, locality2, localityLbEndpoints2));
assertThat(childBalancers).hasSize(1);
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
assertThat(childBalancer.addresses).hasSize(3);
EquivalentAddressGroup addr1 = childBalancer.addresses.get(0);
EquivalentAddressGroup addr2 = childBalancer.addresses.get(1);
EquivalentAddressGroup addr3 = childBalancer.addresses.get(2);
// Endpoints in locality1 have no endpoint-level weight specified, so all endpoints within
// locality1 are equally weighted.
assertThat(addr1.getAddresses()).isEqualTo(endpoint1.getAddresses());
assertThat(addr1.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT)).isEqualTo(10);
assertThat(addr2.getAddresses()).isEqualTo(endpoint2.getAddresses());
assertThat(addr2.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT)).isEqualTo(10);
assertThat(addr3.getAddresses()).isEqualTo(endpoint3.getAddresses());
assertThat(addr3.getAttributes().get(InternalXdsAttributes.ATTR_SERVER_WEIGHT)).isEqualTo(50 * 60);
assertThat(childBalancer.name).isEqualTo(PRIORITY_POLICY_NAME);
PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
assertThat(priorityLbConfig.priorities).containsExactly(CLUSTER1 + "[priority1]");
PriorityChildConfig priorityChildConfig = Iterables.getOnlyElement(priorityLbConfig.childConfigs.values());
assertThat(priorityChildConfig.ignoreReresolution).isTrue();
assertThat(priorityChildConfig.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
ClusterImplConfig clusterImplConfig = (ClusterImplConfig) priorityChildConfig.policySelection.getConfig();
assertClusterImplConfig(clusterImplConfig, CLUSTER1, EDS_SERVICE_NAME1, LRS_SERVER_INFO, 100L, tlsContext, Collections.<DropOverload>emptyList(), "ring_hash_experimental");
RingHashConfig ringHashConfig = (RingHashConfig) clusterImplConfig.childPolicy.getConfig();
assertThat(ringHashConfig.minRingSize).isEqualTo(10L);
assertThat(ringHashConfig.maxRingSize).isEqualTo(100L);
}
use of io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method onlyLogicalDnsCluster_endpointsResolved.
@Test
public void onlyLogicalDnsCluster_endpointsResolved() {
ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(logicalDnsDiscoveryMechanism), roundRobin);
deliverLbConfig(config);
FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
assertThat(childBalancers).isEmpty();
EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
resolver.deliverEndpointAddresses(Arrays.asList(endpoint1, endpoint2));
assertThat(childBalancers).hasSize(1);
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
assertThat(childBalancer.name).isEqualTo(PRIORITY_POLICY_NAME);
PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
String priority = Iterables.getOnlyElement(priorityLbConfig.priorities);
PriorityChildConfig priorityChildConfig = priorityLbConfig.childConfigs.get(priority);
assertThat(priorityChildConfig.ignoreReresolution).isFalse();
assertThat(priorityChildConfig.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
ClusterImplConfig clusterImplConfig = (ClusterImplConfig) priorityChildConfig.policySelection.getConfig();
assertClusterImplConfig(clusterImplConfig, CLUSTER_DNS, null, LRS_SERVER_INFO, 300L, null, Collections.<DropOverload>emptyList(), "pick_first");
assertAddressesEqual(Arrays.asList(endpoint1, endpoint2), childBalancer.addresses);
}
use of io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancer method generateEdsBasedPriorityChildConfigs.
/**
* Generates configs to be used in the priority LB policy for priorities in an EDS cluster.
*
* <p>priority LB -> cluster_impl LB (one per priority) -> (weighted_target LB
* -> round_robin / least_request_experimental (one per locality)) / ring_hash_experimental
*/
private static Map<String, PriorityChildConfig> generateEdsBasedPriorityChildConfigs(String cluster, @Nullable String edsServiceName, @Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests, @Nullable UpstreamTlsContext tlsContext, PolicySelection endpointLbPolicy, LoadBalancerRegistry lbRegistry, Map<String, Map<Locality, Integer>> prioritizedLocalityWeights, List<DropOverload> dropOverloads) {
Map<String, PriorityChildConfig> configs = new HashMap<>();
for (String priority : prioritizedLocalityWeights.keySet()) {
PolicySelection leafPolicy = endpointLbPolicy;
// product of each endpoint's weight and the weight of the locality it belongs to.
if (endpointLbPolicy.getProvider().getPolicyName().equals("round_robin") || endpointLbPolicy.getProvider().getPolicyName().equals("least_request_experimental")) {
Map<Locality, Integer> localityWeights = prioritizedLocalityWeights.get(priority);
Map<String, WeightedPolicySelection> targets = new HashMap<>();
for (Locality locality : localityWeights.keySet()) {
int weight = localityWeights.get(locality);
WeightedPolicySelection target = new WeightedPolicySelection(weight, endpointLbPolicy);
targets.put(localityName(locality), target);
}
LoadBalancerProvider weightedTargetLbProvider = lbRegistry.getProvider(WEIGHTED_TARGET_POLICY_NAME);
WeightedTargetConfig weightedTargetConfig = new WeightedTargetConfig(Collections.unmodifiableMap(targets));
leafPolicy = new PolicySelection(weightedTargetLbProvider, weightedTargetConfig);
}
ClusterImplConfig clusterImplConfig = new ClusterImplConfig(cluster, edsServiceName, lrsServerInfo, maxConcurrentRequests, dropOverloads, leafPolicy, tlsContext);
LoadBalancerProvider clusterImplLbProvider = lbRegistry.getProvider(XdsLbPolicies.CLUSTER_IMPL_POLICY_NAME);
PolicySelection clusterImplPolicy = new PolicySelection(clusterImplLbProvider, clusterImplConfig);
PriorityChildConfig priorityChildConfig = new PriorityChildConfig(clusterImplPolicy, true);
configs.put(priority, priorityChildConfig);
}
return configs;
}
use of io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancer method generateDnsBasedPriorityChildConfig.
/**
* Generates the config to be used in the priority LB policy for the single priority of
* logical DNS cluster.
*
* <p>priority LB -> cluster_impl LB (single hardcoded priority) -> pick_first
*/
private static PriorityChildConfig generateDnsBasedPriorityChildConfig(String cluster, @Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests, @Nullable UpstreamTlsContext tlsContext, LoadBalancerRegistry lbRegistry, List<DropOverload> dropOverloads) {
// Override endpoint-level LB policy with pick_first for logical DNS cluster.
PolicySelection endpointLbPolicy = new PolicySelection(lbRegistry.getProvider("pick_first"), null);
ClusterImplConfig clusterImplConfig = new ClusterImplConfig(cluster, null, lrsServerInfo, maxConcurrentRequests, dropOverloads, endpointLbPolicy, tlsContext);
LoadBalancerProvider clusterImplLbProvider = lbRegistry.getProvider(XdsLbPolicies.CLUSTER_IMPL_POLICY_NAME);
PolicySelection clusterImplPolicy = new PolicySelection(clusterImplLbProvider, clusterImplConfig);
return new PriorityChildConfig(clusterImplPolicy, false);
}
Aggregations