From 37d903ab5f087f89645398d4682f348d16aefe53 Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Sat, 27 Jan 2024 16:48:30 +0900 Subject: [PATCH 1/7] feat: retrieve default metric function --- .../aws-cloudfront/lib/distribution.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts b/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts index ce4d64d02ef24..ca045271539bb 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts @@ -392,6 +392,60 @@ export class Distribution extends Resource implements IDistribution { }); } + /** + * Metric for the total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests. + * + * @default - sum over 5 minutes + */ + public metricRequests(props?: cloudwatch.MetricOptions): cloudwatch.Metric { + return this.metric('Requests', props); + } + + /** + * Metric for the total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests. + * + * @default - sum over 5 minutes + */ + public metricBytesUploaded(props?: cloudwatch.MetricOptions): cloudwatch.Metric { + return this.metric('BytesUploaded', props); + } + + /** + * Metric for the total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests. + * + * @default - sum over 5 minutes + */ + public metricBytesDownloaded(props?: cloudwatch.MetricOptions): cloudwatch.Metric { + return this.metric('BytesDownloaded', props); + } + + /** + * Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx or 5xx. + * + * @default - average over 5 minutes + */ + public metricTotalErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.Metric { + return this.metric('TotalErrorRate', props); + } + + /** + * Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx. + * + * @default - average over 5 minutes + */ + public metricTotal4xxErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.Metric { + return this.metric('4xxErrorRate', props); + } + + /** + * Metric for the percentage of all viewer requests for which the response's HTTP status code is 5xx. + * + * @default - average over 5 minutes + */ + public metricTotal5xxErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.Metric { + return this.metric('5xxErrorRate', props); + } + /** * Metric for the total time spent from when CloudFront receives a request to when it starts providing a response to the network (not the viewer), * for requests that are served from the origin, not the CloudFront cache. From 93ab03dda9f3ac47e81a62e03753b156f250c5f6 Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Sat, 27 Jan 2024 17:20:16 +0900 Subject: [PATCH 2/7] test: integ test --- ...efaultTestDeployAssertB8AA280E.assets.json | 19 + ...aultTestDeployAssertB8AA280E.template.json | 36 ++ .../MyTestStack.assets.json | 19 + .../MyTestStack.template.json | 183 +++++++++ .../cdk.out | 1 + .../integ.json | 12 + .../manifest.json | 149 +++++++ .../tree.json | 381 ++++++++++++++++++ .../integ.distribution-default-metrics.ts | 41 ++ packages/aws-cdk-lib/aws-cloudfront/README.md | 31 +- .../aws-cloudfront/lib/distribution.ts | 4 +- .../aws-cloudfront/test/distribution.test.ts | 15 +- 12 files changed, 885 insertions(+), 6 deletions(-) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestDefaultTestDeployAssertB8AA280E.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestDefaultTestDeployAssertB8AA280E.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestDefaultTestDeployAssertB8AA280E.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestDefaultTestDeployAssertB8AA280E.assets.json new file mode 100644 index 0000000000000..5a407d062b58e --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestDefaultTestDeployAssertB8AA280E.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "MyTestDefaultTestDeployAssertB8AA280E.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestDefaultTestDeployAssertB8AA280E.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestDefaultTestDeployAssertB8AA280E.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestDefaultTestDeployAssertB8AA280E.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.assets.json new file mode 100644 index 0000000000000..856edc532554b --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.assets.json @@ -0,0 +1,19 @@ +{ + "version": "36.0.0", + "files": { + "8b8b5a3f0aa2bea112d22b24ee7522401f44e2138805de741c91cd6b0a0d1d71": { + "source": { + "path": "MyTestStack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "8b8b5a3f0aa2bea112d22b24ee7522401f44e2138805de741c91cd6b0a0d1d71.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.template.json new file mode 100644 index 0000000000000..aa18bcc7e97db --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.template.json @@ -0,0 +1,183 @@ +{ + "Resources": { + "DistB3B78991": { + "Type": "AWS::CloudFront::Distribution", + "Properties": { + "DistributionConfig": { + "DefaultCacheBehavior": { + "CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6", + "Compress": true, + "TargetOriginId": "MyTestStackDistOrigin1CBA48A7B", + "ViewerProtocolPolicy": "allow-all" + }, + "Enabled": true, + "HttpVersion": "http2", + "IPV6Enabled": true, + "Origins": [ + { + "CustomOriginConfig": { + "OriginProtocolPolicy": "https-only" + }, + "DomainName": "www.example.com", + "Id": "MyTestStackDistOrigin1CBA48A7B" + } + ] + } + } + }, + "Alarm1F9009D71": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "Dimensions": [ + { + "Name": "DistributionId", + "Value": { + "Ref": "DistB3B78991" + } + } + ], + "EvaluationPeriods": 1, + "MetricName": "Requests", + "Namespace": "AWS/CloudFront", + "Period": 300, + "Statistic": "Average", + "Threshold": 1 + } + }, + "Alarm2A7122E13": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "Dimensions": [ + { + "Name": "DistributionId", + "Value": { + "Ref": "DistB3B78991" + } + } + ], + "EvaluationPeriods": 1, + "MetricName": "BytesUploaded", + "Namespace": "AWS/CloudFront", + "Period": 300, + "Statistic": "Average", + "Threshold": 1 + } + }, + "Alarm32341D8D9": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "Dimensions": [ + { + "Name": "DistributionId", + "Value": { + "Ref": "DistB3B78991" + } + } + ], + "EvaluationPeriods": 1, + "MetricName": "BytesDownloaded", + "Namespace": "AWS/CloudFront", + "Period": 300, + "Statistic": "Average", + "Threshold": 1 + } + }, + "Alarm4671832C8": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "Dimensions": [ + { + "Name": "DistributionId", + "Value": { + "Ref": "DistB3B78991" + } + } + ], + "EvaluationPeriods": 1, + "MetricName": "4xxErrorRate", + "Namespace": "AWS/CloudFront", + "Period": 300, + "Statistic": "Average", + "Threshold": 1 + } + }, + "Alarm548383B2F": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "Dimensions": [ + { + "Name": "DistributionId", + "Value": { + "Ref": "DistB3B78991" + } + } + ], + "EvaluationPeriods": 1, + "MetricName": "5xxErrorRate", + "Namespace": "AWS/CloudFront", + "Period": 300, + "Statistic": "Average", + "Threshold": 1 + } + }, + "Alarm65738D89F": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "Dimensions": [ + { + "Name": "DistributionId", + "Value": { + "Ref": "DistB3B78991" + } + } + ], + "EvaluationPeriods": 1, + "MetricName": "TotalErrorRate", + "Namespace": "AWS/CloudFront", + "Period": 300, + "Statistic": "Average", + "Threshold": 1 + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/cdk.out new file mode 100644 index 0000000000000..1f0068d32659a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"36.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/integ.json new file mode 100644 index 0000000000000..50b188c9d1840 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "MyTest/DefaultTest": { + "stacks": [ + "MyTestStack" + ], + "assertionStack": "MyTest/DefaultTest/DeployAssert", + "assertionStackName": "MyTestDefaultTestDeployAssertB8AA280E" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/manifest.json new file mode 100644 index 0000000000000..7f010d4da3dce --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/manifest.json @@ -0,0 +1,149 @@ +{ + "version": "36.0.0", + "artifacts": { + "MyTestStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "MyTestStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "MyTestStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "MyTestStack.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/8b8b5a3f0aa2bea112d22b24ee7522401f44e2138805de741c91cd6b0a0d1d71.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "MyTestStack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "MyTestStack.assets" + ], + "metadata": { + "/MyTestStack/Dist/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "DistB3B78991" + } + ], + "/MyTestStack/Alarm1/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm1F9009D71" + } + ], + "/MyTestStack/Alarm2/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm2A7122E13" + } + ], + "/MyTestStack/Alarm3/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm32341D8D9" + } + ], + "/MyTestStack/Alarm4/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm4671832C8" + } + ], + "/MyTestStack/Alarm5/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm548383B2F" + } + ], + "/MyTestStack/Alarm6/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Alarm65738D89F" + } + ], + "/MyTestStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/MyTestStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "MyTestStack" + }, + "MyTestDefaultTestDeployAssertB8AA280E.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "MyTestDefaultTestDeployAssertB8AA280E.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "MyTestDefaultTestDeployAssertB8AA280E": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "MyTestDefaultTestDeployAssertB8AA280E.template.json", + "terminationProtection": false, + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "MyTestDefaultTestDeployAssertB8AA280E.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "MyTestDefaultTestDeployAssertB8AA280E.assets" + ], + "metadata": { + "/MyTest/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/MyTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "MyTest/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/tree.json new file mode 100644 index 0000000000000..397ec7a5b45f0 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/tree.json @@ -0,0 +1,381 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "MyTestStack": { + "id": "MyTestStack", + "path": "MyTestStack", + "children": { + "Dist": { + "id": "Dist", + "path": "MyTestStack/Dist", + "children": { + "Origin1": { + "id": "Origin1", + "path": "MyTestStack/Dist/Origin1", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "Resource": { + "id": "Resource", + "path": "MyTestStack/Dist/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudFront::Distribution", + "aws:cdk:cloudformation:props": { + "distributionConfig": { + "enabled": true, + "origins": [ + { + "domainName": "www.example.com", + "id": "MyTestStackDistOrigin1CBA48A7B", + "customOriginConfig": { + "originProtocolPolicy": "https-only" + } + } + ], + "defaultCacheBehavior": { + "pathPattern": "*", + "targetOriginId": "MyTestStackDistOrigin1CBA48A7B", + "cachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6", + "compress": true, + "viewerProtocolPolicy": "allow-all" + }, + "httpVersion": "http2", + "ipv6Enabled": true + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudfront.CfnDistribution", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudfront.Distribution", + "version": "0.0.0" + } + }, + "Alarm1": { + "id": "Alarm1", + "path": "MyTestStack/Alarm1", + "children": { + "Resource": { + "id": "Resource", + "path": "MyTestStack/Alarm1/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "comparisonOperator": "GreaterThanThreshold", + "dimensions": [ + { + "name": "DistributionId", + "value": { + "Ref": "DistB3B78991" + } + } + ], + "evaluationPeriods": 1, + "metricName": "Requests", + "namespace": "AWS/CloudFront", + "period": 300, + "statistic": "Average", + "threshold": 1 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "Alarm2": { + "id": "Alarm2", + "path": "MyTestStack/Alarm2", + "children": { + "Resource": { + "id": "Resource", + "path": "MyTestStack/Alarm2/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "comparisonOperator": "GreaterThanThreshold", + "dimensions": [ + { + "name": "DistributionId", + "value": { + "Ref": "DistB3B78991" + } + } + ], + "evaluationPeriods": 1, + "metricName": "BytesUploaded", + "namespace": "AWS/CloudFront", + "period": 300, + "statistic": "Average", + "threshold": 1 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "Alarm3": { + "id": "Alarm3", + "path": "MyTestStack/Alarm3", + "children": { + "Resource": { + "id": "Resource", + "path": "MyTestStack/Alarm3/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "comparisonOperator": "GreaterThanThreshold", + "dimensions": [ + { + "name": "DistributionId", + "value": { + "Ref": "DistB3B78991" + } + } + ], + "evaluationPeriods": 1, + "metricName": "BytesDownloaded", + "namespace": "AWS/CloudFront", + "period": 300, + "statistic": "Average", + "threshold": 1 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "Alarm4": { + "id": "Alarm4", + "path": "MyTestStack/Alarm4", + "children": { + "Resource": { + "id": "Resource", + "path": "MyTestStack/Alarm4/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "comparisonOperator": "GreaterThanThreshold", + "dimensions": [ + { + "name": "DistributionId", + "value": { + "Ref": "DistB3B78991" + } + } + ], + "evaluationPeriods": 1, + "metricName": "4xxErrorRate", + "namespace": "AWS/CloudFront", + "period": 300, + "statistic": "Average", + "threshold": 1 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "Alarm5": { + "id": "Alarm5", + "path": "MyTestStack/Alarm5", + "children": { + "Resource": { + "id": "Resource", + "path": "MyTestStack/Alarm5/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "comparisonOperator": "GreaterThanThreshold", + "dimensions": [ + { + "name": "DistributionId", + "value": { + "Ref": "DistB3B78991" + } + } + ], + "evaluationPeriods": 1, + "metricName": "5xxErrorRate", + "namespace": "AWS/CloudFront", + "period": 300, + "statistic": "Average", + "threshold": 1 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "Alarm6": { + "id": "Alarm6", + "path": "MyTestStack/Alarm6", + "children": { + "Resource": { + "id": "Resource", + "path": "MyTestStack/Alarm6/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Alarm", + "aws:cdk:cloudformation:props": { + "comparisonOperator": "GreaterThanThreshold", + "dimensions": [ + { + "name": "DistributionId", + "value": { + "Ref": "DistB3B78991" + } + } + ], + "evaluationPeriods": 1, + "metricName": "TotalErrorRate", + "namespace": "AWS/CloudFront", + "period": 300, + "statistic": "Average", + "threshold": 1 + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnAlarm", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Alarm", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "MyTestStack/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "MyTestStack/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "MyTest": { + "id": "MyTest", + "path": "MyTest", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "MyTest/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "MyTest/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "MyTest/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "MyTest/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "MyTest/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests-alpha.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.3.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.ts new file mode 100644 index 0000000000000..b77c6a410c5f6 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.ts @@ -0,0 +1,41 @@ +import * as cdk from 'aws-cdk-lib'; +import { Construct } from 'constructs'; +import { TestOrigin } from './test-origin'; +import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'; +import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; + +class DistributionMetricsTestStack extends cdk.Stack { + constructor(scope: Construct, id: string, props?: cdk.StackProps) { + super(scope, id, props); + + // CloudFront distribution setup + const distribution = new cloudfront.Distribution(this, 'Dist', { + defaultBehavior: { origin: new TestOrigin('www.example.com') }, + }); + + // Utility function to create alarms + const createAlarm = (alarmName: string, metric: cloudwatch.Metric) => { + return new cloudwatch.Alarm(this, alarmName, { + evaluationPeriods: 1, + threshold: 1, + comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD, + metric: metric, + }); + }; + + createAlarm('Alarm1', distribution.metricRequests()); + createAlarm('Alarm2', distribution.metricBytesUploaded()); + createAlarm('Alarm3', distribution.metricBytesDownloaded()); + createAlarm('Alarm4', distribution.metric4xxErrorRate()); + createAlarm('Alarm5', distribution.metric5xxErrorRate()); + createAlarm('Alarm6', distribution.metricTotalErrorRate()); + } +} + +const app = new cdk.App(); +const stack = new DistributionMetricsTestStack(app, 'MyTestStack'); + +new IntegTest(app, 'MyTest', { + testCases: [stack], +}); diff --git a/packages/aws-cdk-lib/aws-cloudfront/README.md b/packages/aws-cdk-lib/aws-cloudfront/README.md index 79a055ba89a75..7eb960d4dcee4 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/README.md +++ b/packages/aws-cdk-lib/aws-cloudfront/README.md @@ -597,7 +597,36 @@ new cloudfront.Distribution(this, 'myDist', { }); ``` -### Additional CloudFront distribution metrics +### CloudFront Distribution Metrics + +You can view operational metrics about your CloudFront distributions. + +#### Default CloudFront Distribution Metrics + +The [following metrics are available by default](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/viewing-cloudfront-metrics.html#monitoring-console.distributions) for all CloudFront distributions: + +- Total requests: The total number of viewer requests received by CloudFront for all HTTP methods and for both HTTP and HTTPS requests. +- Total bytes uploaded: The total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests. +- Total bytes downloaded: The total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests. +- Total error rate: The percentage of all viewer requests for which the response's HTTP status code was 4xx or 5xx. +- 4xx error rate: The percentage of all viewer requests for which the response's HTTP status code was 4xx. +- 5xx error rate: The percentage of all viewer requests for which the response's HTTP status code was 5xx. + +```ts +const dist = new cloudfront.Distribution(this, 'myDist', { + defaultBehavior: { origin: new origins.HttpOrigin('www.example.com') }, +}); + +// Retrieving default distribution metrics +const requestsMetric = dist.metricRequests(); +const bytesUploadedMetric = dist.metricBytesUploaded(); +const bytesDownloadedMetric = dist.metricBytesDownloaded(); +const totalErrorRateMetric = dist.metricTotalErrorRate(); +const http4xxErrorRateMetric = dist.metric4xxErrorRate(); +const http5xxErrorRateMetric = dist.metric5xxErrorRate(); +``` + +#### Additional CloudFront Distribution Metrics You can enable [additional CloudFront distribution metrics](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/viewing-cloudfront-metrics.html#monitoring-console.distributions-additional), which include the following metrics: diff --git a/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts b/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts index ca045271539bb..a5f8bf944ce8e 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts @@ -433,7 +433,7 @@ export class Distribution extends Resource implements IDistribution { * * @default - average over 5 minutes */ - public metricTotal4xxErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.Metric { + public metric4xxErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.Metric { return this.metric('4xxErrorRate', props); } @@ -442,7 +442,7 @@ export class Distribution extends Resource implements IDistribution { * * @default - average over 5 minutes */ - public metricTotal5xxErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.Metric { + public metric5xxErrorRate(props?: cloudwatch.MetricOptions): cloudwatch.Metric { return this.metric('5xxErrorRate', props); } diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts index 8efb67d82ccc8..5ce42778959a6 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts @@ -1283,7 +1283,7 @@ test('with publish additional metrics', () => { }); describe('Distribution metrics tests', () => { - const metrics = [ + const additionalMetrics = [ { name: 'OriginLatency', method: 'metricOriginLatency', additionalMetricsRequired: true, errorMetricName: 'Origin latency' }, { name: 'CacheHitRate', method: 'metricCacheHitRate', additionalMetricsRequired: true, errorMetricName: 'Cache hit rate' }, ...['401', '403', '404', '502', '503', '504'].map(errorCode => ({ @@ -1294,7 +1294,16 @@ describe('Distribution metrics tests', () => { })), ]; - test.each(metrics)('get %s metric', (metric) => { + const defaultMetrics = [ + { name: 'Requests', method: 'metricRequests', additionalMetricsRequired: false, errorMetricName: '' }, + { name: 'BytesDownloaded', method: 'metricBytesDownloaded', additionalMetricsRequired: false, errorMetricName: '' }, + { name: 'BytesUploaded', method: 'metricBytesUploaded', additionalMetricsRequired: false, errorMetricName: '' }, + { name: 'TotalErrorRate', method: 'metricTotalErrorRate', additionalMetricsRequired: false, errorMetricName: '' }, + { name: '4xxErrorRate', method: 'metric4xxErrorRate', additionalMetricsRequired: false, errorMetricName: '' }, + { name: '5xxErrorRate', method: 'metric5xxErrorRate', additionalMetricsRequired: false, errorMetricName: '' }, + ]; + + test.each(additionalMetrics.concat(defaultMetrics))('get %s metric', (metric) => { const origin = defaultOrigin(); const dist = new Distribution(stack, 'MyDist', { defaultBehavior: { origin }, @@ -1312,7 +1321,7 @@ describe('Distribution metrics tests', () => { })); }); - test.each(metrics)('throw error when trying to get %s metric without publishing additional metrics', (metric) => { + test.each(additionalMetrics)('throw error when trying to get %s metric without publishing additional metrics', (metric) => { const origin = defaultOrigin(); const dist = new Distribution(stack, 'MyDist', { defaultBehavior: { origin }, From 7d36090aac0fabf2e1478a7563b0d114180c1035 Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Tue, 30 Jan 2024 23:06:56 +0900 Subject: [PATCH 3/7] chore: update comments --- packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts | 6 +++--- .../aws-cdk-lib/aws-cloudfront/test/distribution.test.ts | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts b/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts index a5f8bf944ce8e..4f4d7e951e5fa 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts @@ -395,7 +395,7 @@ export class Distribution extends Resource implements IDistribution { /** * Metric for the total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests. * - * @default - sum over 5 minutes + * @default - average over 5 minutes */ public metricRequests(props?: cloudwatch.MetricOptions): cloudwatch.Metric { return this.metric('Requests', props); @@ -404,7 +404,7 @@ export class Distribution extends Resource implements IDistribution { /** * Metric for the total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests. * - * @default - sum over 5 minutes + * @default - average over 5 minutes */ public metricBytesUploaded(props?: cloudwatch.MetricOptions): cloudwatch.Metric { return this.metric('BytesUploaded', props); @@ -413,7 +413,7 @@ export class Distribution extends Resource implements IDistribution { /** * Metric for the total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests. * - * @default - sum over 5 minutes + * @default - average over 5 minutes */ public metricBytesDownloaded(props?: cloudwatch.MetricOptions): cloudwatch.Metric { return this.metric('BytesDownloaded', props); diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts index 5ce42778959a6..b38a345a6be2e 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts @@ -1312,6 +1312,8 @@ describe('Distribution metrics tests', () => { const metricObj = dist[metric.method](); + console.log(metricObj.toMetricConfig()); + expect(metricObj).toEqual(new cloudwatch.Metric({ namespace: 'AWS/CloudFront', metricName: metric.name, From 430e4fd69af4fdfeb624be087fd5a0c2fd86a8cc Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Wed, 31 Jan 2024 02:00:11 +0900 Subject: [PATCH 4/7] fix --- packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts index b38a345a6be2e..5ce42778959a6 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts @@ -1312,8 +1312,6 @@ describe('Distribution metrics tests', () => { const metricObj = dist[metric.method](); - console.log(metricObj.toMetricConfig()); - expect(metricObj).toEqual(new cloudwatch.Metric({ namespace: 'AWS/CloudFront', metricName: metric.name, From 71d26c735bd45e8db348294c5cf0d3ca6a854226 Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Wed, 31 Jan 2024 15:29:09 +0900 Subject: [PATCH 5/7] feat: update default metrics --- .../aws-cloudfront/lib/distribution.ts | 12 ++++++------ .../aws-cloudfront/test/distribution.test.ts | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts b/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts index 4f4d7e951e5fa..f0747997c956f 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/lib/distribution.ts @@ -395,28 +395,28 @@ export class Distribution extends Resource implements IDistribution { /** * Metric for the total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests. * - * @default - average over 5 minutes + * @default - sum over 5 minutes */ public metricRequests(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('Requests', props); + return this.metric('Requests', { statistic: 'sum', ...props }); } /** * Metric for the total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests. * - * @default - average over 5 minutes + * @default - sum over 5 minutes */ public metricBytesUploaded(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('BytesUploaded', props); + return this.metric('BytesUploaded', { statistic: 'sum', ...props }); } /** * Metric for the total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests. * - * @default - average over 5 minutes + * @default - sum over 5 minutes */ public metricBytesDownloaded(props?: cloudwatch.MetricOptions): cloudwatch.Metric { - return this.metric('BytesDownloaded', props); + return this.metric('BytesDownloaded', { statistic: 'sum', ...props }); } /** diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts index 5ce42778959a6..abd135a418632 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts @@ -1284,23 +1284,24 @@ test('with publish additional metrics', () => { describe('Distribution metrics tests', () => { const additionalMetrics = [ - { name: 'OriginLatency', method: 'metricOriginLatency', additionalMetricsRequired: true, errorMetricName: 'Origin latency' }, - { name: 'CacheHitRate', method: 'metricCacheHitRate', additionalMetricsRequired: true, errorMetricName: 'Cache hit rate' }, + { name: 'OriginLatency', method: 'metricOriginLatency', statistic: 'Average', additionalMetricsRequired: true, errorMetricName: 'Origin latency' }, + { name: 'CacheHitRate', method: 'metricCacheHitRate', statistic: 'Average', additionalMetricsRequired: true, errorMetricName: 'Cache hit rate' }, ...['401', '403', '404', '502', '503', '504'].map(errorCode => ({ name: `${errorCode}ErrorRate`, method: `metric${errorCode}ErrorRate`, + statistic: 'Average', additionalMetricsRequired: true, errorMetricName: `${errorCode} error rate`, })), ]; const defaultMetrics = [ - { name: 'Requests', method: 'metricRequests', additionalMetricsRequired: false, errorMetricName: '' }, - { name: 'BytesDownloaded', method: 'metricBytesDownloaded', additionalMetricsRequired: false, errorMetricName: '' }, - { name: 'BytesUploaded', method: 'metricBytesUploaded', additionalMetricsRequired: false, errorMetricName: '' }, - { name: 'TotalErrorRate', method: 'metricTotalErrorRate', additionalMetricsRequired: false, errorMetricName: '' }, - { name: '4xxErrorRate', method: 'metric4xxErrorRate', additionalMetricsRequired: false, errorMetricName: '' }, - { name: '5xxErrorRate', method: 'metric5xxErrorRate', additionalMetricsRequired: false, errorMetricName: '' }, + { name: 'Requests', method: 'metricRequests', statistic: 'Sum', additionalMetricsRequired: false, errorMetricName: '' }, + { name: 'BytesDownloaded', method: 'metricBytesDownloaded', statistic: 'Sum', additionalMetricsRequired: false, errorMetricName: '' }, + { name: 'BytesUploaded', method: 'metricBytesUploaded', statistic: 'Sum', additionalMetricsRequired: false, errorMetricName: '' }, + { name: 'TotalErrorRate', method: 'metricTotalErrorRate', statistic: 'Average', additionalMetricsRequired: false, errorMetricName: '' }, + { name: '4xxErrorRate', method: 'metric4xxErrorRate', statistic: 'Average', additionalMetricsRequired: false, errorMetricName: '' }, + { name: '5xxErrorRate', method: 'metric5xxErrorRate', statistic: 'Average', additionalMetricsRequired: false, errorMetricName: '' }, ]; test.each(additionalMetrics.concat(defaultMetrics))('get %s metric', (metric) => { @@ -1316,7 +1317,7 @@ describe('Distribution metrics tests', () => { namespace: 'AWS/CloudFront', metricName: metric.name, dimensions: { DistributionId: dist.distributionId }, - statistic: 'Average', + statistic: metric.statistic, period: Duration.minutes(5), })); }); From afac8966aa9476e20bd8d0d08491c85f677e21c0 Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Wed, 31 Jan 2024 17:25:24 +0900 Subject: [PATCH 6/7] test: update integ test --- .../MyTestStack.assets.json | 4 ++-- .../MyTestStack.template.json | 6 +++--- .../manifest.json | 2 +- .../tree.json | 6 +++--- packages/@aws-cdk/cx-api/FEATURE_FLAGS.md | 4 ++-- packages/aws-cdk-lib/index.ts | 2 ++ packages/aws-cdk-lib/package.json | 2 ++ packages/aws-cdk-lib/scripts/scope-map.json | 6 ++++++ 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.assets.json index 856edc532554b..07bff9951aed2 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.assets.json @@ -1,7 +1,7 @@ { "version": "36.0.0", "files": { - "8b8b5a3f0aa2bea112d22b24ee7522401f44e2138805de741c91cd6b0a0d1d71": { + "6925d90c1b36859755bae5e304ac217d16e02eadd6c581f9d1cc501a2a40a52a": { "source": { "path": "MyTestStack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "8b8b5a3f0aa2bea112d22b24ee7522401f44e2138805de741c91cd6b0a0d1d71.json", + "objectKey": "6925d90c1b36859755bae5e304ac217d16e02eadd6c581f9d1cc501a2a40a52a.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.template.json index aa18bcc7e97db..9978af28618d9 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/MyTestStack.template.json @@ -41,7 +41,7 @@ "MetricName": "Requests", "Namespace": "AWS/CloudFront", "Period": 300, - "Statistic": "Average", + "Statistic": "Sum", "Threshold": 1 } }, @@ -61,7 +61,7 @@ "MetricName": "BytesUploaded", "Namespace": "AWS/CloudFront", "Period": 300, - "Statistic": "Average", + "Statistic": "Sum", "Threshold": 1 } }, @@ -81,7 +81,7 @@ "MetricName": "BytesDownloaded", "Namespace": "AWS/CloudFront", "Period": 300, - "Statistic": "Average", + "Statistic": "Sum", "Threshold": 1 } }, diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/manifest.json index 7f010d4da3dce..f7d5cccf0a416 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/8b8b5a3f0aa2bea112d22b24ee7522401f44e2138805de741c91cd6b0a0d1d71.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6925d90c1b36859755bae5e304ac217d16e02eadd6c581f9d1cc501a2a40a52a.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/tree.json index 397ec7a5b45f0..ce99142367438 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront/test/integ.distribution-default-metrics.js.snapshot/tree.json @@ -83,7 +83,7 @@ "metricName": "Requests", "namespace": "AWS/CloudFront", "period": 300, - "statistic": "Average", + "statistic": "Sum", "threshold": 1 } }, @@ -121,7 +121,7 @@ "metricName": "BytesUploaded", "namespace": "AWS/CloudFront", "period": 300, - "statistic": "Average", + "statistic": "Sum", "threshold": 1 } }, @@ -159,7 +159,7 @@ "metricName": "BytesDownloaded", "namespace": "AWS/CloudFront", "period": 300, - "statistic": "Average", + "statistic": "Sum", "threshold": 1 } }, diff --git a/packages/@aws-cdk/cx-api/FEATURE_FLAGS.md b/packages/@aws-cdk/cx-api/FEATURE_FLAGS.md index 6ba99522b8f73..4235a36f11d8b 100644 --- a/packages/@aws-cdk/cx-api/FEATURE_FLAGS.md +++ b/packages/@aws-cdk/cx-api/FEATURE_FLAGS.md @@ -63,7 +63,7 @@ Flags come in three types: | [@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters](#aws-cdkaws-rdsauroraclusterchangescopeofinstanceparametergroupwitheachparameters) | When enabled, a scope of InstanceParameterGroup for AuroraClusterInstance with each parameters will change. | 2.97.0 | (fix) | | [@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials](#aws-cdkaws-rdspreventrenderingdeprecatedcredentials) | When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials. | 2.98.0 | (fix) | | [@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource](#aws-cdkaws-codepipeline-actionsusenewdefaultbranchforcodecommitsource) | When enabled, the CodeCommit source action is using the default branch name 'main'. | 2.103.1 | (fix) | -| [@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction](#aws-cdkaws-cloudwatch-actionschangelambdapermissionlogicalidforlambdaaction) | When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID. | V2NEXT | (fix) | +| [@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction](#aws-cdkaws-cloudwatch-actionschangelambdapermissionlogicalidforlambdaaction) | When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID. | 2.124.0 | (fix) | @@ -1210,7 +1210,7 @@ If the flag is set to false then it can only make one alarm for the Lambda with | Since | Default | Recommended | | ----- | ----- | ----- | | (not in v1) | | | -| V2NEXT | `false` | `true` | +| 2.124.0 | `false` | `true` | diff --git a/packages/aws-cdk-lib/index.ts b/packages/aws-cdk-lib/index.ts index 1bb52ac857d9f..a8457fc0d9e8b 100644 --- a/packages/aws-cdk-lib/index.ts +++ b/packages/aws-cdk-lib/index.ts @@ -1,4 +1,5 @@ export * as alexa_ask from './alexa-ask'; +export * as amzn_sdc from './amzn-sdc'; export * as assertions from './assertions'; export * as assets from './assets'; export * as aws_accessanalyzer from './aws-accessanalyzer'; @@ -57,6 +58,7 @@ export * as aws_codepipeline_actions from './aws-codepipeline-actions'; export * as aws_codestar from './aws-codestar'; export * as aws_codestarconnections from './aws-codestarconnections'; export * as aws_codestarnotifications from './aws-codestarnotifications'; +export * as aws_codetest from './aws-codetest'; export * as aws_cognito from './aws-cognito'; export * as aws_comprehend from './aws-comprehend'; export * as aws_config from './aws-config'; diff --git a/packages/aws-cdk-lib/package.json b/packages/aws-cdk-lib/package.json index 31afb1c0e2bb7..34fc266025b40 100644 --- a/packages/aws-cdk-lib/package.json +++ b/packages/aws-cdk-lib/package.json @@ -209,6 +209,7 @@ "./.jsii": "./.jsii", "./.warnings.jsii.js": "./.warnings.jsii.js", "./alexa-ask": "./alexa-ask/index.js", + "./amzn-sdc": "./amzn-sdc/index.js", "./assertions": "./assertions/index.js", "./assertions/lib/helpers-internal": "./assertions/lib/helpers-internal/index.js", "./assets": "./assets/index.js", @@ -268,6 +269,7 @@ "./aws-codestar": "./aws-codestar/index.js", "./aws-codestarconnections": "./aws-codestarconnections/index.js", "./aws-codestarnotifications": "./aws-codestarnotifications/index.js", + "./aws-codetest": "./aws-codetest/index.js", "./aws-cognito": "./aws-cognito/index.js", "./aws-comprehend": "./aws-comprehend/index.js", "./aws-config": "./aws-config/index.js", diff --git a/packages/aws-cdk-lib/scripts/scope-map.json b/packages/aws-cdk-lib/scripts/scope-map.json index 66acb280f873e..19018f7aaba56 100644 --- a/packages/aws-cdk-lib/scripts/scope-map.json +++ b/packages/aws-cdk-lib/scripts/scope-map.json @@ -2,6 +2,9 @@ "alexa-ask": [ "Alexa::ASK" ], + "amzn-sdc": [ + "AMZN::SDC" + ], "aws-accessanalyzer": [ "AWS::AccessAnalyzer" ], @@ -146,6 +149,9 @@ "aws-codestarnotifications": [ "AWS::CodeStarNotifications" ], + "aws-codetest": [ + "AWS::CodeTest" + ], "aws-cognito": [ "AWS::Cognito" ], From 8673e158370cdf803886746d01bb8412cd26e606 Mon Sep 17 00:00:00 2001 From: Kazuho CryerShinozuka Date: Wed, 31 Jan 2024 22:37:34 +0900 Subject: [PATCH 7/7] fix --- packages/@aws-cdk/cx-api/FEATURE_FLAGS.md | 4 ++-- packages/aws-cdk-lib/index.ts | 2 -- packages/aws-cdk-lib/package.json | 2 -- packages/aws-cdk-lib/scripts/scope-map.json | 6 ------ 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/@aws-cdk/cx-api/FEATURE_FLAGS.md b/packages/@aws-cdk/cx-api/FEATURE_FLAGS.md index 4235a36f11d8b..6ba99522b8f73 100644 --- a/packages/@aws-cdk/cx-api/FEATURE_FLAGS.md +++ b/packages/@aws-cdk/cx-api/FEATURE_FLAGS.md @@ -63,7 +63,7 @@ Flags come in three types: | [@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters](#aws-cdkaws-rdsauroraclusterchangescopeofinstanceparametergroupwitheachparameters) | When enabled, a scope of InstanceParameterGroup for AuroraClusterInstance with each parameters will change. | 2.97.0 | (fix) | | [@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials](#aws-cdkaws-rdspreventrenderingdeprecatedcredentials) | When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials. | 2.98.0 | (fix) | | [@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource](#aws-cdkaws-codepipeline-actionsusenewdefaultbranchforcodecommitsource) | When enabled, the CodeCommit source action is using the default branch name 'main'. | 2.103.1 | (fix) | -| [@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction](#aws-cdkaws-cloudwatch-actionschangelambdapermissionlogicalidforlambdaaction) | When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID. | 2.124.0 | (fix) | +| [@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction](#aws-cdkaws-cloudwatch-actionschangelambdapermissionlogicalidforlambdaaction) | When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID. | V2NEXT | (fix) | @@ -1210,7 +1210,7 @@ If the flag is set to false then it can only make one alarm for the Lambda with | Since | Default | Recommended | | ----- | ----- | ----- | | (not in v1) | | | -| 2.124.0 | `false` | `true` | +| V2NEXT | `false` | `true` | diff --git a/packages/aws-cdk-lib/index.ts b/packages/aws-cdk-lib/index.ts index a8457fc0d9e8b..1bb52ac857d9f 100644 --- a/packages/aws-cdk-lib/index.ts +++ b/packages/aws-cdk-lib/index.ts @@ -1,5 +1,4 @@ export * as alexa_ask from './alexa-ask'; -export * as amzn_sdc from './amzn-sdc'; export * as assertions from './assertions'; export * as assets from './assets'; export * as aws_accessanalyzer from './aws-accessanalyzer'; @@ -58,7 +57,6 @@ export * as aws_codepipeline_actions from './aws-codepipeline-actions'; export * as aws_codestar from './aws-codestar'; export * as aws_codestarconnections from './aws-codestarconnections'; export * as aws_codestarnotifications from './aws-codestarnotifications'; -export * as aws_codetest from './aws-codetest'; export * as aws_cognito from './aws-cognito'; export * as aws_comprehend from './aws-comprehend'; export * as aws_config from './aws-config'; diff --git a/packages/aws-cdk-lib/package.json b/packages/aws-cdk-lib/package.json index 34fc266025b40..31afb1c0e2bb7 100644 --- a/packages/aws-cdk-lib/package.json +++ b/packages/aws-cdk-lib/package.json @@ -209,7 +209,6 @@ "./.jsii": "./.jsii", "./.warnings.jsii.js": "./.warnings.jsii.js", "./alexa-ask": "./alexa-ask/index.js", - "./amzn-sdc": "./amzn-sdc/index.js", "./assertions": "./assertions/index.js", "./assertions/lib/helpers-internal": "./assertions/lib/helpers-internal/index.js", "./assets": "./assets/index.js", @@ -269,7 +268,6 @@ "./aws-codestar": "./aws-codestar/index.js", "./aws-codestarconnections": "./aws-codestarconnections/index.js", "./aws-codestarnotifications": "./aws-codestarnotifications/index.js", - "./aws-codetest": "./aws-codetest/index.js", "./aws-cognito": "./aws-cognito/index.js", "./aws-comprehend": "./aws-comprehend/index.js", "./aws-config": "./aws-config/index.js", diff --git a/packages/aws-cdk-lib/scripts/scope-map.json b/packages/aws-cdk-lib/scripts/scope-map.json index 19018f7aaba56..66acb280f873e 100644 --- a/packages/aws-cdk-lib/scripts/scope-map.json +++ b/packages/aws-cdk-lib/scripts/scope-map.json @@ -2,9 +2,6 @@ "alexa-ask": [ "Alexa::ASK" ], - "amzn-sdc": [ - "AMZN::SDC" - ], "aws-accessanalyzer": [ "AWS::AccessAnalyzer" ], @@ -149,9 +146,6 @@ "aws-codestarnotifications": [ "AWS::CodeStarNotifications" ], - "aws-codetest": [ - "AWS::CodeTest" - ], "aws-cognito": [ "AWS::Cognito" ],