Skip to content

Commit

Permalink
fix(applicationautoscaling): typo in `DYANMODB_WRITE_CAPACITY_UTILIZA…
Browse files Browse the repository at this point in the history
…TION` (#18085)

Enum value `DYANMODB_WRITE_CAPACITY_UTILIZATION` in `PredefinedMetric` has a typo in `DYANMODB`.
This PR deprecates this value and adds the new value `DYNAMODB_WRITE_CAPACITY_UTILIZATION`.

I think we don't need to add a test case to this PR. Please add the label `pr-linter/exempt-test` if you agree.

Fixes #17209.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jumic authored Jan 14, 2022
1 parent a5a9cbd commit 626e6aa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,20 @@ export class TargetTrackingScalingPolicy extends CoreConstruct {

super(scope, id);

// replace dummy value in DYNAMODB_WRITE_CAPACITY_UTILIZATION due to a jsii bug (https://github.com/aws/jsii/issues/2782)
const predefinedMetric = props.predefinedMetric === PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION ?
PredefinedMetric.DYANMODB_WRITE_CAPACITY_UTILIZATION :
props.predefinedMetric;

const resource = new CfnScalingPolicy(this, 'Resource', {
policyName: props.policyName || cdk.Names.uniqueId(this),
policyType: 'TargetTrackingScaling',
scalingTargetId: props.scalingTarget.scalableTargetId,
targetTrackingScalingPolicyConfiguration: {
customizedMetricSpecification: renderCustomMetric(props.customMetric),
disableScaleIn: props.disableScaleIn,
predefinedMetricSpecification: props.predefinedMetric !== undefined ? {
predefinedMetricType: props.predefinedMetric,
predefinedMetricSpecification: predefinedMetric !== undefined ? {
predefinedMetricType: predefinedMetric,
resourceLabel: props.resourceLabel,
} : undefined,
scaleInCooldown: props.scaleInCooldown && props.scaleInCooldown.toSeconds(),
Expand Down Expand Up @@ -183,9 +188,20 @@ export enum PredefinedMetric {
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
DYNAMODB_READ_CAPACITY_UTILIZATION = 'DynamoDBReadCapacityUtilization',
/**
* DYNAMODB_WRITE_CAPACITY_UTILIZATION
*
* Suffix `dummy` is necessary due to jsii bug (https://github.com/aws/jsii/issues/2782).
* Duplicate values will be dropped, so this suffix is added as a workaround.
* The value will be replaced when this enum is used.
*
* @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html
*/
DYNAMODB_WRITE_CAPACITY_UTILIZATION = 'DynamoDBWriteCapacityUtilization-dummy',
/**
* 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',
/**
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 @@ -53,6 +53,26 @@ describe('target tracking', () => {

});

test('test setup target tracking on predefined metric for DYNAMODB_WRITE_CAPACITY_UTILIZATION', () => {
// GIVEN
const stack = new cdk.Stack();
const target = createScalableTarget(stack);

// WHEN
target.scaleToTrackMetric('Tracking', {
predefinedMetric: appscaling.PredefinedMetric.DYNAMODB_WRITE_CAPACITY_UTILIZATION,
targetValue: 0.9,
});

// THEN
expect(stack).toHaveResourceLike('AWS::ApplicationAutoScaling::ScalingPolicy', {
TargetTrackingScalingPolicyConfiguration: {
PredefinedMetricSpecification: { PredefinedMetricType: 'DynamoDBWriteCapacityUtilization' },
TargetValue: 0.9,
},
});
});

test('test setup target tracking on custom metric', () => {
// GIVEN
const stack = new cdk.Stack();
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

0 comments on commit 626e6aa

Please sign in to comment.