@@ -40,7 +40,7 @@ type Scaler interface {
40
40
Scale (apiName string , request int32 ) error
41
41
GetInFlightRequests (apiName string , window time.Duration ) (* float64 , error )
42
42
GetAutoscalingSpec (apiName string ) (* userconfig.Autoscaling , error )
43
- CurrentReplicas (apiName string ) (int32 , error )
43
+ CurrentRequestedReplicas (apiName string ) (int32 , error )
44
44
}
45
45
46
46
type Autoscaler struct {
@@ -76,12 +76,12 @@ func (a *Autoscaler) Awaken(api userconfig.Resource) error {
76
76
zap .String ("apiKind" , api .Kind .String ()),
77
77
)
78
78
79
- currentReplicas , err := scaler .CurrentReplicas (api .Name )
79
+ currentRequestedReplicas , err := scaler .CurrentRequestedReplicas (api .Name )
80
80
if err != nil {
81
81
return errors .Wrap (err , "failed to get current replicas" )
82
82
}
83
83
84
- if currentReplicas > 0 {
84
+ if currentRequestedReplicas > 0 {
85
85
return nil
86
86
}
87
87
@@ -166,7 +166,7 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
166
166
return errors .Wrap (err , "failed to get autoscaling spec" )
167
167
}
168
168
169
- currentReplicas , err := scaler .CurrentReplicas (api .Name )
169
+ currentRequestedReplicas , err := scaler .CurrentRequestedReplicas (api .Name )
170
170
if err != nil {
171
171
return errors .Wrap (err , "failed to get current replicas" )
172
172
}
@@ -187,22 +187,22 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
187
187
rawRecommendation := * avgInFlight / * autoscalingSpec .TargetInFlight
188
188
recommendation := int32 (math .Ceil (rawRecommendation ))
189
189
190
- if rawRecommendation < float64 (currentReplicas ) && rawRecommendation > float64 (currentReplicas )* (1 - autoscalingSpec .DownscaleTolerance ) {
191
- recommendation = currentReplicas
190
+ if rawRecommendation < float64 (currentRequestedReplicas ) && rawRecommendation > float64 (currentRequestedReplicas )* (1 - autoscalingSpec .DownscaleTolerance ) {
191
+ recommendation = currentRequestedReplicas
192
192
}
193
193
194
- if rawRecommendation > float64 (currentReplicas ) && rawRecommendation < float64 (currentReplicas )* (1 + autoscalingSpec .UpscaleTolerance ) {
195
- recommendation = currentReplicas
194
+ if rawRecommendation > float64 (currentRequestedReplicas ) && rawRecommendation < float64 (currentRequestedReplicas )* (1 + autoscalingSpec .UpscaleTolerance ) {
195
+ recommendation = currentRequestedReplicas
196
196
}
197
197
198
198
// always allow subtraction of 1
199
- downscaleFactorFloor := libmath .MinInt32 (currentReplicas - 1 , int32 (math .Ceil (float64 (currentReplicas )* autoscalingSpec .MaxDownscaleFactor )))
199
+ downscaleFactorFloor := libmath .MinInt32 (currentRequestedReplicas - 1 , int32 (math .Ceil (float64 (currentRequestedReplicas )* autoscalingSpec .MaxDownscaleFactor )))
200
200
if recommendation < downscaleFactorFloor {
201
201
recommendation = downscaleFactorFloor
202
202
}
203
203
204
204
// always allow addition of 1
205
- upscaleFactorCeil := libmath .MaxInt32 (currentReplicas + 1 , int32 (math .Ceil (float64 (currentReplicas )* autoscalingSpec .MaxUpscaleFactor )))
205
+ upscaleFactorCeil := libmath .MaxInt32 (currentRequestedReplicas + 1 , int32 (math .Ceil (float64 (currentRequestedReplicas )* autoscalingSpec .MaxUpscaleFactor )))
206
206
if recommendation > upscaleFactorCeil {
207
207
recommendation = upscaleFactorCeil
208
208
}
@@ -228,24 +228,24 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
228
228
var downscaleStabilizationFloor * int32
229
229
var upscaleStabilizationCeil * int32
230
230
231
- if request < currentReplicas {
231
+ if request < currentRequestedReplicas {
232
232
downscaleStabilizationFloor = recs .maxSince (autoscalingSpec .DownscaleStabilizationPeriod )
233
233
if downscaleStabilizationFloor != nil {
234
- downscaleStabilizationFloor = pointer .Int32 (libmath .MinInt32 (* downscaleStabilizationFloor , currentReplicas ))
234
+ downscaleStabilizationFloor = pointer .Int32 (libmath .MinInt32 (* downscaleStabilizationFloor , currentRequestedReplicas ))
235
235
}
236
236
if time .Since (startTime ) < autoscalingSpec .DownscaleStabilizationPeriod {
237
- request = currentReplicas
237
+ request = currentRequestedReplicas
238
238
} else if downscaleStabilizationFloor != nil && request < * downscaleStabilizationFloor {
239
239
request = * downscaleStabilizationFloor
240
240
}
241
241
}
242
- if request > currentReplicas {
242
+ if request > currentRequestedReplicas {
243
243
upscaleStabilizationCeil = recs .minSince (autoscalingSpec .UpscaleStabilizationPeriod )
244
244
if upscaleStabilizationCeil != nil {
245
- upscaleStabilizationCeil = pointer .Int32 (libmath .MaxInt32 (* upscaleStabilizationCeil , currentReplicas ))
245
+ upscaleStabilizationCeil = pointer .Int32 (libmath .MaxInt32 (* upscaleStabilizationCeil , currentRequestedReplicas ))
246
246
}
247
247
if time .Since (startTime ) < autoscalingSpec .UpscaleStabilizationPeriod {
248
- request = currentReplicas
248
+ request = currentRequestedReplicas
249
249
} else if upscaleStabilizationCeil != nil && request > * upscaleStabilizationCeil {
250
250
request = * upscaleStabilizationCeil
251
251
}
@@ -256,7 +256,7 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
256
256
"avg_in_flight" : * avgInFlight ,
257
257
"target_in_flight" : * autoscalingSpec .TargetInFlight ,
258
258
"raw_recommendation" : rawRecommendation ,
259
- "current_replicas" : currentReplicas ,
259
+ "current_replicas" : currentRequestedReplicas ,
260
260
"downscale_tolerance" : autoscalingSpec .DownscaleTolerance ,
261
261
"upscale_tolerance" : autoscalingSpec .UpscaleTolerance ,
262
262
"max_downscale_factor" : autoscalingSpec .MaxDownscaleFactor ,
@@ -274,8 +274,8 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
274
274
},
275
275
)
276
276
277
- if currentReplicas != request {
278
- log .Infof ("autoscaling event: %d -> %d" , currentReplicas , request )
277
+ if currentRequestedReplicas != request {
278
+ log .Infof ("autoscaling event: %d -> %d" , currentRequestedReplicas , request )
279
279
if err = scaler .Scale (api .Name , request ); err != nil {
280
280
return err
281
281
}
0 commit comments