Search in sources :

Example 6 with LocalityLbEndpoints

use of io.grpc.xds.Endpoints.LocalityLbEndpoints in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method edsResourceRevoked_dnsResolutionError_shutDownChildLbPolicyAndReturnErrorPicker.

@Test
public void edsResourceRevoked_dnsResolutionError_shutDownChildLbPolicyAndReturnErrorPicker() {
    ClusterResolverConfig config = new ClusterResolverConfig(Arrays.asList(edsDiscoveryMechanism1, logicalDnsDiscoveryMechanism), roundRobin);
    deliverLbConfig(config);
    assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1);
    FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
    assertThat(childBalancers).isEmpty();
    reset(helper);
    EquivalentAddressGroup endpoint = makeAddress("endpoint-addr-1");
    LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint, 100, true)), 10, /* localityWeight */
    1);
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality1, localityLbEndpoints));
    resolver.deliverError(Status.UNKNOWN.withDescription("I am lost"));
    assertThat(childBalancers).hasSize(1);
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    assertThat(((PriorityLbConfig) childBalancer.config).priorities).containsExactly(CLUSTER1 + "[priority1]");
    assertAddressesEqual(Collections.singletonList(endpoint), childBalancer.addresses);
    assertThat(childBalancer.shutdown).isFalse();
    xdsClient.deliverResourceNotFound(EDS_SERVICE_NAME1);
    assertThat(childBalancer.shutdown).isTrue();
    verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
    assertPicker(pickerCaptor.getValue(), Status.UNAVAILABLE.withDescription("I am lost"), null);
}
Also used : EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) PriorityLbConfig(io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) Test(org.junit.Test)

Example 7 with LocalityLbEndpoints

use of io.grpc.xds.Endpoints.LocalityLbEndpoints in project grpc-java by grpc.

the class ClientXdsClient method processClusterLoadAssignment.

private static EdsUpdate processClusterLoadAssignment(ClusterLoadAssignment assignment) throws ResourceInvalidException {
    Set<Integer> priorities = new HashSet<>();
    Map<Locality, LocalityLbEndpoints> localityLbEndpointsMap = new LinkedHashMap<>();
    List<DropOverload> dropOverloads = new ArrayList<>();
    int maxPriority = -1;
    for (io.envoyproxy.envoy.config.endpoint.v3.LocalityLbEndpoints localityLbEndpointsProto : assignment.getEndpointsList()) {
        StructOrError<LocalityLbEndpoints> structOrError = parseLocalityLbEndpoints(localityLbEndpointsProto);
        if (structOrError == null) {
            continue;
        }
        if (structOrError.getErrorDetail() != null) {
            throw new ResourceInvalidException(structOrError.getErrorDetail());
        }
        LocalityLbEndpoints localityLbEndpoints = structOrError.getStruct();
        maxPriority = Math.max(maxPriority, localityLbEndpoints.priority());
        priorities.add(localityLbEndpoints.priority());
        // Note endpoints with health status other than HEALTHY and UNKNOWN are still
        // handed over to watching parties. It is watching parties' responsibility to
        // filter out unhealthy endpoints. See EnvoyProtoData.LbEndpoint#isHealthy().
        localityLbEndpointsMap.put(parseLocality(localityLbEndpointsProto.getLocality()), localityLbEndpoints);
    }
    if (priorities.size() != maxPriority + 1) {
        throw new ResourceInvalidException("ClusterLoadAssignment has sparse priorities");
    }
    for (ClusterLoadAssignment.Policy.DropOverload dropOverloadProto : assignment.getPolicy().getDropOverloadsList()) {
        dropOverloads.add(parseDropOverload(dropOverloadProto));
    }
    return new EdsUpdate(assignment.getClusterName(), localityLbEndpointsMap, dropOverloads);
}
Also used : RetryPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.RetryPolicy) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) LbPolicy(io.envoyproxy.envoy.config.cluster.v3.Cluster.LbPolicy) BackoffPolicy(io.grpc.internal.BackoffPolicy) ArrayList(java.util.ArrayList) LbEndpoint(io.grpc.xds.Endpoints.LbEndpoint) LinkedHashMap(java.util.LinkedHashMap) DropOverload(io.grpc.xds.Endpoints.DropOverload) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) HashSet(java.util.HashSet)

Example 8 with LocalityLbEndpoints

use of io.grpc.xds.Endpoints.LocalityLbEndpoints in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method resolutionErrorAfterChildLbCreated_propagateErrorIfAllClustersEncounterError.

