Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #39 from AssemblyAI/mitch/fix-scaling-bug
Browse files Browse the repository at this point in the history
mitch/fix scaling bug
  • Loading branch information
chilledornaments authored Jul 28, 2021
2 parents ea064d6 + 3a06d16 commit 5e41370
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions cmd/plugin/blue_green.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/assemblyai/drone-deploy-ecs/pkg/types"
)

var (
initialDesiredCount int
)

// Returns blue service, green service, error
func determineBlueGreen(e types.ECSClient, blueService string, greenService string, cluster string) (string, string, error) {

Expand Down Expand Up @@ -124,6 +128,7 @@ func blueGreen(dc deploy.DeployConfig, maxDeployChecks int) error {
dc.ScaleUp(currBlueDesiredCount, serviceMinCount, serviceMaxCount, determinedGreenService)

log.Println("Pausing for 45 seconds while ECS schedules", currBlueDesiredCount, "containers")
initialDesiredCount = int(currBlueDesiredCount)
time.Sleep(45 * time.Second)

// Start polling deployment
Expand Down Expand Up @@ -207,15 +212,6 @@ func blueGreen(dc deploy.DeployConfig, maxDeployChecks int) error {
return err
}

/*
There is a bug in this function. It effectively performs an exponential backoff.
This is because it multiplies desiredCount * scalePercent, but it also calls itself recursively,
so desiredCount gets smaller and smaller
We should hold the initial desiredCount passed from blueGreen(), maybe in a global variable, then perform our logic on that number
This bug doesn't really hurt anything, it just makes the scale down go slower than expected
*/
func scaleDownInPercentages(dc deploy.DeployConfig, service string, serviceUsesAppAutoscaling bool, scalePercent string, scaleDownInterval string, desiredCount int) error {
scalePercentString, err := strconv.Atoi(scalePercent)

Expand All @@ -242,7 +238,7 @@ func scaleDownInPercentages(dc deploy.DeployConfig, service string, serviceUsesA
var newDesiredCount int32
var lastScaleDownEvent bool

scaleDownNumber := float64(desiredCount) * percent
scaleDownNumber := float64(initialDesiredCount) * percent

if scaleDownNumber < 0 {
scaleDownBy = 1
Expand Down

0 comments on commit 5e41370

Please sign in to comment.