Skip to content

Commit

Permalink
Merge pull request #10 from buildkite/add-flag-to-disable-scale-in
Browse files Browse the repository at this point in the history
Add DISABLE_SCALE_IN param to opt-out of scale in
  • Loading branch information
lox authored Mar 25, 2019
2 parents 5efc3e6 + b3c6d1e commit 12043f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func Handler(ctx context.Context, evt json.RawMessage) (string, error) {
params.PublishCloudWatchMetrics = true
}

if m := os.Getenv(`DISABLE_SCALE_IN`); m == `true` || m == `1` {
log.Printf("Disabling scale-in")
params.ScaleInParams.Disable = true
}

scaler, err := scaler.NewScaler(client, params)
if err != nil {
log.Fatal(err)
Expand Down
6 changes: 6 additions & 0 deletions scaler/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

type ScaleInParams struct {
Disable bool
CooldownPeriod time.Duration
Adjustment int64
LastScaleInTime *time.Time
Expand Down Expand Up @@ -117,6 +118,11 @@ func (s *Scaler) Run() error {

log.Printf("↳ Set desired to %d (took %v)", desired, time.Now().Sub(t))
} else if current.DesiredCount > desired {
if s.scaleInParams.Disable {
log.Printf("Skipping scale IN, disabled")
return nil
}

cooldownRemaining := s.scaleInParams.CooldownPeriod - time.Since(*s.scaleInParams.LastScaleInTime)

if cooldownRemaining > 0 {
Expand Down

0 comments on commit 12043f1

Please sign in to comment.