Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure capacity does not exceed ASG MaxSize #35

Merged
merged 3 commits into from
Oct 19, 2020

Conversation

nitrocode
Copy link
Contributor

Closes #34

@yob

@yob
Copy link
Contributor

yob commented Oct 7, 2020

Thanks @nitrocode, we'll give this a test run and get back to you 🙏

@nitrocode
Copy link
Contributor Author

after this is tested and merged, could we have a new release v1.0.2 tag of this scaler and have it be used in the master aws-stack.yml ?

We're eager to get past this issue. For now to be safe, we've raised all of our ASG MaxSize=100 and/or reset our ScaleOutFactor=1.

Copy link
Contributor

@yob yob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @nitrocode.

It'd be great to avoid the extra API call to fetch the ASG state, and I just noticed that we have existing code for capping the scale out to MaxSize:

if desired > current.MaxSize {
log.Printf("⚠️ Desired count exceed MaxSize, capping at %d", current.MaxSize)
desired = current.MaxSize
} else if desired < current.MinSize {
log.Printf("⚠️ Desired count is less than MinSize, capping at %d", current.MinSize)
desired = current.MinSize
}

Unfortunately, that capping happens before the scale factors are applied.

I haven't explored this idea fully or tested it, but what do you think about moving the application of the scale factors (in and out) to happen before the capping process? Maybe as an extra unexported function like this:

diff --git a/scaler/scaler.go b/scaler/scaler.go
index b6a4334..6f5bcef 100644
--- a/scaler/scaler.go
+++ b/scaler/scaler.go
@@ -115,6 +115,12 @@ func (s *Scaler) Run() (time.Duration, error) {
                return metrics.PollDuration, err
        }
 
+       if desired > current {
+               desired = s.applyScaleOutFactor(desired)
+       } else if desired < current {
+               desired = s.applyScaleInFactor(desired)
+       }
+
        if desired > current.MaxSize {
                log.Printf("⚠️  Desired count exceed MaxSize, capping at %d", current.MaxSize)
                desired = current.MaxSize

@nitrocode
Copy link
Contributor Author

Sure, sounds better than making another api call I suppose. As long as it works, I'm happy.

@nitrocode
Copy link
Contributor Author

I reverted my change and added yours. Are there any unit or integration tests that can be run on this? @yob

@JuanitoFatas JuanitoFatas merged commit 6201207 into buildkite:master Oct 19, 2020
@yob
Copy link
Contributor

yob commented Oct 19, 2020

Thanks @nitrocode 🙏

We ended up extending this PR with a slightly different solution to the one I suggested, and added some unit tests in #37.

@nitrocode nitrocode deleted the patch-1 branch October 19, 2020 10:25
@nitrocode
Copy link
Contributor Author

Perfect! Thanks @yob

Could we get this released as part of a 5.0 beta 2 for the elastic ci stack?

@yob
Copy link
Contributor

yob commented Oct 19, 2020

yup, that's the plan 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ScaleOutFactor * number of jobs cannot be greater than MaxSize or no agents will be scaled out
3 participants