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 all 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -643,6 +643,99 @@
"Statistic": "Average",
"Threshold": 50
}
},
"ASGStepScalingWithDefaultAdjustmentTypeLowerPolicyA6C1EA33": {
"Type": "AWS::AutoScaling::ScalingPolicy",
"Properties": {
"AdjustmentType": "ChangeInCapacity",
"AutoScalingGroupName": {
"Ref": "ASG46ED3070"
},
"MetricAggregationType": "Maximum",
"PolicyType": "StepScaling",
"StepAdjustments": [
{
"MetricIntervalUpperBound": 0,
"ScalingAdjustment": -1
}
]
}
},
"ASGStepScalingWithDefaultAdjustmentTypeLowerAlarmF9F52487": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmActions": [
{
"Ref": "ASGStepScalingWithDefaultAdjustmentTypeLowerPolicyA6C1EA33"
}
],
"AlarmDescription": "Lower threshold scaling alarm",
"ComparisonOperator": "LessThanOrEqualToThreshold",
"DatapointsToAlarm": 5,
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": {
"Ref": "ASG46ED3070"
}
}
],
"EvaluationPeriods": 10,
"MetricName": "DiskWriteOps",
"Namespace": "AWS/EC2",
"Period": 300,
"Statistic": "Average",
"Threshold": 100
}
},
"ASGStepScalingWithDefaultAdjustmentTypeUpperPolicy08CC2D99": {
"Type": "AWS::AutoScaling::ScalingPolicy",
"Properties": {
"AdjustmentType": "ChangeInCapacity",
"AutoScalingGroupName": {
"Ref": "ASG46ED3070"
},
"MetricAggregationType": "Maximum",
"PolicyType": "StepScaling",
"StepAdjustments": [
{
"MetricIntervalLowerBound": 0,
"MetricIntervalUpperBound": 200,
"ScalingAdjustment": 1
},
{
"MetricIntervalLowerBound": 200,
"ScalingAdjustment": 2
}
]
}
},
"ASGStepScalingWithDefaultAdjustmentTypeUpperAlarm2379E17B": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmActions": [
{
"Ref": "ASGStepScalingWithDefaultAdjustmentTypeUpperPolicy08CC2D99"
}
],
"AlarmDescription": "Upper threshold scaling alarm",
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
"DatapointsToAlarm": 5,
"Dimensions": [
{
"Name": "AutoScalingGroupName",
"Value": {
"Ref": "ASG46ED3070"
}
}
],
"EvaluationPeriods": 10,
"MetricName": "DiskWriteOps",
"Namespace": "AWS/EC2",
"Period": 300,
"Statistic": "Average",
"Threshold": 300
}
}
},
"Parameters": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -30,6 +30,17 @@ asg.scaleOnMetric('StepScaling', {
datapointsToAlarm: 5,
metricAggregationType: autoscaling.MetricAggregationType.MAXIMUM,
});
asg.scaleOnMetric('StepScalingWithDefaultAdjustmentType', {
metric: new cloudwatch.Metric({ namespace: 'AWS/EC2', metricName: 'DiskWriteOps', dimensionsMap: { AutoScalingGroupName: asg.autoScalingGroupName } }),
scalingSteps: [
{ upper: 100, change: -1 },
{ lower: 300, change: +1 },
{ lower: 500, change: +2 },
],
evaluationPeriods: 10,
datapointsToAlarm: 5,
metricAggregationType: autoscaling.MetricAggregationType.MAXIMUM,
});

new integ.IntegTest(app, 'autoscaling-step-scaling-integ', {
testCases: [stack],
Expand Down
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