feat(elasticloadbalancingv2): support Weighted Random algorithm and Automatic Target Weights for alb#30542
Conversation
lpizzinidev
left a comment
There was a problem hiding this comment.
Thanks 👍 Left comments for minor adjustments
packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts
Outdated
Show resolved
Hide resolved
packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.ts
Outdated
Show resolved
Hide resolved
packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts
Outdated
Show resolved
Hide resolved
packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts
Outdated
Show resolved
Hide resolved
packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/listener.test.ts
Outdated
Show resolved
Hide resolved
packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/target-group.test.ts
Outdated
Show resolved
Hide resolved
…ation-target-group.ts Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
…ation-listener.ts Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
…ation-target-group.ts Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
…ner.test.ts Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
…ner.test.ts Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
…t-group.test.ts Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
Co-authored-by: Luca Pizzini <lpizzini7@gmail.com>
2ef710f to
398b91d
Compare
|
@lpizzinidev |
|
|
||
| if (props.enableAnomalyMitigation !== undefined) { | ||
| if (props.enableAnomalyMitigation && isWeightedRandomAlgorithm) { | ||
| if (props.enableAnomalyMitigation && !isWeightedRandomAlgorithm) { |
There was a problem hiding this comment.
I want to throw an error when anomaly mitigation is enabled and the algorithm is not weighted_random, so I added a '!' before isWeightedRandomAlgorithm.
There was a problem hiding this comment.
The codechanges make sense to me but the only thing I'm not so keen on is enforcing the restrictions on the properties:
weighted_randomalgorithm cannot be used in slow start mode- anomaly mitigation can only be enabled when the
weighted_randomalgorithm is used
with error handling in the constructor. For this current case it works fine because we're not adding much but this can slowly grow over time into a wall of error handling checks as more properties with restrictions are added.
What I had in mind here was to instead create another version of this class that specifically has the weighted_random algorithm set by default and does not allow the user to set other conflicting properties to remove the need for these error checks.
i.e. A class like ApplicationTargetGroupWeightedRandomRouting or something where the anomaly mitigation can be enabled or not without the need for error handling and slow start mode is disabled and cannot be enabled.
Although part of me worries that this may be a bit confusing as a DX to use because we're not providing the option through ApplicationTargetGroup and I'm not sure how many other routing algorithm options there are that we may not have done this for. What do you think?
There was a problem hiding this comment.
Thank you for your suggestion.
Personally, I like the current consolidated form of ApplicationTargetGroup.
- While there are other routing algorithms such as Least outstanding requests, I think having only weighted random as a separate class would be confusing for users.
- Additionally, I think that the current restriction is not complex enough to warrant a separate class.
- There are common items with other routing algorithms such as stickiness.enabled, and it's easier to understand when they are grouped together.
For the reasons mentioned above, I personally think the current format is preferable.
However, as you've expressed concern, your suggestion might be better considering the possibility of increased constraints in the future.
But honestly, I'm not sure if they will increase...
Given the above, I'd appreciate your thoughts on this.
There was a problem hiding this comment.
Thanks for sharing your thoughts.
After hearing your reasonings I agree that separating out a new class just for this algorithm is probably not necessary. As you mentioned, the restriction is not super complex so I'm okay to accept this change as is.
Thanks @mazyu36!
paulhcsun
left a comment
There was a problem hiding this comment.
Hi @mazyu36, thank you for your contribution! I just left one comment regarding the error checks in the constructor to enforce a couple of the restrictions of using the weighted_random algorithm. Let me know what you think!
| }); | ||
| ``` | ||
|
|
||
| ### Weighted random routing algorithms and automatic target weights for your Application Load Balancer |
There was a problem hiding this comment.
Can we also document the. restriction that the weighted_random algorithm cannot be used with slow start mode?
There was a problem hiding this comment.
Thanks. I've updated docs.
|
|
||
| if (props.enableAnomalyMitigation !== undefined) { | ||
| if (props.enableAnomalyMitigation && isWeightedRandomAlgorithm) { | ||
| if (props.enableAnomalyMitigation && !isWeightedRandomAlgorithm) { |
There was a problem hiding this comment.
The codechanges make sense to me but the only thing I'm not so keen on is enforcing the restrictions on the properties:
weighted_randomalgorithm cannot be used in slow start mode- anomaly mitigation can only be enabled when the
weighted_randomalgorithm is used
with error handling in the constructor. For this current case it works fine because we're not adding much but this can slowly grow over time into a wall of error handling checks as more properties with restrictions are added.
What I had in mind here was to instead create another version of this class that specifically has the weighted_random algorithm set by default and does not allow the user to set other conflicting properties to remove the need for these error checks.
i.e. A class like ApplicationTargetGroupWeightedRandomRouting or something where the anomaly mitigation can be enabled or not without the need for error handling and slow start mode is disabled and cannot be enabled.
Although part of me worries that this may be a bit confusing as a DX to use because we're not providing the option through ApplicationTargetGroup and I'm not sure how many other routing algorithm options there are that we may not have done this for. What do you think?
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
@paulhcsun |
paulhcsun
left a comment
There was a problem hiding this comment.
Nice work @mazyu36!
And thanks for the review as always @lpizzinidev!
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #29969
Reason for this change
Application Load Balancer supports Weight Random routing Algorithm and Automatic Target Weights. (link)
But current L2 construct does not support it.
Description of changes
weighted_randomalgorithm to ENUM.Description of how you validated changes
Add unit tests and integ tests.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license