Skip to content

Commit

Permalink
Merge Use the larger of min-OD-instances and (min-OD-percent * current)
Browse files Browse the repository at this point in the history
  • Loading branch information
mello7tre committed Jul 9, 2020
1 parent 8907710 commit c9c3ff1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 30 deletions.
13 changes: 10 additions & 3 deletions core/autoscaling_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,32 @@ func (a *autoScalingGroup) getTagValue(keyMatch string) *string {
return nil
}

func (a *autoScalingGroup) setMinOnDemandIfLarger(newValue int64, hasMinOnDemand bool) bool {
if !hasMinOnDemand || newValue > a.minOnDemand {
a.minOnDemand = newValue
}
return true
}

func (a *autoScalingGroup) loadConfOnDemand() bool {
tagList := [2]string{OnDemandNumberLong, OnDemandPercentageTag}
loadDyn := map[string]func(*string) (int64, bool){
OnDemandPercentageTag: a.loadPercentageOnDemand,
OnDemandNumberLong: a.loadNumberOnDemand,
}

foundLimit := false
for _, tagKey := range tagList {
if tagValue := a.getTagValue(tagKey); tagValue != nil {
if _, ok := loadDyn[tagKey]; ok {
if newValue, done := loadDyn[tagKey](tagValue); done {
a.minOnDemand = newValue
return done
foundLimit = a.setMinOnDemandIfLarger(newValue, foundLimit)
}
}
}
debug.Println("Couldn't find tag", tagKey)
}
return false
return foundLimit
}

func (a *autoScalingGroup) loadPatchBeanstalkUserdata() {
Expand Down
85 changes: 58 additions & 27 deletions core/autoscaling_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,33 +350,6 @@ func TestLoadConfOnDemand(t *testing.T) {
numberExpected: 1,
loadingExpected: true,
},
{name: "Number has priority on percentage value",
asgTags: []*autoscaling.TagDescription{
{
Key: aws.String("Name"),
Value: aws.String("asg-test"),
},
{
Key: aws.String(OnDemandPercentageTag),
Value: aws.String("75"),
},
{
Key: aws.String(OnDemandNumberLong),
Value: aws.String("2"),
},
},
asgInstances: makeInstancesWithCatalog(
instanceMap{
"id-1": {},
"id-2": {},
"id-3": {},
"id-4": {},
},
),
maxSize: aws.Int64(10),
numberExpected: 2,
loadingExpected: true,
},
{name: "Number is invalid so percentage value is used",
asgTags: []*autoscaling.TagDescription{
{
Expand Down Expand Up @@ -424,6 +397,64 @@ func TestLoadConfOnDemand(t *testing.T) {
numberExpected: DefaultMinOnDemandValue,
loadingExpected: false,
},
{name: "Number lower than percentage and both valid so take the percentage",
asgTags: []*autoscaling.TagDescription{
{
Key: aws.String("Name"),
Value: aws.String("asg-test"),
},
{
Key: aws.String(OnDemandPercentageTag),
Value: aws.String("75"),
},
{
Key: aws.String(OnDemandNumberLong),
Value: aws.String("2"),
},
},
asgInstances: makeInstancesWithCatalog(
instanceMap{
"id-1": {},
"id-2": {},
"id-3": {},
"id-4": {},
"id-5": {},
"id-6": {},
"id-7": {},
"id-8": {},
},
),
maxSize: aws.Int64(10),
numberExpected: 6,
loadingExpected: true,
},
{name: "Number higher than percentage and both valid so take the number",
asgTags: []*autoscaling.TagDescription{
{
Key: aws.String("Name"),
Value: aws.String("asg-test"),
},
{
Key: aws.String(OnDemandPercentageTag),
Value: aws.String("10"),
},
{
Key: aws.String(OnDemandNumberLong),
Value: aws.String("3"),
},
},
asgInstances: makeInstancesWithCatalog(
instanceMap{
"id-1": {},
"id-2": {},
"id-3": {},
"id-4": {},
},
),
maxSize: aws.Int64(10),
numberExpected: 3,
loadingExpected: true,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit c9c3ff1

Please sign in to comment.