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

grpc / grpc-java / #20034

29 Oct 2025 05:05PM UTC coverage: 88.514% (-0.02%) from 88.533%
#20034

push

github

ejona86
Include causal status details in higher-level statuses

When an operation fails and we want to produce a new status at a higher
level, we commonly are turning the first status into an exception to
attach to the new exception. We should instead prefer to keep as much
information in the status description itself, as cause is not as
reliable to be logged/propagated.

I do expect long-term we'll want to expose an API in grpc-api for this,
but for the moment let's keep it internal. In particular, we'd have to
figure out its name. I could also believe we might want different
formatting, which becomes a clearer discussion when we can see the
usages.

I'm pretty certain there are some other places that could benefit from
this utility, as I remember really wishing I had these functions a month
or two ago. But these are the places I could immediately find.

OutlierDetectionLoadBalancerConfig had its status code changed from
INTERNAL to UNAVAILABLE because the value comes externally, and so isn't
a gRPC bug or such. I didn't change the xds policies in the same way
because it's murkier as the configuration for those is largely generated
within xds itself.

34957 of 39493 relevant lines covered (88.51%)

0.89 hits per line

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

64.29
/../xds/src/main/java/io/grpc/xds/WrrLocalityLoadBalancerProvider.java
1
/*
2
 * Copyright 2022 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 io.grpc.Internal;
20
import io.grpc.LoadBalancer;
21
import io.grpc.LoadBalancer.Helper;
22
import io.grpc.LoadBalancerProvider;
23
import io.grpc.LoadBalancerRegistry;
24
import io.grpc.NameResolver.ConfigOrError;
25
import io.grpc.Status;
26
import io.grpc.internal.GrpcUtil;
27
import io.grpc.internal.JsonUtil;
28
import io.grpc.util.GracefulSwitchLoadBalancer;
29
import io.grpc.xds.WrrLocalityLoadBalancer.WrrLocalityConfig;
30
import java.util.Map;
31

32
/**
33
 * The provider for {@link WrrLocalityLoadBalancer}. An instance of this class should be acquired
34
 * through {@link LoadBalancerRegistry#getProvider} by using the name
35
 * "xds_wrr_locality_experimental".
36
 */
37
@Internal
38
public final class WrrLocalityLoadBalancerProvider extends LoadBalancerProvider {
1✔
39

40
  @Override
41
  public LoadBalancer newLoadBalancer(Helper helper) {
42
    return new WrrLocalityLoadBalancer(helper);
1✔
43
  }
44

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

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

55
  @Override
56
  public String getPolicyName() {
57
    return XdsLbPolicies.WRR_LOCALITY_POLICY_NAME;
1✔
58
  }
59

60
  @Override
61
  public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawConfig) {
62
    try {
63
      ConfigOrError childConfig = GracefulSwitchLoadBalancer.parseLoadBalancingPolicyConfig(
1✔
64
          JsonUtil.getListOfObjects(rawConfig, "childPolicy"));
1✔
65
      if (childConfig.getError() != null) {
1✔
66
        return ConfigOrError.fromError(GrpcUtil.statusWithDetails(
×
67
            Status.Code.INTERNAL,
68
            "Failed to parse child policy in wrr_locality LB policy",
69
            childConfig.getError()));
×
70
      }
71
      return ConfigOrError.fromConfig(new WrrLocalityConfig(childConfig.getConfig()));
1✔
72
    } catch (RuntimeException e) {
×
73
      return ConfigOrError.fromError(Status.INTERNAL.withCause(e)
×
74
          .withDescription("Failed to parse wrr_locality LB config: " + rawConfig));
×
75
    }
76
  }
77
}
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

© 2026 Coveralls, Inc