Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(elasticloadbalancingv2): support Weighted Random algorithm and Automatic Target Weights for alb #30542

Merged
merged 17 commits into from
Jul 30, 2024

Conversation

mazyu36
Copy link
Contributor

@mazyu36 mazyu36 commented Jun 13, 2024

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

  • Add weighted_random algorithm to ENUM.
  • Add a flag for setting Automatic Target Weights anomaly mitigation.

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

@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Jun 13, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team June 13, 2024 11:16
@github-actions github-actions bot added the admired-contributor [Pilot] contributed between 13-24 PRs to the CDK label Jun 13, 2024
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 13, 2024
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍 Left comments for minor adjustments

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 14, 2024
mazyu36 and others added 8 commits June 15, 2024 05:35
…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>
@mazyu36 mazyu36 force-pushed the elb-automatic-target-weights-29969 branch 2 times, most recently from 2ef710f to 398b91d Compare June 15, 2024 12:48
@mazyu36
Copy link
Contributor Author

mazyu36 commented Jun 15, 2024

@lpizzinidev
Thank you for the review. I have incorporated your suggestions and made the modifications.

@@ -367,13 +367,11 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
this.addTarget(...(props.targets || []));

if (props.enableAnomalyMitigation !== undefined) {
if (props.enableAnomalyMitigation && isWeightedRandomAlgorithm) {
if (props.enableAnomalyMitigation && !isWeightedRandomAlgorithm) {
Copy link
Contributor Author

@mazyu36 mazyu36 Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to throw an error when anomaly mitigation is enabled and the algorithm is not weighted_random, so I added a '!' before isWeightedRandomAlgorithm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codechanges make sense to me but the only thing I'm not so keen on is enforcing the restrictions on the properties:

  • weighted_random algorithm cannot be used in slow start mode
  • anomaly mitigation can only be enabled when the weighted_random algorithm 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jun 15, 2024
@paulhcsun paulhcsun self-assigned this Jul 26, 2024
Copy link
Contributor

@paulhcsun paulhcsun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@@ -458,6 +458,24 @@ const tg = new elbv2.ApplicationTargetGroup(this, 'TG', {
});
```

### Weighted random routing algorithms and automatic target weights for your Application Load Balancer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also document the. restriction that the weighted_random algorithm cannot be used with slow start mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've updated docs.

@@ -367,13 +367,11 @@ export class ApplicationTargetGroup extends TargetGroupBase implements IApplicat
this.addTarget(...(props.targets || []));

if (props.enableAnomalyMitigation !== undefined) {
if (props.enableAnomalyMitigation && isWeightedRandomAlgorithm) {
if (props.enableAnomalyMitigation && !isWeightedRandomAlgorithm) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codechanges make sense to me but the only thing I'm not so keen on is enforcing the restrictions on the properties:

  • weighted_random algorithm cannot be used in slow start mode
  • anomaly mitigation can only be enabled when the weighted_random algorithm 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-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 29, 2024
@mergify mergify bot dismissed paulhcsun’s stale review July 30, 2024 03:13

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: e1733c1
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mazyu36
Copy link
Contributor Author

mazyu36 commented Jul 30, 2024

@paulhcsun
Thank you for the review !
I've addressed all your comments.

@mazyu36 mazyu36 requested a review from paulhcsun July 30, 2024 04:17
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 30, 2024
Copy link
Contributor

@paulhcsun paulhcsun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @mazyu36!

And thanks for the review as always @lpizzinidev!

Copy link
Contributor

mergify bot commented Jul 30, 2024

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).

@mergify mergify bot merged commit d0a609d into aws:main Jul 30, 2024
15 checks passed
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 30, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2024
@mazyu36 mazyu36 deleted the elb-automatic-target-weights-29969 branch July 30, 2024 22:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-elasticloadbalancingv2): Add the weighted_random load balancing algorithm
4 participants