From 5bb1cebcc03e0e8e46fd1037ab4a64a38181944f Mon Sep 17 00:00:00 2001 From: Kunal Shah Date: Wed, 14 Aug 2024 20:07:47 +0000 Subject: [PATCH] feat(applicationautoscaling): add missing PredefinedMetricType enum values --- .../lib/target-tracking-scaling-policy.ts | 15 +++++ .../test/target-tracking.test.ts | 60 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/packages/aws-cdk-lib/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts b/packages/aws-cdk-lib/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts index 7277fc164e1ea..313c32bc1e7a1 100644 --- a/packages/aws-cdk-lib/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts +++ b/packages/aws-cdk-lib/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts @@ -304,4 +304,19 @@ export enum PredefinedMetric { * @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html */ ELASTICACHE_DATABASE_CAPACITY_USAGE_COUNTED_FOR_EVICT_PERCENTAGE = 'ElastiCacheDatabaseCapacityUsageCountedForEvictPercentage', + /** + * SAGEMAKER_INFERENCE_COMPONENT_CONCURRENT_REQUESTS_PER_COPY_HIGH_RESOLUTION + * @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html + */ + SAGEMAKER_INFERENCE_COMPONENT_CONCURRENT_REQUESTS_PER_COPY_HIGH_RESOLUTION = 'SageMakerInferenceComponentConcurrentRequestsPerCopyHighResolution', + /** + * SAGEMAKER_VARIANT_CONCURRENT_REQUESTS_PER_MODEL_HIGH_RESOLUTION + * @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html + */ + SAGEMAKER_VARIANT_CONCURRENT_REQUESTS_PER_MODEL_HIGH_RESOLUTION = 'SageMakerVariantConcurrentRequestsPerModelHighResolution', + /** + * WORKSPACES_AVERAGE_USER_SESSIONS_CAPACITY_UTILIZATION + * @see https://docs.aws.amazon.com/autoscaling/application/APIReference/API_PredefinedMetricSpecification.html + */ + WORKSPACES_AVERAGE_USER_SESSIONS_CAPACITY_UTILIZATION = 'WorkSpacesAverageUserSessionsCapacityUtilization', } diff --git a/packages/aws-cdk-lib/aws-applicationautoscaling/test/target-tracking.test.ts b/packages/aws-cdk-lib/aws-applicationautoscaling/test/target-tracking.test.ts index df3c2c098d841..d97347b65033f 100644 --- a/packages/aws-cdk-lib/aws-applicationautoscaling/test/target-tracking.test.ts +++ b/packages/aws-cdk-lib/aws-applicationautoscaling/test/target-tracking.test.ts @@ -91,6 +91,66 @@ describe('target tracking', () => { }); }); + test('test setup target tracking on predefined metric for SAGEMAKER_VARIANT_CONCURRENT_REQUESTS_PER_MODEL_HIGH_RESOLUTION', () => { + // GIVEN + const stack = new cdk.Stack(); + const target = createScalableTarget(stack); + + // WHEN + target.scaleToTrackMetric('Tracking', { + predefinedMetric: appscaling.PredefinedMetric.SAGEMAKER_VARIANT_CONCURRENT_REQUESTS_PER_MODEL_HIGH_RESOLUTION, + targetValue: 0.5, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { + TargetTrackingScalingPolicyConfiguration: { + PredefinedMetricSpecification: { PredefinedMetricType: 'SageMakerVariantConcurrentRequestsPerModelHighResolution' }, + TargetValue: 0.5, + }, + }); + }); + + test('test setup target tracking on predefined metric for SAGEMAKER_INFERENCE_COMPONENT_CONCURRENT_REQUESTS_PER_COPY_HIGH_RESOLUTION', () => { + // GIVEN + const stack = new cdk.Stack(); + const target = createScalableTarget(stack); + + // WHEN + target.scaleToTrackMetric('Tracking', { + predefinedMetric: appscaling.PredefinedMetric.SAGEMAKER_INFERENCE_COMPONENT_CONCURRENT_REQUESTS_PER_COPY_HIGH_RESOLUTION, + targetValue: 0.5, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { + TargetTrackingScalingPolicyConfiguration: { + PredefinedMetricSpecification: { PredefinedMetricType: 'SageMakerInferenceComponentConcurrentRequestsPerCopyHighResolution' }, + TargetValue: 0.5, + }, + }); + }); + + test('test setup target tracking on predefined metric for WORKSPACES_AVERAGE_USER_SESSIONS_CAPACITY_UTILIZATION', () => { + // GIVEN + const stack = new cdk.Stack(); + const target = createScalableTarget(stack); + + // WHEN + target.scaleToTrackMetric('Tracking', { + predefinedMetric: appscaling.PredefinedMetric.WORKSPACES_AVERAGE_USER_SESSIONS_CAPACITY_UTILIZATION, + targetValue: 0.5, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::ApplicationAutoScaling::ScalingPolicy', { + TargetTrackingScalingPolicyConfiguration: { + PredefinedMetricSpecification: { PredefinedMetricType: 'WorkSpacesAverageUserSessionsCapacityUtilization' }, + TargetValue: 0.5, + }, + }); + }); + test('test setup target tracking on custom metric', () => { // GIVEN const stack = new cdk.Stack();