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(autoscaling): add availabilityZoneDistribution property to an AutoScalingGroup #32100

Merged

Conversation

ren-yamanashi
Copy link
Contributor

@ren-yamanashi ren-yamanashi commented Nov 12, 2024

Issue # (if applicable)

n/A

Reason for this change

We can set a availabilityZoneDistribution for an AutoScalingGroup from cloudformation, but this was not supported in the AWS CDK L2 construct.

Description of changes

Add availabilityZoneDistribution property to CommonAutoScalingGroupProps and set it in the CfnAutoScalingGroup.

Description of how you validated changes

Added both unit and integration 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 the p2 label Nov 12, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team November 12, 2024 15:18
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Nov 12, 2024
@ren-yamanashi ren-yamanashi changed the title WIP: feat(aws-autoscaling): add availabilityZoneDistribution property to a AutoScalingGroup feat(aws-autoscaling): add availabilityZoneDistribution property to a AutoScalingGroup Nov 12, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@ren-yamanashi ren-yamanashi changed the title feat(aws-autoscaling): add availabilityZoneDistribution property to a AutoScalingGroup feat(autoscaling): add availabilityZoneDistribution property to a AutoScalingGroup Nov 12, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review November 13, 2024 06:21

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@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 Nov 13, 2024
@ren-yamanashi ren-yamanashi changed the title feat(autoscaling): add availabilityZoneDistribution property to a AutoScalingGroup feat(autoscaling): add availabilityZoneDistribution property to an AutoScalingGroup Nov 23, 2024
Copy link

codecov bot commented Nov 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.54%. Comparing base (a81eec6) to head (ba90575).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32100   +/-   ##
=======================================
  Coverage   80.54%   80.54%           
=======================================
  Files         106      106           
  Lines        6954     6954           
  Branches     1287     1287           
=======================================
  Hits         5601     5601           
  Misses       1175     1175           
  Partials      178      178           
Flag Coverage Δ
suite.unit 80.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 80.54% <ø> (ø)

Copy link
Contributor

@mazyu36 mazyu36 left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution.
I've commented on property design.
If you have any thoughts on that please let me know.

* The instance capacity distribution across Availability Zones.
* @default { capacityDistributionStrategy: CapacityDistributionStrategy.BALANCED_BEST_EFFORT }
*/
readonly availabilityZoneDistribution?: AvailabilityZoneDistribution;
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, we can reduce a nest like this:

readonly azCapacityDistributionStrategy?: CapacityDistributionStrategy;

In the design docs, fewer nesting is preferred.

@@ -1529,6 +1560,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements

