• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19214

09 May 2024 12:14AM CUT coverage: 88.262% (+0.01%) from 88.25%
#19214

push

github

web-flow
Change HappyEyeballs and new pick first LB flags default value to false (1.63.x backport) (#11176)

* port PR 11120

* Revert backported changes that aren't relevant for v1.63.x

* Revert backported changes that aren't relevant for v1.63.x

31214 of 35365 relevant lines covered (88.26%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.18
/../core/src/main/java/io/grpc/internal/PickFirstLoadBalancerProvider.java
1
/*
2
 * Copyright 2018 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.internal;
18

19
import com.google.common.annotations.VisibleForTesting;
20
import io.grpc.LoadBalancer;
21
import io.grpc.LoadBalancerProvider;
22
import io.grpc.NameResolver;
23
import io.grpc.NameResolver.ConfigOrError;
24
import io.grpc.Status;
25
import io.grpc.internal.PickFirstLeafLoadBalancer.PickFirstLeafLoadBalancerConfig;
26
import io.grpc.internal.PickFirstLoadBalancer.PickFirstLoadBalancerConfig;
27
import java.util.Map;
28

29
/**
30
 * Provider for the "pick_first" balancing policy.
31
 *
32
 * <p>This provides no load-balancing over the addresses from the {@link NameResolver}.  It walks
33
 * down the address list and sticks to the first that works.
34
 */
35
public final class PickFirstLoadBalancerProvider extends LoadBalancerProvider {
1✔
36
  public static final String GRPC_EXPERIMENTAL_XDS_DUALSTACK_ENDPOINTS =
37
      "GRPC_EXPERIMENTAL_XDS_DUALSTACK_ENDPOINTS";
38
  private static final String SHUFFLE_ADDRESS_LIST_KEY = "shuffleAddressList";
39

40
  static boolean enableNewPickFirst =
1✔
41
      GrpcUtil.getFlag("GRPC_EXPERIMENTAL_ENABLE_NEW_PICK_FIRST", false);
1✔
42

43
  public static boolean isEnabledHappyEyeballs() {
44
    return GrpcUtil.getFlag(GRPC_EXPERIMENTAL_XDS_DUALSTACK_ENDPOINTS, false);
1✔
45
  }
46

47
  @VisibleForTesting
48
  public static boolean isEnableNewPickFirst() {
49
    return enableNewPickFirst;
×
50
  }
51

52
  @Override
53
  public boolean isAvailable() {
54
    return true;
1✔
55
  }
56

57
  @Override
58
  public int getPriority() {
59
    return 5;
1✔
60
  }
61

62
  @Override
63
  public String getPolicyName() {
64
    return "pick_first";
1✔
65
  }
66

67
  @Override
68
  public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
69
    if (enableNewPickFirst) {
1✔
70
      return new PickFirstLeafLoadBalancer(helper);
×
71
    } else {
72
      return new PickFirstLoadBalancer(helper);
1✔
73
    }
74
  }
75

76
  @Override
77
  public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLbPolicyConfig) {
78
    try {
79
      Object config = getLbPolicyConfig(rawLbPolicyConfig);
1✔
80
      return ConfigOrError.fromConfig(config);
1✔
81
    } catch (RuntimeException e) {
×
82
      return ConfigOrError.fromError(
×
83
          Status.UNAVAILABLE.withCause(e).withDescription(
×
84
              "Failed parsing configuration for " + getPolicyName()));
×
85
    }
86
  }
87

88
  private static Object getLbPolicyConfig(Map<String, ?> rawLbPolicyConfig) {
89
    Boolean shuffleAddressList = JsonUtil.getBoolean(rawLbPolicyConfig, SHUFFLE_ADDRESS_LIST_KEY);
1✔
90
    if (enableNewPickFirst) {
1✔
91
      return new PickFirstLeafLoadBalancerConfig(shuffleAddressList);
×
92
    } else {
93
      return new PickFirstLoadBalancerConfig(shuffleAddressList);
1✔
94
    }
95
  }
96

97
  @VisibleForTesting
98
  public static boolean isEnabledNewPickFirst() {
99
    return enableNewPickFirst;
1✔
100
  }
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc