3030import io .envoyproxy .envoy .config .cluster .v3 .LoadBalancingPolicy ;
3131import io .envoyproxy .envoy .config .cluster .v3 .LoadBalancingPolicy .Policy ;
3232import io .envoyproxy .envoy .extensions .load_balancing_policies .client_side_weighted_round_robin .v3 .ClientSideWeightedRoundRobin ;
33+ import io .envoyproxy .envoy .extensions .load_balancing_policies .common .v3 .SlowStartConfig ;
3334import io .envoyproxy .envoy .extensions .load_balancing_policies .least_request .v3 .LeastRequest ;
3435import io .envoyproxy .envoy .extensions .load_balancing_policies .pick_first .v3 .PickFirst ;
3536import io .envoyproxy .envoy .extensions .load_balancing_policies .ring_hash .v3 .RingHash ;
@@ -92,6 +93,14 @@ class LoadBalancerConfigFactory {
9293
9394 static final String ERROR_UTILIZATION_PENALTY = "errorUtilizationPenalty" ;
9495
96+ static final String AGGRESSION = "aggression" ;
97+
98+ static final String SLOW_START_WINDOW = "slowStartWindow" ;
99+
100+ static final String MIN_WEIGHT_PERCENT = "minWeightPercent" ;
101+
102+ static final String SLOW_START_CONFIG = "slowStartConfig" ;
103+
95104 /**
96105 * Factory method for creating a new {link LoadBalancerConfigConverter} for a given xDS {@link
97106 * Cluster}.
@@ -138,7 +147,8 @@ class LoadBalancerConfigFactory {
138147 String oobReportingPeriod ,
139148 Boolean enableOobLoadReport ,
140149 String weightUpdatePeriod ,
141- Float errorUtilizationPenalty ) {
150+ Float errorUtilizationPenalty ,
151+ ImmutableMap <String , ?> slowStartConfig ) {
142152 ImmutableMap .Builder <String , Object > configBuilder = ImmutableMap .builder ();
143153 if (blackoutPeriod != null ) {
144154 configBuilder .put (BLACK_OUT_PERIOD , blackoutPeriod );
@@ -158,10 +168,29 @@ class LoadBalancerConfigFactory {
158168 if (errorUtilizationPenalty != null ) {
159169 configBuilder .put (ERROR_UTILIZATION_PENALTY , errorUtilizationPenalty );
160170 }
171+ if (slowStartConfig != null ) {
172+ configBuilder .put (SLOW_START_CONFIG , slowStartConfig );
173+ }
161174 return ImmutableMap .of (WeightedRoundRobinLoadBalancerProvider .SCHEME ,
162175 configBuilder .buildOrThrow ());
163176 }
164177
178+ private static ImmutableMap <String , ?> buildSlowStartConfig (Double minWeightPercent ,
179+ Double aggression ,
180+ String slowStartWindow ) {
181+ ImmutableMap .Builder <String , Object > configBuilder = ImmutableMap .builder ();
182+ if (minWeightPercent != null ) {
183+ configBuilder .put (MIN_WEIGHT_PERCENT , minWeightPercent );
184+ }
185+ if (aggression != null ) {
186+ configBuilder .put (AGGRESSION , aggression );
187+ }
188+ if (slowStartWindow != null ) {
189+ configBuilder .put (SLOW_START_WINDOW , slowStartWindow );
190+ }
191+ return configBuilder .buildOrThrow ();
192+ }
193+
165194 /**
166195 * Builds a service config JSON object for the least_request load balancer config based on the
167196 * given config values.
@@ -293,13 +322,28 @@ static class LoadBalancingPolicyConverter {
293322 wrr .hasOobReportingPeriod () ? Durations .toString (wrr .getOobReportingPeriod ()) : null ,
294323 wrr .hasEnableOobLoadReport () ? wrr .getEnableOobLoadReport ().getValue () : null ,
295324 wrr .hasWeightUpdatePeriod () ? Durations .toString (wrr .getWeightUpdatePeriod ()) : null ,
296- wrr .hasErrorUtilizationPenalty () ? wrr .getErrorUtilizationPenalty ().getValue () : null );
325+ wrr .hasErrorUtilizationPenalty () ? wrr .getErrorUtilizationPenalty ().getValue () : null ,
326+ wrr .hasSlowStartConfig () ? convertSlotStartConfig (wrr .getSlowStartConfig ()) : null );
297327 } catch (IllegalArgumentException ex ) {
298328 throw new ResourceInvalidException ("Invalid duration in weighted round robin config: "
299329 + ex .getMessage ());
300330 }
301331 }
302332
333+ private static ImmutableMap <String , ?> convertSlotStartConfig (
334+ SlowStartConfig config ) throws ResourceInvalidException {
335+ try {
336+ return buildSlowStartConfig (
337+ config .hasMinWeightPercent () ? config .getMinWeightPercent ().getValue () : null ,
338+ config .hasAggression () ? config .getAggression ().getDefaultValue () : null ,
339+ config .hasSlowStartWindow () ? Durations .toString (config .getSlowStartWindow ()) : null
340+ );
341+ } catch (IllegalArgumentException ex ) {
342+ throw new ResourceInvalidException ("Invalid duration in slow start slowStart: "
343+ + ex .getMessage ());
344+ }
345+ }
346+
303347 /**
304348 * Converts a wrr_locality {@link Any} configuration to service config format.
305349 */
0 commit comments