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(applicationautoscaling): typo in DYANMODB_WRITE_CAPACITY_UTILIZATION #18085

Merged
merged 9 commits into from
Jan 14, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,14 @@ export enum PredefinedMetric {
/**
* DYANMODB_WRITE_CAPACITY_UTILIZATION
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
* @deprecated use `PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION`
*/
DYANMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization',
/**
* DYNAMODB_WRITE_CAPACITY_UTILIZATION
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
DYNAMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization',
Copy link
Contributor

Choose a reason for hiding this comment

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

The new property needs to be above the deprecated property (see #17731 for details).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as proposed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@comcalvi Do you have any ideas how I could fix the build error? Value DYANMODB_WRITE_CAPACITY_UTILIZATION was not removed. Is there something wrong with the validation? Thanks.

@aws-cdk/aws-applicationautoscaling... CHANGES.
Original assembly: @aws-cdk/[email protected]
Updated assembly:  @aws-cdk/[email protected]
API elements with incompatible changes:
err  - ENUM VALUE @aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION: member DYANMODB_WRITE_CAPACITY_UTILIZATION has been removed [removed:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION]

Copy link
Contributor

Choose a reason for hiding this comment

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

@jumic I was mistaken about the effects of the above-mentioned jsii bug. It turns out that because only the first enum member is accepted, the second one is entirely removed from the jsii assembly, which is equivalent to deleting it; this results in a breaking change.

The only way to truly fix this is to give the new enum a dummy value that will be replaced by the correct value whenever it's used. We can do this as follows:

  1. Change the value of DYNAMODB_WRITE_CAPACITY_UTILIZATION to a dummy value, something like 'DynamoDBWriteCapacityUtilization-dummy'.
  2. Anytime the props are used to assign a value (pretty sure here is the only spot), add a check (if statement or ternary operator, preferably) to find the dummy value and replace it with the correct value (which DYANMODB_WRITE_CAPACITY_UTILIZATION will have).

Would you be willing to make those changes? It's totally fine if you're not, this is a good bit more work than this change should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@comcalvi Thanks, this fixed the build.
I also added a test case for this special logic. I hope this is okay.

/**
* ALB_REQUEST_COUNT_PER_TARGET
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-applicationautoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.StepScalingPolicyProps",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.ECS_SERVICE_AVERAGE_CPU_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYNAMODB_READ_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.ALB_REQUEST_COUNT_PER_TARGET",
"docs-public-apis:@aws-cdk/aws-applicationautoscaling.PredefinedMetric.RDS_READER_AVERAGE_CPU_UTILIZATION",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ScalableTableAttribute extends appscaling.BaseScalableAttribute {
}
this.scalingPolicyCreated = true;
const predefinedMetric = this.props.dimension.indexOf('ReadCapacity') === -1
? appscaling.PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION
? appscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION
: appscaling.PredefinedMetric.DYNAMODB_READ_CAPACITY_UTILIZATION;

super.doScaleToTrackMetric('Tracking', {
Expand Down