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

fix(autoscaling): step scaling without adjustment type fails #29158

Merged
merged 6 commits into from
Feb 28, 2024

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Feb 19, 2024

Reason for this change

Step Scaling without adjustmentType fails with CFn error You must specify an AdjustmentType for policy type: StepScaling.

  • Reproduction code
const asg = new autoscaling.AutoScalingGroup(stack, 'ASG', {
  vpc,
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
  machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }),
});

asg.scaleOnMetric('StepScaling', {
  metric: new cloudwatch.Metric({ namespace: 'AWS/EC2', metricName: 'CPUUtilization', dimensionsMap: { AutoScalingGroupName: asg.autoScalingGroupName } }),
  scalingSteps: [
    { upper: 10, change: -1 },
    { lower: 50, change: +1 },
    { lower: 90, change: +2 },
  ],
  evaluationPeriods: 10,
  datapointsToAlarm: 5,
  metricAggregationType: autoscaling.MetricAggregationType.MAXIMUM,

  // adjustmentType: autoscaling.AdjustmentType.CHANGE_IN_CAPACITY,
});

Description of changes

According to the CDK code, CHANGE_IN_CAPACITY will be used if adjustmentType is not specified in the prop. But the variable is not passed into StepScalingAction construct (instead props.adjustmentType is passed as is).

The documentation also says that the default value is CHANGE_IN_CAPACITY.

So we should use adjustmentType instead of props.adjustmentType.

    const adjustmentType = props.adjustmentType || AdjustmentType.CHANGE_IN_CAPACITY;
    const changesAreAbsolute = adjustmentType === AdjustmentType.EXACT_CAPACITY;
    // ...
    // ...

      this.lowerAction = new StepScalingAction(this, 'LowerPolicy', {
        // adjustmentType: props.adjustmentType,
        adjustmentType,

The fact that the error occurs if props.adjustmentType is not specified means that the user's successful existing stack always specifies props.adjustmentType. In other words, no change to the existing resource will occur due to this change, so there is no need for a feature flag.

Description of how you validated changes

Unit tests without integ tests, because this PR could cover this bug by unit tests.
Both unit 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 the p2 label Feb 19, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team February 19, 2024 09:20
@github-actions github-actions bot added the distinguished-contributor [Pilot] contributed 50+ PRs to the CDK label Feb 19, 2024
@@ -147,7 +147,7 @@ export class StepScalingPolicy extends Construct {
const threshold = intervals[alarms.lowerAlarmIntervalIndex].upper;

this.lowerAction = new StepScalingAction(this, 'LowerPolicy', {
adjustmentType: props.adjustmentType,
adjustmentType,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The property is defined here.

@go-to-k
Copy link
Contributor Author

go-to-k commented Feb 19, 2024

Exemption Request: This PR could cover this bug by unit tests.

I could change an integ test and snapshots

@go-to-k go-to-k marked this pull request as ready for review February 19, 2024 09:21
@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Feb 19, 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.

@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 Feb 19, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 20, 2024 06:12

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

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.

Looks good to me 👍

…/test/integ.asg-step-scaling.ts

Co-authored-by: Luca Pizzini <[email protected]>
@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 Feb 25, 2024
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for contributing

Copy link
Contributor

mergify bot commented Feb 28, 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 Feb 28, 2024
@mergify mergify bot merged commit a7de7fe into aws:main Feb 28, 2024
12 checks passed
Copy link
Contributor

mergify bot commented Feb 28, 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: c40ab28
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants