Skip to content

Commit

Permalink
fix(resizeServerGroup): Use targetHealthyDeployPercentage when availa…
Browse files Browse the repository at this point in the history
…ble (#3785)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
vigneshm and mergify[bot] committed Jun 30, 2020
1 parent 1826063 commit 5280801
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ class WaitForCapacityMatchTask extends AbstractInstancesCheckTask {
desired = ((Map<String, Integer>)serverGroup.capacity).desired
}

splainer.add("checking if capacity matches (desired=${desired}, instances.size()=${instances.size()}) ")
if (desired != instances.size()) {
splainer.add("checking if capacity matches (desired=${desired}, target=${stage.context.targetDesiredSize ?: "none"} current=${instances.size()}) ")
if (stage.context.targetDesiredSize) {
// `targetDesiredSize` is derived from `targetHealthyDeployPercentage` and if present, then scaling has
// succeeded if the number of instances is greater than this value.
if (instances.size() < (stage.context.targetDesiredSize as Integer)) {
splainer.add("short-circuiting out of WaitForCapacityMatchTask because targetDesired and current capacity don't match")
return false
}
} else if (desired != instances.size()) {
splainer.add("short-circuiting out of WaitForCapacityMatchTask because expected and current capacity don't match}")
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WaitForCapacityMatchTaskSpec extends Specification {
oort.getServerGroup("test", "us-east-1", "kato-main-v000") >> { new Response('kato', 200, 'ok', [], new TypedString(mapper.writeValueAsString(serverGroup))) }
task.oortService = oort
def context = [account: "test", "deploy.server.groups": ["us-east-1": ["kato-main-v000"]]]
def stage = new StageExecutionImpl(PipelineExecutionImpl.newOrchestration("orca"), "resizeAsg", context)
def stage = new StageExecutionImpl(PipelineExecutionImpl.newOrchestration("orca"), "resizeAsg", context)

when:
def result = task.execute(stage)
Expand Down Expand Up @@ -175,6 +175,50 @@ class WaitForCapacityMatchTaskSpec extends Specification {
]
}

@Unroll
void 'should use targetHealthyDeployPercentage (if available) when determining if scaling has succeeded'() {
when:
def context = [
capacity: [
min: configured.min,
max: configured.max,
desired: configured.desired
],
targetHealthyDeployPercentage: targetHealthyDeployPercentage,
targetDesiredSize: targetHealthyDeployPercentage
? Math.round(targetHealthyDeployPercentage * configured.desired / 100) : null
]
def serverGroup = [
asg: [
desiredCapacity: asg.desired
],
capacity: [
min: asg.min,
max: asg.max,
desired: asg.desired
]
]
def instances = []
(1..healthy).each {
instances << [health: [[state: 'Up']]]
}
then:
result == task.hasSucceeded(
new StageExecutionImpl(PipelineExecutionImpl.newPipeline("orca"), "", "", context),
serverGroup, instances, null
)
where:
result || healthy | asg | configured | targetHealthyDeployPercentage
false || 5 | [min: 10, max: 15, desired: 15] | [min: 10, max: 15, desired: 15] | 85
false || 12 | [min: 10, max: 15, desired: 15] | [min: 10, max: 15, desired: 15] | 85
true || 13 | [min: 10, max: 15, desired: 15] | [min: 10, max: 15, desired: 15] | 85
false || 13 | [min: 10, max: 15, desired: 15] | [min: 10, max: 15, desired: 15] | null
}
@Unroll
void 'should wait based on configured capacity when autoscaling is disabled'() {
when:
Expand Down

0 comments on commit 5280801

Please sign in to comment.