fix(autoscaling): pause suspended capacity adjustments (#5545)

* fix(autoscaling): pause suspended capacity adjustments

* test(autoscaling): cover suspended capacity through AWS clients

* fix(autoscaling): coordinate suspension with capacity changes

* fix(autoscaling): keep capacity locks within each account

* test(autoscaling): check suspension without scheduler waits
This commit is contained in:
David Phillips authored and GitHub committed 2026-10-13 09:37:17 -04:00
1 parent 2927a4520e
commit 41517f3c2f
8 files changed
+535 -56

No files matched your search

@@ -129,14 +129,16 @@ public class AutoScalingReconciler {
removeOrphanedTargetRegistrations(asg);
promoteReadyInstances(asg);
long activeCapacity = activeCapacity(asg);
int desired = asg.getDesiredCapacity();
asgService.adjustCapacityIfPresent(asg, () -> {
long activeCapacity = activeCapacity(asg);
int desired = asg.getDesiredCapacity();
if (activeCapacity < desired) {
scaleOut(asg, (int) (desired - activeCapacity));
} else if (activeCapacity > desired) {
scaleIn(asg, (int) (activeCapacity - desired));
}
if (activeCapacity < desired && !asg.getSuspendedProcesses().contains("Launch")) {
scaleOut(asg, (int) (desired - activeCapacity));
} else if (activeCapacity > desired && !asg.getSuspendedProcesses().contains("Terminate")) {
scaleIn(asg, (int) (activeCapacity - desired));
}
});
if (asgService.saveAutoScalingGroupIfPresent(asg)) {
asgService.completeInstanceRefreshIfSettled(asg.getRegion(), asg.getAutoScalingGroupName());
}
@@ -493,8 +493,17 @@ public class AutoScalingService {
}
}
void adjustCapacityIfPresent(AutoScalingGroup asg, Runnable adjustment) {
String key = asgKey(asg.getRegion(), asg.getAutoScalingGroupName());
synchronized (lockFor(key)) {
if (groups.get(key) == asg) {
adjustment.run();
}
}
}
private Object lockFor(String key) {
return groupLocks.computeIfAbsent(key, ignored -> new Object());
return groupLocks.computeIfAbsent(regionResolver.getAccountId() + "::" + key, ignored -> new Object());
}
Set<String> autoScalingGroupAccountIds() {
@@ -544,36 +553,38 @@ public class AutoScalingService {
return requireGroup(region, resourceId);
}
// Real AWS suspends the named scaling processes ("Launch", "Terminate", "HealthCheck", ...)
// so they stop running until resumed; an empty list suspends all of them. Floci has no
// scaling loop for these processes to pause, so this only needs to record which processes
// are suspended for DescribeAutoScalingGroups to report back - the same "accept and
// remember" shape as terminationPolicies. The AWS provider calls this unconditionally
// around ASG creation whenever wait_for_capacity_timeout is non-zero (the default), so an
// unimplemented SuspendProcesses fails ASG creation outright, not just a feature gap.
// An empty list suspends all processes. The reconciler honors Launch and Terminate
// for desired-capacity adjustments; other names remain stored state. Refresh selection
// and cleanup are separate paths and do not yet honor suspended processes.
private static final List<String> ALL_SCALING_PROCESSES = List.of(
"Launch", "Terminate", "AddToLoadBalancer", "AlarmNotification", "AZRebalance",
"HealthCheck", "InstanceRefresh", "ReplaceUnhealthy", "ScheduledActions");
public void suspendProcesses(String region, String name, List<String> processes) {
AutoScalingGroup asg = requireGroup(region, name);
List<String> toSuspend = processes.isEmpty() ? ALL_SCALING_PROCESSES : processes;
Set<String> suspended = new LinkedHashSet<>(asg.getSuspendedProcesses());
suspended.addAll(toSuspend);
asg.setSuspendedProcesses(new ArrayList<>(suspended));
groups.put(asgKey(region, name), asg);
String key = asgKey(region, name);
synchronized (lockFor(key)) {
AutoScalingGroup asg = requireGroup(region, name);
List<String> toSuspend = processes.isEmpty() ? ALL_SCALING_PROCESSES : processes;
Set<String> suspended = new LinkedHashSet<>(asg.getSuspendedProcesses());
suspended.addAll(toSuspend);
asg.setSuspendedProcesses(new ArrayList<>(suspended));
groups.put(key, asg);
}
}
public void resumeProcesses(String region, String name, List<String> processes) {
AutoScalingGroup asg = requireGroup(region, name);
if (processes.isEmpty()) {
asg.setSuspendedProcesses(new ArrayList<>());
} else {
List<String> remaining = new ArrayList<>(asg.getSuspendedProcesses());
remaining.removeAll(processes);
asg.setSuspendedProcesses(remaining);
String key = asgKey(region, name);
synchronized (lockFor(key)) {
AutoScalingGroup asg = requireGroup(region, name);
if (processes.isEmpty()) {
asg.setSuspendedProcesses(new ArrayList<>());
} else {
List<String> remaining = new ArrayList<>(asg.getSuspendedProcesses());
remaining.removeAll(processes);
asg.setSuspendedProcesses(remaining);
}
groups.put(key, asg);
}
groups.put(asgKey(region, name), asg);
}
// ── Instance management ────────────────────────────────────────────────────