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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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.

cooldown: props.cooldown,
estimatedInstanceWarmup: props.estimatedInstanceWarmup,
metricAggregationType: props.metricAggregationType ?? aggregationTypeFromMetric(props.metric),
Expand Down Expand Up @@ -179,7 +179,7 @@ export class StepScalingPolicy extends Construct {
const threshold = intervals[alarms.upperAlarmIntervalIndex].lower;

this.upperAction = new StepScalingAction(this, 'UpperPolicy', {
adjustmentType: props.adjustmentType,
adjustmentType,
cooldown: props.cooldown,
estimatedInstanceWarmup: props.estimatedInstanceWarmup,
metricAggregationType: props.metricAggregationType ?? aggregationTypeFromMetric(props.metric),
Expand Down
22 changes: 22 additions & 0 deletions packages/aws-cdk-lib/aws-autoscaling/test/scaling.test.ts
Expand Up @@ -294,6 +294,28 @@ test('step scaling from percentile metric', () => {
});
});

test('step scaling with adjustmentType by default', () => {
// GIVEN
const stack = new cdk.Stack();
const fixture = new ASGFixture(stack, 'Fixture');

// WHEN
fixture.asg.scaleOnMetric('Tracking', {
metric: new cloudwatch.Metric({ namespace: 'Test', metricName: 'Metric', statistic: 'p99' }),
scalingSteps: [
{ upper: 0, change: -1 },
{ lower: 100, change: +1 },
{ lower: 500, change: +5 },
],
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::ScalingPolicy', {
PolicyType: 'StepScaling',
AdjustmentType: 'ChangeInCapacity',
});
});

test('step scaling with evaluation period configured', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down