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

grpc / grpc-java / #19415

12 Aug 2024 06:19PM UTC coverage: 84.471% (+0.002%) from 84.469%
#19415

push

github

ejona86
xds: Remove useless ExperimentalApi for WRR

A package-private class isn't visible and `@Internal` is stronger than
experimental. The only way users should use WRR is via the
weight_round_robin string, and that's already not suffixed with
_experimental.

Closes #9885

33389 of 39527 relevant lines covered (84.47%)

0.84 hits per line

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

87.88
/../xds/src/main/java/io/grpc/xds/WeightedRoundRobinLoadBalancerProvider.java
1
/*
2
 * Copyright 2023 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 com.google.common.annotations.VisibleForTesting;
20
import io.grpc.Deadline;
21
import io.grpc.Internal;
22
import io.grpc.LoadBalancer;
23
import io.grpc.LoadBalancer.Helper;
24
import io.grpc.LoadBalancerProvider;
25
import io.grpc.NameResolver.ConfigOrError;
26
import io.grpc.Status;
27
import io.grpc.internal.JsonUtil;
28
import io.grpc.xds.WeightedRoundRobinLoadBalancer.WeightedRoundRobinLoadBalancerConfig;
29
import java.util.Map;
30

31
/**
32
 * Provides a {@link WeightedRoundRobinLoadBalancer}.
33
 * */
34
@Internal
35
public final class WeightedRoundRobinLoadBalancerProvider extends LoadBalancerProvider {
1✔
36

37
  @VisibleForTesting
38
  static final long MIN_WEIGHT_UPDATE_PERIOD_NANOS = 100_000_000L; // 100ms
39

40
  static final String SCHEME = "weighted_round_robin";
41

42
  @Override
43
  public LoadBalancer newLoadBalancer(Helper helper) {
44
    return new WeightedRoundRobinLoadBalancer(helper, Deadline.getSystemTicker());
1✔
45
  }
46

47
  @Override
48
  public boolean isAvailable() {
49
    return true;
1✔
50
  }
51

52
  @Override
53
  public int getPriority() {
54
    return 5;
1✔
55
  }
56

57
  @Override
58
  public String getPolicyName() {
59
    return SCHEME;
1✔
60
  }
61

62
  @Override
63
  public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawConfig) {
64
    try {
65
      return parseLoadBalancingPolicyConfigInternal(rawConfig);
1✔
66
    } catch (RuntimeException e) {
×
67
      return ConfigOrError.fromError(
×
68
          Status.UNAVAILABLE.withCause(e).withDescription(
×
69
              "Failed parsing configuration for " + getPolicyName()));
×
70
    }
71
  }
72

73
  private ConfigOrError parseLoadBalancingPolicyConfigInternal(Map<String, ?> rawConfig) {
74
    Long blackoutPeriodNanos = JsonUtil.getStringAsDuration(rawConfig, "blackoutPeriod");
1✔
75
    Long weightExpirationPeriodNanos =
1✔
76
            JsonUtil.getStringAsDuration(rawConfig, "weightExpirationPeriod");
1✔
77
    Long oobReportingPeriodNanos = JsonUtil.getStringAsDuration(rawConfig, "oobReportingPeriod");
1✔
78
    Boolean enableOobLoadReport = JsonUtil.getBoolean(rawConfig, "enableOobLoadReport");
1✔
79
    Long weightUpdatePeriodNanos = JsonUtil.getStringAsDuration(rawConfig, "weightUpdatePeriod");
1✔
80
    Float errorUtilizationPenalty = JsonUtil.getNumberAsFloat(rawConfig, "errorUtilizationPenalty");
1✔
81

82
    WeightedRoundRobinLoadBalancerConfig.Builder configBuilder =
83
            WeightedRoundRobinLoadBalancerConfig.newBuilder();
1✔
84
    if (blackoutPeriodNanos != null) {
1✔
85
      configBuilder.setBlackoutPeriodNanos(blackoutPeriodNanos);
1✔
86
    }
87
    if (weightExpirationPeriodNanos != null) {
1✔
88
      configBuilder.setWeightExpirationPeriodNanos(weightExpirationPeriodNanos);
1✔
89
    }
90
    if (enableOobLoadReport != null) {
1✔
91
      configBuilder.setEnableOobLoadReport(enableOobLoadReport);
1✔
92
    }
93
    if (oobReportingPeriodNanos != null) {
1✔
94
      configBuilder.setOobReportingPeriodNanos(oobReportingPeriodNanos);
1✔
95
    }
96
    if (weightUpdatePeriodNanos != null) {
1✔
97
      configBuilder.setWeightUpdatePeriodNanos(weightUpdatePeriodNanos);
1✔
98
      if (weightUpdatePeriodNanos < MIN_WEIGHT_UPDATE_PERIOD_NANOS) {
1✔
99
        configBuilder.setWeightUpdatePeriodNanos(MIN_WEIGHT_UPDATE_PERIOD_NANOS);
1✔
100
      }
101
    }
102
    if (errorUtilizationPenalty != null) {
1✔
103
      configBuilder.setErrorUtilizationPenalty(errorUtilizationPenalty);
1✔
104
    }
105
    return ConfigOrError.fromConfig(configBuilder.build());
1✔
106
  }
107
}
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