|
32 | 32 | import io.envoyproxy.envoy.extensions.load_balancing_policies.client_side_weighted_round_robin.v3.ClientSideWeightedRoundRobin;
|
33 | 33 | import io.envoyproxy.envoy.extensions.load_balancing_policies.least_request.v3.LeastRequest;
|
34 | 34 | import io.envoyproxy.envoy.extensions.load_balancing_policies.pick_first.v3.PickFirst;
|
| 35 | +import io.envoyproxy.envoy.extensions.load_balancing_policies.random_subsetting.v3.RandomSubsetting; |
35 | 36 | import io.envoyproxy.envoy.extensions.load_balancing_policies.ring_hash.v3.RingHash;
|
36 | 37 | import io.envoyproxy.envoy.extensions.load_balancing_policies.round_robin.v3.RoundRobin;
|
37 | 38 | import io.envoyproxy.envoy.extensions.load_balancing_policies.wrr_locality.v3.WrrLocality;
|
@@ -92,6 +93,9 @@ class LoadBalancerConfigFactory {
|
92 | 93 |
|
93 | 94 | static final String ERROR_UTILIZATION_PENALTY = "errorUtilizationPenalty";
|
94 | 95 |
|
| 96 | + static final String RANDOM_SUBSETTING_FIELD_NAME = "random_subsetting"; |
| 97 | + static final String SUBSET_SIZE = "subsetSize"; |
| 98 | + |
95 | 99 | /**
|
96 | 100 | * Factory method for creating a new {link LoadBalancerConfigConverter} for a given xDS {@link
|
97 | 101 | * Cluster}.
|
@@ -200,6 +204,20 @@ class LoadBalancerConfigFactory {
|
200 | 204 | return ImmutableMap.of(PICK_FIRST_FIELD_NAME, configBuilder.buildOrThrow());
|
201 | 205 | }
|
202 | 206 |
|
| 207 | + /** |
| 208 | + * Builds a service config JSON object for the random_subsetting load balancer config based on the |
| 209 | + * given config values. |
| 210 | + */ |
| 211 | + private static ImmutableMap<String, ?> buildRandomSubsettingConfig( |
| 212 | + RandomSubsetting randomSubsetting) { |
| 213 | + return ImmutableMap.of( |
| 214 | + RANDOM_SUBSETTING_FIELD_NAME, |
| 215 | + ImmutableMap.of( |
| 216 | + SUBSET_SIZE, randomSubsetting.getSubsetSize(), |
| 217 | + CHILD_POLICY_FIELD, randomSubsetting.getChildPolicy() |
| 218 | + )); |
| 219 | + } |
| 220 | + |
203 | 221 | /**
|
204 | 222 | * Responsible for converting from a {@code envoy.config.cluster.v3.LoadBalancingPolicy} proto
|
205 | 223 | * message to a gRPC service config format.
|
@@ -236,6 +254,9 @@ static class LoadBalancingPolicyConverter {
|
236 | 254 | typedConfig.unpack(ClientSideWeightedRoundRobin.class));
|
237 | 255 | } else if (typedConfig.is(PickFirst.class)) {
|
238 | 256 | serviceConfig = convertPickFirstConfig(typedConfig.unpack(PickFirst.class));
|
| 257 | + } else if (typedConfig.is(RandomSubsetting.class)) { |
| 258 | + serviceConfig = convertRandomSubsettingConfig( |
| 259 | + typedConfig.unpack(RandomSubsetting.class)); |
239 | 260 | } else if (typedConfig.is(com.github.xds.type.v3.TypedStruct.class)) {
|
240 | 261 | serviceConfig = convertCustomConfig(
|
241 | 262 | typedConfig.unpack(com.github.xds.type.v3.TypedStruct.class));
|
@@ -324,6 +345,14 @@ static class LoadBalancingPolicyConverter {
|
324 | 345 | return buildPickFirstConfig(pickFirst.getShuffleAddressList());
|
325 | 346 | }
|
326 | 347 |
|
| 348 | + /** |
| 349 | + * "Converts" a random_subsetting configuration to service config format. |
| 350 | + */ |
| 351 | + private static ImmutableMap<String, ?> convertRandomSubsettingConfig( |
| 352 | + RandomSubsetting randomSubsetting) { |
| 353 | + return buildRandomSubsettingConfig(randomSubsetting); |
| 354 | + } |
| 355 | + |
327 | 356 | /**
|
328 | 357 | * Converts a least_request {@link Any} configuration to service config format.
|
329 | 358 | */
|
|
0 commit comments