Repository navigation
fix(autoscaling): register instances with a Classic Load Balancer on attach and deregister them on detach - #8496
Conversation
…attach and deregister them on detach AttachLoadBalancers and DetachLoadBalancers only stored the Classic Load Balancer's name, so the group's instances joined a load balancer only as they were launched, and stayed in one after it was detached. They now go through changeAttachments, as the target group calls do since floci-io#8469: the group's instances leave a detached load balancer before the change is stored, and its InService instances join an attached one. A refused deregistration puts back everything the change detached, as a refused target group does, so sending the detach again finishes it. elb traffic sources count as Classic Load Balancers throughout, as elbv2 sources count as target groups: for registration as instances come into service and for deregistration as they leave. The reconciler's Classic registration moves next to registerWithTargetGroups, so both take the same path. An EKS group's node is kept in step with the group's Classic Load Balancers as with its target groups: it joins them when it is added, and a detach, a deleted group or a detached node takes it out of only those no other group holding it has attached.
PR Summary by QodoRegister and deregister Classic ELB instances when ASG attachments change
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1.
|
… refused A detach takes the group's members out of the target groups and Classic Load Balancers it names one at a time. When one refuses, the group keeps them all attached, but the members had already left those processed before it, so a target group could stay attached without them until the detach was sent again. The in-service members now rejoin each load balancer they already left before the failure is returned, so the group is as it was. From Qodo's review of floci-io#8496.
|
On Qodo's second finding (attach logs a Classic registration failure and succeeds): that is deliberate, as for target groups in #8469. AWS attaches a load balancer asynchronously: |
|
@mrfelek thanks, this reads well. Putting the members back in what they already left when a detach is refused closes the partial-failure gap, and logging a failed registration on attach matches the target group path from #8469. One thing before it can go in: the new test copies its fixtures. The constants, the constructor's group and |
|
Thanks, will do: the group with one |
There was a problem hiding this comment.
Follow-up at 300b0a0: compiled the extracted shared fixtures and directly ran 25 test methods across Classic ELB attachment, target-group attachment, and EKS managed-group tests; all passed. Production is unchanged from my prior dd061ef review. Validation uses mocked ELB dependencies, not full JUnit, HTTP/SDK, or live AWS.
From the review of floci-io#8496. AutoScalingClassicLoadBalancerAttachmentTest copied its ordinary group, with one member in service and one in standby, from AutoScalingTargetGroupAttachmentTest, and its EKS groups sharing a node from AutoScalingEksManagedGroupTest. AutoScalingGroupFixtures now holds them: the constants, the service, the ordinary group and member, and the node, its groups' tags and groupsSharingTheNode. The three classes build on it, with their tests as they were.
|
Done in 300b0a0: The red |
|
A correction to my note above: |
|
Found it: the same |
pgermosen
left a comment
There was a problem hiding this comment.
@mrfelek thanks, AutoScalingGroupFixtures is what I had in mind: the three classes now build on one ordinary group and one pair of EKS groups, with their tests as they were. Registering on attach, deregistering on detach and putting the members back when a detach is refused all read well.
Summary
Follow-up to #8469, from its review:
AttachLoadBalancersandDetachLoadBalancersonly recorded the Classic Load Balancer's name. The group's instances joined a Classic Load Balancer only as the reconciler brought each into service, so those already in service stayed out of one attached later, and every instance stayed in one detached from its group. AWS registers the group's running instances on attach and deregisters them on detach. Classic Load Balancers attached aselbtraffic sources were only recorded too.Both operations now go through
changeAttachments, the path #8469 gave the target group calls:attachedClassicLoadBalancersgives the Classic Load Balancers a group has attached: by name, and aselbtraffic sources. It sits besideattachedTargetGroups(target groups andelbv2sources), and both read through one helper.deregisterFromClassicLoadBalancersalready skipsLoadBalancerNotFound.InServiceinstances are then registered with the Classic Load Balancers the change attached. One inStandbyorPendingis not; the reconciler registers it as it comes into service.deregisterFromUnsharedTargetGroupsand the newderegisterFromUnsharedClassicLoadBalancersshare that look at the Region's other groups.elbtraffic sources now count as Classic Load Balancers wherever instances join or leave one.deregisterFromClassicLoadBalancers(elb, asg, ids), which detaching instances, standby, force delete and every reconciler removal call, readsattachedClassicLoadBalancers. The reconciler's registration of an instance coming into service moves fromAutoScalingReconcilertoAutoScalingService.registerWithClassicLoadBalancers, besideregisterWithTargetGroups, and reads it too.docs/services/autoscaling.mddescribedAttachLoadBalancersas "stored",DetachLoadBalancersas a detachment only, and the traffic source operations as registering withelbv2sources only. The four rows now describe what the operations do.Not in this PR:
AttachInstancesputs the instances in service without registering them with the group's target groups or Classic Load Balancers, as on main.EksServicelogs the failure and deletes the node group.Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
The
AttachLoadBalancersreference has "Amazon EC2 Auto Scaling registers the running instances with these Classic Load Balancers", andDetachLoadBalancershas "When you detach a load balancer, it enters the Removing state while deregistering the instances in the group". botocore's Auto Scaling model givesLoadBalancerState's states as "Adding - The Auto Scaling instances are being registered with the load balancer" and "Removing - The Auto Scaling instances are being deregistered from the load balancer".Checklist
./mvnw test: the 105 test classes the change can affect (the Auto Scaling and EKS classes, and those naming a changed class) pass on Temurin 25 (1,811 tests), with checkstyle;make docs-checkpasses. This PR's CI runs the full suite.New or updated tests added:
AutoScalingClassicLoadBalancerAttachmentTest, on an ordinary group with oneInServiceand oneStandbyinstance, mirroringAutoScalingTargetGroupAttachmentTest:elbtraffic source registers and deregisters the instances as a Classic Load Balancer does.elbtraffic source as well as from the load balancers attached by name.elbv2and anelbsource, refused by the Classic Load Balancer, puts the in-service instance back in the target group it already left and leaves both attached; sending it again finishes it.elbsource, and detaching it there takes the node out.All but the deleted-load-balancer test fail on main. That one passes there, since main sends no deregistration on detach, and guards the new path's handling of a deleted load balancer.
AutoScalingGroupFixturesholds the groups this class,AutoScalingTargetGroupAttachmentTestandAutoScalingEksManagedGroupTestshare: the ordinary group and its members, and the EKS groups sharing a node.AutoScalingStandbyTest.returningInstanceRetriesFailedRegistrationBeforeCompletingActivitynow captures the Classic registration's warning fromAutoScalingService, where it is logged since the move. Every Auto Scaling test class andEksNodegroupAutoScalingGroupIntegrationTestpass (809 tests).Commit messages follow Conventional Commits
I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).