30
30
import io .envoyproxy .envoy .config .cluster .v3 .LoadBalancingPolicy ;
31
31
import io .envoyproxy .envoy .config .cluster .v3 .LoadBalancingPolicy .Policy ;
32
32
import 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 ;
33
34
import io .envoyproxy .envoy .extensions .load_balancing_policies .least_request .v3 .LeastRequest ;
34
35
import io .envoyproxy .envoy .extensions .load_balancing_policies .pick_first .v3 .PickFirst ;
35
36
import io .envoyproxy .envoy .extensions .load_balancing_policies .ring_hash .v3 .RingHash ;
@@ -92,6 +93,14 @@ class LoadBalancerConfigFactory {
92
93
93
94
static final String ERROR_UTILIZATION_PENALTY = "errorUtilizationPenalty" ;
94
95
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
+
95
104
/**
96
105
* Factory method for creating a new {link LoadBalancerConfigConverter} for a given xDS {@link
97
106
* Cluster}.
@@ -138,7 +147,8 @@ class LoadBalancerConfigFactory {
138
147
String oobReportingPeriod ,
139
148
Boolean enableOobLoadReport ,
140
149
String weightUpdatePeriod ,
141
- Float errorUtilizationPenalty ) {
150
+ Float errorUtilizationPenalty ,
151
+ ImmutableMap <String , ?> slowStartConfig ) {
142
152
ImmutableMap .Builder <String , Object > configBuilder = ImmutableMap .builder ();
143
153
if (blackoutPeriod != null ) {
144
154
configBuilder .put (BLACK_OUT_PERIOD , blackoutPeriod );
@@ -158,10 +168,29 @@ class LoadBalancerConfigFactory {
158
168
if (errorUtilizationPenalty != null ) {
159
169
configBuilder .put (ERROR_UTILIZATION_PENALTY , errorUtilizationPenalty );
160
170
}
171
+ if (slowStartConfig != null ) {
172
+ configBuilder .put (SLOW_START_CONFIG , slowStartConfig );
173
+ }
161
174
return ImmutableMap .of (WeightedRoundRobinLoadBalancerProvider .SCHEME ,
162
175
configBuilder .buildOrThrow ());
163
176
}
164
177
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
+
165
194
/**
166
195
* Builds a service config JSON object for the least_request load balancer config based on the
167
196
* given config values.
@@ -293,13 +322,28 @@ static class LoadBalancingPolicyConverter {
293
322
wrr .hasOobReportingPeriod () ? Durations .toString (wrr .getOobReportingPeriod ()) : null ,
294
323
wrr .hasEnableOobLoadReport () ? wrr .getEnableOobLoadReport ().getValue () : null ,
295
324
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 );
297
327
} catch (IllegalArgumentException ex ) {
298
328
throw new ResourceInvalidException ("Invalid duration in weighted round robin config: "
299
329
+ ex .getMessage ());
300
330
}
301
331
}
302
332
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
+
303
347
/**
304
348
* Converts a wrr_locality {@link Any} configuration to service config format.
305
349
*/
0 commit comments