@Test
public void resolutionErrorAfterChildLbCreated_propagateErrorIfAllClustersEncounterError() {
    ClusterResolverConfig config = new ClusterResolverConfig(Arrays.asList(edsDiscoveryMechanism1, logicalDnsDiscoveryMechanism), roundRobin);
    deliverLbConfig(config);
    assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1);
    FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
    assertThat(childBalancers).isEmpty();
    reset(helper);
    EquivalentAddressGroup endpoint = makeAddress("endpoint-addr-1");
    LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint, 100, true)), 10, /* localityWeight */
    1);
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality1, localityLbEndpoints));
    // not created until all clusters resolved.
    assertThat(childBalancers).isEmpty();
    resolver.deliverError(Status.UNKNOWN.withDescription("I am lost"));
    // DNS resolution failed, but there are EDS endpoints can be used.
    assertThat(childBalancers).hasSize(1);
    // child LB created
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    // should not propagate error to child LB
    assertThat(childBalancer.upstreamError).isNull();
    assertAddressesEqual(Collections.singletonList(endpoint), childBalancer.addresses);
    xdsClient.deliverError(Status.RESOURCE_EXHAUSTED.withDescription("out of memory"));
    // last cluster's (DNS) error propagated
    assertThat(childBalancer.upstreamError).isNotNull();
    assertThat(childBalancer.upstreamError.getCode()).isEqualTo(Code.UNKNOWN);
    assertThat(childBalancer.upstreamError.getDescription()).isEqualTo("I am lost");
    assertThat(childBalancer.shutdown).isFalse();
    verify(helper, never()).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), any(SubchannelPicker.class));
}
Also used : SubchannelPicker(io.grpc.LoadBalancer.SubchannelPicker) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) Test(org.junit.Test)

Example 9 with LocalityLbEndpoints

use of io.grpc.xds.Endpoints.LocalityLbEndpoints in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method handleEdsResource_noHealthyEndpoint.

@Test
public void handleEdsResource_noHealthyEndpoint() {
    ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(edsDiscoveryMechanism1), roundRobin);
    deliverLbConfig(config);
    EquivalentAddressGroup endpoint = makeAddress("endpoint-addr-1");
    LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint, 100, false)), 10, /* localityWeight */
    1);
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, // single endpoint, unhealthy
    Collections.singletonMap(locality1, localityLbEndpoints));
    assertThat(childBalancers).isEmpty();
    verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
    assertPicker(pickerCaptor.getValue(), Status.UNAVAILABLE.withDescription("No usable endpoint from cluster(s): " + Collections.singleton(CLUSTER1)), null);
}
Also used : EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) Test(org.junit.Test)

Example 10 with LocalityLbEndpoints

use of io.grpc.xds.Endpoints.LocalityLbEndpoints in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method onlyEdsClusters_receivedEndpoints.

