Skip to content

Commit

Permalink
Merge pull request #37 from buildkite/dont-scale-out-over-max
Browse files Browse the repository at this point in the history
Avoid scale out over max and scale in under min
  • Loading branch information
JuanitoFatas authored Oct 19, 2020
2 parents 12d9dfb + 3cab033 commit 456bf3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func (s *Scaler) scaleIn(desired int64, current AutoscaleGroupDetails) error {
}

desired = current.DesiredCount + factoredChange

if desired < current.MinSize {
log.Printf("⚠️ Post scalein-factor desired count lower than MinSize, capping at %d", current.MinSize)
desired = current.MinSize
}
}

// Correct negative values if we get them
Expand Down Expand Up @@ -222,6 +227,11 @@ func (s *Scaler) scaleOut(desired int64, current AutoscaleGroupDetails) error {
}

desired = current.DesiredCount + factoredChange

if desired > current.MaxSize {
log.Printf("⚠️ Post scaleout-factor desired count exceed MaxSize, capping at %d", current.MaxSize)
desired = current.MaxSize
}
}

log.Printf("Scaling OUT 📈 to %d instances (currently %d)", desired, current.DesiredCount)
Expand Down
13 changes: 13 additions & 0 deletions scaler/scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ func TestScalingOutWithoutError(t *testing.T) {
currentDesiredCapacity: 11,
expectedDesiredCapacity: 12,
},
// Scale-out with a factor too large
{
metrics: buildkite.AgentMetrics{
ScheduledJobs: 10,
},
params: Params{
AgentsPerInstance: 1,
ScaleOutParams: ScaleParams{
Factor: 500.0,
},
},
expectedDesiredCapacity: 100.0,
},
// Cool-down period is enforced
{
metrics: buildkite.AgentMetrics{
Expand Down

0 comments on commit 456bf3b

Please sign in to comment.