@@ -40,7 +40,7 @@ type Scaler interface {
4040 Scale (apiName string , request int32 ) error
4141 GetInFlightRequests (apiName string , window time.Duration ) (* float64 , error )
4242 GetAutoscalingSpec (apiName string ) (* userconfig.Autoscaling , error )
43- CurrentReplicas (apiName string ) (int32 , error )
43+ CurrentRequestedReplicas (apiName string ) (int32 , error )
4444}
4545
4646type Autoscaler struct {
@@ -76,12 +76,12 @@ func (a *Autoscaler) Awaken(api userconfig.Resource) error {
7676 zap .String ("apiKind" , api .Kind .String ()),
7777 )
7878
79- currentReplicas , err := scaler .CurrentReplicas (api .Name )
79+ currentRequestedReplicas , err := scaler .CurrentRequestedReplicas (api .Name )
8080 if err != nil {
8181 return errors .Wrap (err , "failed to get current replicas" )
8282 }
8383
84- if currentReplicas > 0 {
84+ if currentRequestedReplicas > 0 {
8585 return nil
8686 }
8787
@@ -166,7 +166,7 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
166166 return errors .Wrap (err , "failed to get autoscaling spec" )
167167 }
168168
169- currentReplicas , err := scaler .CurrentReplicas (api .Name )
169+ currentRequestedReplicas , err := scaler .CurrentRequestedReplicas (api .Name )
170170 if err != nil {
171171 return errors .Wrap (err , "failed to get current replicas" )
172172 }
@@ -187,22 +187,22 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
187187 rawRecommendation := * avgInFlight / * autoscalingSpec .TargetInFlight
188188 recommendation := int32 (math .Ceil (rawRecommendation ))
189189
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
192192 }
193193
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
196196 }
197197
198198 // 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 )))
200200 if recommendation < downscaleFactorFloor {
201201 recommendation = downscaleFactorFloor
202202 }
203203
204204 // 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 )))
206206 if recommendation > upscaleFactorCeil {
207207 recommendation = upscaleFactorCeil
208208 }
@@ -228,24 +228,24 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
228228 var downscaleStabilizationFloor * int32
229229 var upscaleStabilizationCeil * int32
230230
231- if request < currentReplicas {
231+ if request < currentRequestedReplicas {
232232 downscaleStabilizationFloor = recs .maxSince (autoscalingSpec .DownscaleStabilizationPeriod )
233233 if downscaleStabilizationFloor != nil {
234- downscaleStabilizationFloor = pointer .Int32 (libmath .MinInt32 (* downscaleStabilizationFloor , currentReplicas ))
234+ downscaleStabilizationFloor = pointer .Int32 (libmath .MinInt32 (* downscaleStabilizationFloor , currentRequestedReplicas ))
235235 }
236236 if time .Since (startTime ) < autoscalingSpec .DownscaleStabilizationPeriod {
237- request = currentReplicas
237+ request = currentRequestedReplicas
238238 } else if downscaleStabilizationFloor != nil && request < * downscaleStabilizationFloor {
239239 request = * downscaleStabilizationFloor
240240 }
241241 }
242- if request > currentReplicas {
242+ if request > currentRequestedReplicas {
243243 upscaleStabilizationCeil = recs .minSince (autoscalingSpec .UpscaleStabilizationPeriod )
244244 if upscaleStabilizationCeil != nil {
245- upscaleStabilizationCeil = pointer .Int32 (libmath .MaxInt32 (* upscaleStabilizationCeil , currentReplicas ))
245+ upscaleStabilizationCeil = pointer .Int32 (libmath .MaxInt32 (* upscaleStabilizationCeil , currentRequestedReplicas ))
246246 }
247247 if time .Since (startTime ) < autoscalingSpec .UpscaleStabilizationPeriod {
248- request = currentReplicas
248+ request = currentRequestedReplicas
249249 } else if upscaleStabilizationCeil != nil && request > * upscaleStabilizationCeil {
250250 request = * upscaleStabilizationCeil
251251 }
@@ -256,7 +256,7 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
256256 "avg_in_flight" : * avgInFlight ,
257257 "target_in_flight" : * autoscalingSpec .TargetInFlight ,
258258 "raw_recommendation" : rawRecommendation ,
259- "current_replicas" : currentReplicas ,
259+ "current_replicas" : currentRequestedReplicas ,
260260 "downscale_tolerance" : autoscalingSpec .DownscaleTolerance ,
261261 "upscale_tolerance" : autoscalingSpec .UpscaleTolerance ,
262262 "max_downscale_factor" : autoscalingSpec .MaxDownscaleFactor ,
@@ -274,8 +274,8 @@ func (a *Autoscaler) autoscaleFn(api userconfig.Resource) (func() error, error)
274274 },
275275 )
276276
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 )
279279 if err = scaler .Scale (api .Name , request ); err != nil {
280280 return err
281281 }
0 commit comments