@Test
public void onlyEdsClusters_receivedEndpoints() {
    ClusterResolverConfig config = new ClusterResolverConfig(Arrays.asList(edsDiscoveryMechanism1, edsDiscoveryMechanism2), roundRobin);
    deliverLbConfig(config);
    assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1, EDS_SERVICE_NAME2);
    assertThat(childBalancers).isEmpty();
    // CLUSTER1 has priority 1 (priority3), which has locality 2, which has endpoint3.
    // CLUSTER2 has priority 1 (priority1) and 2 (priority2); priority1 has locality1,
    // which has endpoint1 and endpoint2; priority2 has locality3, which has endpoint4.
    EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
    EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
    EquivalentAddressGroup endpoint3 = makeAddress("endpoint-addr-3");
    EquivalentAddressGroup endpoint4 = makeAddress("endpoint-addr-4");
    LocalityLbEndpoints localityLbEndpoints1 = LocalityLbEndpoints.create(Arrays.asList(LbEndpoint.create(endpoint1, 100, true), LbEndpoint.create(endpoint2, 100, true)), 70, /* localityWeight */
    1);
    LocalityLbEndpoints localityLbEndpoints2 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint3, 100, true)), 10, /* localityWeight */
    1);
    LocalityLbEndpoints localityLbEndpoints3 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint4, 100, true)), 20, /* localityWeight */
    2);
    String priority1 = CLUSTER2 + "[priority1]";
    String priority2 = CLUSTER2 + "[priority2]";
    String priority3 = CLUSTER1 + "[priority1]";
    // CLUSTER2: locality1 with priority 1 and locality3 with priority 2.
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME2, ImmutableMap.of(locality1, localityLbEndpoints1, locality3, localityLbEndpoints3));
    // not created until all clusters resolved
    assertThat(childBalancers).isEmpty();
    // CLUSTER1: locality2 with priority 1.
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality2, localityLbEndpoints2));
    // Endpoints of all clusters have been resolved.
    assertThat(childBalancers).hasSize(1);
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    assertThat(childBalancer.name).isEqualTo(PRIORITY_POLICY_NAME);
    PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
    assertThat(priorityLbConfig.priorities).containsExactly(priority3, priority1, priority2).inOrder();
    PriorityChildConfig priorityChildConfig1 = priorityLbConfig.childConfigs.get(priority1);
    assertThat(priorityChildConfig1.ignoreReresolution).isTrue();
    assertThat(priorityChildConfig1.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
    ClusterImplConfig clusterImplConfig1 = (ClusterImplConfig) priorityChildConfig1.policySelection.getConfig();
    assertClusterImplConfig(clusterImplConfig1, CLUSTER2, EDS_SERVICE_NAME2, LRS_SERVER_INFO, 200L, tlsContext, Collections.<DropOverload>emptyList(), WEIGHTED_TARGET_POLICY_NAME);
    WeightedTargetConfig weightedTargetConfig1 = (WeightedTargetConfig) clusterImplConfig1.childPolicy.getConfig();
    assertThat(weightedTargetConfig1.targets.keySet()).containsExactly(locality1.toString());
    WeightedPolicySelection target1 = weightedTargetConfig1.targets.get(locality1.toString());
    assertThat(target1.weight).isEqualTo(70);
    assertThat(target1.policySelection.getProvider().getPolicyName()).isEqualTo("round_robin");
    PriorityChildConfig priorityChildConfig2 = priorityLbConfig.childConfigs.get(priority2);
    assertThat(priorityChildConfig2.ignoreReresolution).isTrue();
    assertThat(priorityChildConfig2.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
    ClusterImplConfig clusterImplConfig2 = (ClusterImplConfig) priorityChildConfig2.policySelection.getConfig();
    assertClusterImplConfig(clusterImplConfig2, CLUSTER2, EDS_SERVICE_NAME2, LRS_SERVER_INFO, 200L, tlsContext, Collections.<DropOverload>emptyList(), WEIGHTED_TARGET_POLICY_NAME);
    WeightedTargetConfig weightedTargetConfig2 = (WeightedTargetConfig) clusterImplConfig2.childPolicy.getConfig();
    assertThat(weightedTargetConfig2.targets.keySet()).containsExactly(locality3.toString());
    WeightedPolicySelection target2 = weightedTargetConfig2.targets.get(locality3.toString());
    assertThat(target2.weight).isEqualTo(20);
    assertThat(target2.policySelection.getProvider().getPolicyName()).isEqualTo("round_robin");
    List<EquivalentAddressGroup> priorityAddrs1 = AddressFilter.filter(childBalancer.addresses, priority1);
    assertThat(priorityAddrs1).hasSize(2);
    assertAddressesEqual(Arrays.asList(endpoint1, endpoint2), priorityAddrs1);
    List<EquivalentAddressGroup> priorityAddrs2 = AddressFilter.filter(childBalancer.addresses, priority2);
    assertThat(priorityAddrs2).hasSize(1);
    assertAddressesEqual(Collections.singletonList(endpoint4), priorityAddrs2);
    PriorityChildConfig priorityChildConfig3 = priorityLbConfig.childConfigs.get(priority3);
    assertThat(priorityChildConfig3.ignoreReresolution).isTrue();
    assertThat(priorityChildConfig3.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
    ClusterImplConfig clusterImplConfig3 = (ClusterImplConfig) priorityChildConfig3.policySelection.getConfig();
    assertClusterImplConfig(clusterImplConfig3, CLUSTER1, EDS_SERVICE_NAME1, LRS_SERVER_INFO, 100L, tlsContext, Collections.<DropOverload>emptyList(), WEIGHTED_TARGET_POLICY_NAME);
    WeightedTargetConfig weightedTargetConfig3 = (WeightedTargetConfig) clusterImplConfig3.childPolicy.getConfig();
    assertThat(weightedTargetConfig3.targets.keySet()).containsExactly(locality2.toString());
    WeightedPolicySelection target3 = weightedTargetConfig3.targets.get(locality2.toString());
    assertThat(target3.weight).isEqualTo(10);
    assertThat(target3.policySelection.getProvider().getPolicyName()).isEqualTo("round_robin");
    List<EquivalentAddressGroup> priorityAddrs3 = AddressFilter.filter(childBalancer.addresses, priority3);
    assertThat(priorityAddrs3).hasSize(1);
    assertAddressesEqual(Collections.singletonList(endpoint3), priorityAddrs3);
}
Also used : PriorityChildConfig(io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) PriorityLbConfig(io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) WeightedPolicySelection(io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedPolicySelection) WeightedTargetConfig(io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedTargetConfig) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) ClusterImplConfig(io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig) Test(org.junit.Test)

Aggregations

LocalityLbEndpoints (io.grpc.xds.Endpoints.LocalityLbEndpoints)13 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)12 ClusterResolverConfig (io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig)12 Test (org.junit.Test)12 PriorityLbConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig)8 ClusterImplConfig (io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig)4 PriorityChildConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig)4 WeightedTargetConfig (io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedTargetConfig)3 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)2 LbPolicy (io.envoyproxy.envoy.config.cluster.v3.Cluster.LbPolicy)1 ConnectivityState (io.grpc.ConnectivityState)1 Status (io.grpc.Status)1 BackoffPolicy (io.grpc.internal.BackoffPolicy)1 DropOverload (io.grpc.xds.Endpoints.DropOverload)1 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)1 RingHashConfig (io.grpc.xds.RingHashLoadBalancer.RingHashConfig)1 HashPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy)1 RetryPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.RetryPolicy)1 WeightedPolicySelection (io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedPolicySelection)1 ArrayList (java.util.ArrayList)1