const asgProps: CfnAutoScalingGroupProps = {
autoScalingGroupName: this.physicalName,
availabilityZoneDistribution: props.availabilityZoneDistribution,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we reduce nest, we can set property like this:

availabilityZoneDistribution: props.azCapacityDistributionStrategy ?  { capacityDistributionStrategy: props.azCapacityDistributionStrategy }  : undefined,

@ren-yamanashi
Copy link
Contributor Author

ren-yamanashi commented Dec 19, 2024

Thank you for the contribution. I've commented on property design. If you have any thoughts on that please let me know.

@mazyu36

Thank you for review!
I have corrected the issue in the following commit, please confirm.

478f2ac

@ren-yamanashi
Copy link
Contributor Author

@Mergifyio update

Copy link
Contributor

mergify bot commented Dec 19, 2024

update

☑️ Nothing to do

  • #commits-behind > 0 [📌 update requirement]
  • -closed [📌 update requirement]
  • -conflict [📌 update requirement]
  • queue-position = -1 [📌 update requirement]

@ren-yamanashi
Copy link
Contributor Author

@Mergifyio update

Copy link
Contributor

mergify bot commented Dec 19, 2024

update

☑️ Nothing to do

  • #commits-behind > 0 [📌 update requirement]
  • -closed [📌 update requirement]
  • -conflict [📌 update requirement]
  • queue-position = -1 [📌 update requirement]

@ren-yamanashi
Copy link
Contributor Author

ren-yamanashi commented Dec 19, 2024

I am getting the following error in Codecov / collect

Report creating failed: {“message”: “Token required because branch is protected”}

However, I do not have this branch protected and am not sure of the direct cause.

Also, CodeBuild is failing, but the changes I made do not seem to be the cause of the failure.

How can I resolve these issues?

Copy link
Contributor

@mazyu36 mazyu36 left a comment

Choose a reason for hiding this comment

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

Thanks! Some minor comments.
I'm not sure why Codecov failed.
Let's see if the issue persists after the changes are applied.


/**
* The strategy for distributing instances across Availability Zones.
* @default BALANCED_BEST_EFFORT
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @default BALANCED_BEST_EFFORT
* @default CapacityDistributionStrategy.BALANCED_BEST_EFFORT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/**
* If launches fail in an Availability Zone, Auto Scaling will attempt to launch in another healthy Availability Zone instead.
*/
BALANCED_BEST_EFFORT= 'balanced-best-effort',
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: space

Suggested change
BALANCED_BEST_EFFORT= 'balanced-best-effort',
BALANCED_BEST_EFFORT = 'balanced-best-effort',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ren-yamanashi
Copy link
Contributor Author

ren-yamanashi commented Dec 19, 2024

Thanks! Some minor comments. I'm not sure why Codecov failed. Let's see if the issue persists after the changes are applied.

@mazyu36

Thank you for comment!
I have corrected the issue, please confirm.
( I have included a link to the corrected commit in the thread)

Also, I fixed the default value of capacityDistributionStrategy was not applied correctly.
Please check this as well 🙏

bda5050

(Codecov seems to have fixed it too! Thank you 😆 )

@@ -1530,6 +1550,9 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements

const asgProps: CfnAutoScalingGroupProps = {
autoScalingGroupName: this.physicalName,
availabilityZoneDistribution: props.azCapacityDistributionStrategy
? { capacityDistributionStrategy: props.azCapacityDistributionStrategy }
: { capacityDistributionStrategy: CapacityDistributionStrategy.BALANCED_BEST_EFFORT },
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the fix.
But I think default value should be undefined.
The @default should describe the behavior at that time.

When the default value is explicitly set, it causes a breaking change.
This is because before and after this PR merged, the synth result changes when props.azCapacityDistributionStrategy is omitted.

Copy link
Contributor Author

@ren-yamanashi ren-yamanashi Dec 19, 2024

Choose a reason for hiding this comment

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

@mazyu36

thank you!

I see, I understand.

So, I will also omit the description of default in JSDoc, is that correct?
(Because there was no mention of default values in the CloudFormation documentation...)
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-autoscaling-autoscalinggroup-availabilityzonedistribution.html

  /**
   * The strategy for distributing instances across Availability Zones.
-  * @default CapacityDistributionStrategy.BALANCED_BEST_EFFORT
   */
  readonly azCapacityDistributionStrategy?: CapacityDistributionStrategy;

Copy link
Contributor

Choose a reason for hiding this comment

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

For optional properties, @default is necessary.

Also, it's common that default value behaviors are not documented in the CFn documentation.
In such cases, I often verify the default value by deploying without specifying the value.

When I tried deploying it without availabilityZoneDistribution property, the value became Balanced best effort, so I think this is the default value.

image

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 the details.
I have corrected it with the following commit!

ea1e756

Copy link
Contributor

@mazyu36 mazyu36 left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Dec 19, 2024
Copy link
Contributor

mergify bot commented Dec 23, 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).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 23, 2024
Copy link
Contributor

mergify bot commented Dec 23, 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).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Contributor

mergify bot commented Dec 24, 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 ecfce7c into aws:main Dec 24, 2024
17 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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants