From a17f3640997499b0991e97f2078d126f895bed34 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Fri, 1 Sep 2023 17:17:06 +0900 Subject: [PATCH 01/12] feat(cloudwatch): add start and end properties to GraphWidgets --- .../aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 69 +++++++++++++++ .../aws-cloudwatch/test/graphs.test.ts | 86 +++++++++++++++++++ 2 files changed, 155 insertions(+) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index c7b5c7d497a34..25b29cfaaf13c 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -204,6 +204,27 @@ export interface GaugeWidgetProps extends MetricWidgetProps { * @default - The statistic for each metric is used */ readonly statistic?: string; + + /** + * The start of the time range to use for each widget on the dashboard. + * You can specify start without specifying end to specify a relative time range that ends with the current time. + * In this case, the value of start must begin with -P, and you can use M, H, D, W and M as abbreviations for + * minutes, hours, days, weeks and months. For example, -PT8H shows the last 8 hours and -P3M shows the last three months. + * You can also use start along with an end field, to specify an absolute time range. + * When specifying an absolute time range, use the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. + * + * @default When the dashboard loads, the start time will be the default time range. + */ + readonly start?: string; + + /** + * The end of the time range to use for each widget on the dashboard when the dashboard loads. + * If you specify a value for end, you must also specify a value for start. + * Specify an absolute time in the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. + * + * @default When the dashboard loads, the end date will be the current time. + */ + readonly end?: string; } /** @@ -263,6 +284,8 @@ export class GaugeWidget extends ConcreteWidget { setPeriodToTimeRange: this.props.setPeriodToTimeRange, period: this.props.period?.toSeconds(), stat: this.props.statistic, + start: this.props.start, + end: this.props.end, }, }]; } @@ -368,6 +391,27 @@ export interface GraphWidgetProps extends MetricWidgetProps { * @default - The statistic for each metric is used */ readonly statistic?: string; + + /** + * The start of the time range to use for each widget on the dashboard. + * You can specify start without specifying end to specify a relative time range that ends with the current time. + * In this case, the value of start must begin with -P, and you can use M, H, D, W and M as abbreviations for + * minutes, hours, days, weeks and months. For example, -PT8H shows the last 8 hours and -P3M shows the last three months. + * You can also use start along with an end field, to specify an absolute time range. + * When specifying an absolute time range, use the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. + * + * @default When the dashboard loads, the start time will be the default time range. + */ + readonly start?: string; + + /** + * The end of the time range to use for each widget on the dashboard when the dashboard loads. + * If you specify a value for end, you must also specify a value for start. + * Specify an absolute time in the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. + * + * @default When the dashboard loads, the end date will be the current time. + */ + readonly end?: string; } /** @@ -437,6 +481,8 @@ export class GraphWidget extends ConcreteWidget { setPeriodToTimeRange: this.props.setPeriodToTimeRange, period: this.props.period?.toSeconds(), stat: this.props.statistic, + start: this.props.start, + end: this.props.end, }, }]; } @@ -481,6 +527,27 @@ export interface SingleValueWidgetProps extends MetricWidgetProps { * @default false */ readonly sparkline?: boolean; + + /** + * The start of the time range to use for each widget on the dashboard. + * You can specify start without specifying end to specify a relative time range that ends with the current time. + * In this case, the value of start must begin with -P, and you can use M, H, D, W and M as abbreviations for + * minutes, hours, days, weeks and months. For example, -PT8H shows the last 8 hours and -P3M shows the last three months. + * You can also use start along with an end field, to specify an absolute time range. + * When specifying an absolute time range, use the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. + * + * @default When the dashboard loads, the start time will be the default time range. + */ + readonly start?: string; + + /** + * The end of the time range to use for each widget on the dashboard when the dashboard loads. + * If you specify a value for end, you must also specify a value for start. + * Specify an absolute time in the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. + * + * @default When the dashboard loads, the end date will be the current time. + */ + readonly end?: string; } /** @@ -515,6 +582,8 @@ export class SingleValueWidget extends ConcreteWidget { setPeriodToTimeRange: this.props.setPeriodToTimeRange, singleValueFullPrecision: this.props.fullPrecision, period: this.props.period?.toSeconds(), + start: this.props.start, + end: this.props.end, }, }]; } diff --git a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts index fc440f1c416b9..7907fcaebbd03 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts @@ -855,4 +855,90 @@ describe('Graphs', () => { }, }]); }); + + test('add start and end properties to GraphWidget', () => { + // GIVEN + const stack = new Stack(); + const widget = new GraphWidget({ + left: [new Metric({ namespace: 'CDK', metricName: 'Test' })], + view: GraphWidgetView.PIE, + start: '-9H', + end: '2018-12-17T06:00:00.000Z', + }); + + // THEN + expect(stack.resolve(widget.toJson())).toEqual([{ + type: 'metric', + width: 6, + height: 6, + properties: { + view: 'pie', + region: { Ref: 'AWS::Region' }, + metrics: [ + ['CDK', 'Test'], + ], + yAxis: {}, + start: '-9H', + end: '2018-12-17T06:00:00.000Z', + }, + }]); + }); + + test('add start and end properties to SingleValueWidget', () => { + // GIVEN + const stack = new Stack(); + const widget = new SingleValueWidget({ + metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], + start: '-9H', + end: '2018-12-17T06:00:00.000Z', + }); + + // THEN + expect(stack.resolve(widget.toJson())).toEqual([{ + type: 'metric', + width: 6, + height: 3, + properties: { + view: 'singleValue', + region: { Ref: 'AWS::Region' }, + metrics: [ + ['CDK', 'Test'], + ], + start: '-9H', + end: '2018-12-17T06:00:00.000Z', + }, + }]); + }); + + test('add start and end properties to GaugeWidget', () => { + // GIVEN + const stack = new Stack(); + const widget = new GaugeWidget({ + metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], + start: '-9H', + end: '2018-12-17T06:00:00.000Z', + }); + + // THEN + expect(stack.resolve(widget.toJson())).toEqual([{ + type: 'metric', + width: 6, + height: 6, + properties: { + view: 'gauge', + region: { Ref: 'AWS::Region' }, + metrics: [ + ['CDK', 'Test'], + ], + yAxis: { + left: { + min: 0, + max: 100, + }, + }, + start: '-9H', + end: '2018-12-17T06:00:00.000Z', + }, + }]); + }); }); From e2c39791678532d24537bc79463e2f4becc0348b Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Fri, 1 Sep 2023 19:06:04 +0900 Subject: [PATCH 02/12] test: add snapshot test --- ...hboardAndWidgetWithStartAndEnd.assets.json | 19 +++ ...oardAndWidgetWithStartAndEnd.template.json | 63 ++++++++ .../cdk.out | 1 + ...efaultTestDeployAssert4D8483F4.assets.json | 19 +++ ...aultTestDeployAssert4D8483F4.template.json | 36 +++++ .../integ.json | 12 ++ .../manifest.json | 111 ++++++++++++++ .../tree.json | 144 ++++++++++++++++++ ...dashboard-and-widget-with-start-and-end.ts | 42 +++++ 9 files changed, 447 insertions(+) create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/DashboardAndWidgetWithStartAndEnd.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/DashboardAndWidgetWithStartAndEnd.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdk.out create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.assets.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.template.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/integ.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/manifest.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/tree.json create mode 100644 packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.ts diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/DashboardAndWidgetWithStartAndEnd.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/DashboardAndWidgetWithStartAndEnd.assets.json new file mode 100644 index 0000000000000..048b1a92a7635 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/DashboardAndWidgetWithStartAndEnd.assets.json @@ -0,0 +1,19 @@ +{ + "version": "34.0.0", + "files": { + "874df94f43f12341a3001f4b19d4e1bba754a4fc3a33c6a592ae6c265fc99a44": { + "source": { + "path": "DashboardAndWidgetWithStartAndEnd.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "874df94f43f12341a3001f4b19d4e1bba754a4fc3a33c6a592ae6c265fc99a44.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-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/DashboardAndWidgetWithStartAndEnd.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/DashboardAndWidgetWithStartAndEnd.template.json new file mode 100644 index 0000000000000..9ff3f1cedf6cc --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/DashboardAndWidgetWithStartAndEnd.template.json @@ -0,0 +1,63 @@ +{ + "Resources": { + "Dashboard9E4231ED": { + "Type": "AWS::CloudWatch::Dashboard", + "Properties": { + "DashboardBody": { + "Fn::Join": [ + "", + [ + "{\"widgets\":[{\"type\":\"metric\",\"width\":6,\"height\":3,\"x\":0,\"y\":0,\"properties\":{\"view\":\"singleValue\",\"region\":\"", + { + "Ref": "AWS::Region" + }, + "\",\"metrics\":[[\"CDK/Test\",\"Metric\"]],\"start\":\"-P7D\",\"end\":\"2018-12-17T06:00:00.000Z\"}},{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":3,\"properties\":{\"view\":\"timeSeries\",\"region\":\"", + { + "Ref": "AWS::Region" + }, + "\",\"metrics\":[[\"CDK/Test\",\"Metric\"]],\"yAxis\":{},\"start\":\"-P7D\",\"end\":\"2018-12-17T06:00:00.000Z\"}},{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":9,\"properties\":{\"view\":\"gauge\",\"region\":\"", + { + "Ref": "AWS::Region" + }, + "\",\"metrics\":[[\"CDK/Test\",\"Metric\"]],\"yAxis\":{\"left\":{\"min\":0,\"max\":100}},\"start\":\"-P7D\",\"end\":\"2018-12-17T06:00:00.000Z\"}}]}" + ] + ] + } + } + } + }, + "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-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdk.out new file mode 100644 index 0000000000000..2313ab5436501 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"34.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.assets.json new file mode 100644 index 0000000000000..eff956f039962 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.assets.json @@ -0,0 +1,19 @@ +{ + "version": "34.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.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-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.template.json new file mode 100644 index 0000000000000..ad9d0fb73d1dd --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.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-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/integ.json new file mode 100644 index 0000000000000..0ef12514015b1 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "34.0.0", + "testCases": { + "cdk-integ-dashboard-and-widget-with-start-and-end/DefaultTest": { + "stacks": [ + "DashboardAndWidgetWithStartAndEnd" + ], + "assertionStack": "cdk-integ-dashboard-and-widget-with-start-and-end/DefaultTest/DeployAssert", + "assertionStackName": "cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/manifest.json new file mode 100644 index 0000000000000..da40c03020eed --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/manifest.json @@ -0,0 +1,111 @@ +{ + "version": "34.0.0", + "artifacts": { + "DashboardAndWidgetWithStartAndEnd.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "DashboardAndWidgetWithStartAndEnd.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "DashboardAndWidgetWithStartAndEnd": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "DashboardAndWidgetWithStartAndEnd.template.json", + "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}/874df94f43f12341a3001f4b19d4e1bba754a4fc3a33c6a592ae6c265fc99a44.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "DashboardAndWidgetWithStartAndEnd.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": [ + "DashboardAndWidgetWithStartAndEnd.assets" + ], + "metadata": { + "/DashboardAndWidgetWithStartAndEnd/Dashboard/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "Dashboard9E4231ED" + } + ], + "/DashboardAndWidgetWithStartAndEnd/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/DashboardAndWidgetWithStartAndEnd/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "DashboardAndWidgetWithStartAndEnd" + }, + "cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.template.json", + "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": [ + "cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.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": [ + "cdkintegdashboardandwidgetwithstartandendDefaultTestDeployAssert4D8483F4.assets" + ], + "metadata": { + "/cdk-integ-dashboard-and-widget-with-start-and-end/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/cdk-integ-dashboard-and-widget-with-start-and-end/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "cdk-integ-dashboard-and-widget-with-start-and-end/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-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/tree.json new file mode 100644 index 0000000000000..dec19d3db0811 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.js.snapshot/tree.json @@ -0,0 +1,144 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "DashboardAndWidgetWithStartAndEnd": { + "id": "DashboardAndWidgetWithStartAndEnd", + "path": "DashboardAndWidgetWithStartAndEnd", + "children": { + "Dashboard": { + "id": "Dashboard", + "path": "DashboardAndWidgetWithStartAndEnd/Dashboard", + "children": { + "Resource": { + "id": "Resource", + "path": "DashboardAndWidgetWithStartAndEnd/Dashboard/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Dashboard", + "aws:cdk:cloudformation:props": { + "dashboardBody": { + "Fn::Join": [ + "", + [ + "{\"widgets\":[{\"type\":\"metric\",\"width\":6,\"height\":3,\"x\":0,\"y\":0,\"properties\":{\"view\":\"singleValue\",\"region\":\"", + { + "Ref": "AWS::Region" + }, + "\",\"metrics\":[[\"CDK/Test\",\"Metric\"]],\"start\":\"-P7D\",\"end\":\"2018-12-17T06:00:00.000Z\"}},{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":3,\"properties\":{\"view\":\"timeSeries\",\"region\":\"", + { + "Ref": "AWS::Region" + }, + "\",\"metrics\":[[\"CDK/Test\",\"Metric\"]],\"yAxis\":{},\"start\":\"-P7D\",\"end\":\"2018-12-17T06:00:00.000Z\"}},{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":9,\"properties\":{\"view\":\"gauge\",\"region\":\"", + { + "Ref": "AWS::Region" + }, + "\",\"metrics\":[[\"CDK/Test\",\"Metric\"]],\"yAxis\":{\"left\":{\"min\":0,\"max\":100}},\"start\":\"-P7D\",\"end\":\"2018-12-17T06:00:00.000Z\"}}]}" + ] + ] + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.CfnDashboard", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_cloudwatch.Dashboard", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "DashboardAndWidgetWithStartAndEnd/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "DashboardAndWidgetWithStartAndEnd/CheckBootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.Stack", + "version": "0.0.0" + } + }, + "cdk-integ-dashboard-and-widget-with-start-and-end": { + "id": "cdk-integ-dashboard-and-widget-with-start-and-end", + "path": "cdk-integ-dashboard-and-widget-with-start-and-end", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "cdk-integ-dashboard-and-widget-with-start-and-end/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "cdk-integ-dashboard-and-widget-with-start-and-end/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.2.70" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "cdk-integ-dashboard-and-widget-with-start-and-end/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "cdk-integ-dashboard-and-widget-with-start-and-end/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "aws-cdk-lib.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "cdk-integ-dashboard-and-widget-with-start-and-end/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.2.70" + } + } + }, + "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-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.ts new file mode 100644 index 0000000000000..280845d4e60ab --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-and-widget-with-start-and-end.ts @@ -0,0 +1,42 @@ +import { App, Stack, StackProps } from 'aws-cdk-lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { Dashboard, SingleValueWidget, Metric, GraphWidget, GaugeWidget } from 'aws-cdk-lib/aws-cloudwatch'; + +class TestStack extends Stack { + constructor(scope: App, id: string, props?: StackProps) { + super(scope, id, props); + + const dashboard = new Dashboard(this, 'Dashboard'); + + const testMetric = new Metric({ + namespace: 'CDK/Test', + metricName: 'Metric', + }); + + const singleValueWidget = new SingleValueWidget({ + metrics: [testMetric], + start: '-P7D', + end: '2018-12-17T06:00:00.000Z', + }); + + const graphWidget = new GraphWidget({ + left: [testMetric], + start: '-P7D', + end: '2018-12-17T06:00:00.000Z', + }); + + const gaugeWidget = new GaugeWidget({ + metrics: [testMetric], + start: '-P7D', + end: '2018-12-17T06:00:00.000Z', + }); + + dashboard.addWidgets(singleValueWidget); + dashboard.addWidgets(graphWidget); + dashboard.addWidgets(gaugeWidget); + } +} +const app = new App(); +new IntegTest(app, 'cdk-integ-dashboard-and-widget-with-start-and-end', { + testCases: [new TestStack(app, 'DashboardAndWidgetWithStartAndEnd')], +}); From 71ed6c25c84bb0a92be7dd833ab9c1158b02bb7b Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Fri, 1 Sep 2023 19:06:20 +0900 Subject: [PATCH 03/12] test: change unit tests --- .../aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts index 7907fcaebbd03..ff15eaa37c510 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts @@ -862,7 +862,7 @@ describe('Graphs', () => { const widget = new GraphWidget({ left: [new Metric({ namespace: 'CDK', metricName: 'Test' })], view: GraphWidgetView.PIE, - start: '-9H', + start: '-P7D', end: '2018-12-17T06:00:00.000Z', }); @@ -878,7 +878,7 @@ describe('Graphs', () => { ['CDK', 'Test'], ], yAxis: {}, - start: '-9H', + start: '-P7D', end: '2018-12-17T06:00:00.000Z', }, }]); @@ -889,7 +889,7 @@ describe('Graphs', () => { const stack = new Stack(); const widget = new SingleValueWidget({ metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], - start: '-9H', + start: '-P7D', end: '2018-12-17T06:00:00.000Z', }); @@ -904,7 +904,7 @@ describe('Graphs', () => { metrics: [ ['CDK', 'Test'], ], - start: '-9H', + start: '-P7D', end: '2018-12-17T06:00:00.000Z', }, }]); @@ -915,7 +915,7 @@ describe('Graphs', () => { const stack = new Stack(); const widget = new GaugeWidget({ metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], - start: '-9H', + start: '-P7D', end: '2018-12-17T06:00:00.000Z', }); @@ -936,7 +936,7 @@ describe('Graphs', () => { max: 100, }, }, - start: '-9H', + start: '-P7D', end: '2018-12-17T06:00:00.000Z', }, }]); From 99d7222a112a32ff6056ff003fb523dcccd95979 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Fri, 1 Sep 2023 19:21:44 +0900 Subject: [PATCH 04/12] docs: README --- packages/aws-cdk-lib/aws-cloudwatch/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/README.md b/packages/aws-cdk-lib/aws-cloudwatch/README.md index c28f46e28b476..27d38a932f3a5 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/README.md +++ b/packages/aws-cdk-lib/aws-cloudwatch/README.md @@ -479,6 +479,20 @@ dashboard.addWidgets(new cloudwatch.GraphWidget({ })); ``` +The `start` and `end` properties can be used to specify the time range for each graph widget independently from those of the dashboard. +The parameters can be specified at `GraphWidget`, `GaugeWidget`, and `SingleValueWidget`. + +```ts +declare const dashboard: cloudwatch.Dashboard; + +dashboard.addWidgets(new cloudwatch.GraphWidget({ + // ... + + start: '-P7D', + end: '2018-12-17T06:00:00.000Z', +})); +``` + ### Gauge widget Gauge graph requires the max and min value of the left Y axis, if no value is informed the limits will be from 0 to 100. From 45faf83d37576ba54bfacfe030b73ee877e6df6f Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Fri, 1 Sep 2023 19:48:22 +0900 Subject: [PATCH 05/12] docs: jsdoc --- packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 25b29cfaaf13c..387f7cc97cc74 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -206,7 +206,7 @@ export interface GaugeWidgetProps extends MetricWidgetProps { readonly statistic?: string; /** - * The start of the time range to use for each widget on the dashboard. + * The start of the time range to use for each widget independently from those of the dashboard. * You can specify start without specifying end to specify a relative time range that ends with the current time. * In this case, the value of start must begin with -P, and you can use M, H, D, W and M as abbreviations for * minutes, hours, days, weeks and months. For example, -PT8H shows the last 8 hours and -P3M shows the last three months. @@ -218,7 +218,7 @@ export interface GaugeWidgetProps extends MetricWidgetProps { readonly start?: string; /** - * The end of the time range to use for each widget on the dashboard when the dashboard loads. + * The end of the time range to use for each widget independently from those of the dashboard. * If you specify a value for end, you must also specify a value for start. * Specify an absolute time in the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. * @@ -393,7 +393,7 @@ export interface GraphWidgetProps extends MetricWidgetProps { readonly statistic?: string; /** - * The start of the time range to use for each widget on the dashboard. + * The start of the time range to use for each widget independently from those of the dashboard. * You can specify start without specifying end to specify a relative time range that ends with the current time. * In this case, the value of start must begin with -P, and you can use M, H, D, W and M as abbreviations for * minutes, hours, days, weeks and months. For example, -PT8H shows the last 8 hours and -P3M shows the last three months. @@ -405,7 +405,7 @@ export interface GraphWidgetProps extends MetricWidgetProps { readonly start?: string; /** - * The end of the time range to use for each widget on the dashboard when the dashboard loads. + * The end of the time range to use for each widget independently from those of the dashboard. * If you specify a value for end, you must also specify a value for start. * Specify an absolute time in the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. * @@ -529,7 +529,7 @@ export interface SingleValueWidgetProps extends MetricWidgetProps { readonly sparkline?: boolean; /** - * The start of the time range to use for each widget on the dashboard. + * The start of the time range to use for each widget independently from those of the dashboard. * You can specify start without specifying end to specify a relative time range that ends with the current time. * In this case, the value of start must begin with -P, and you can use M, H, D, W and M as abbreviations for * minutes, hours, days, weeks and months. For example, -PT8H shows the last 8 hours and -P3M shows the last three months. @@ -541,7 +541,7 @@ export interface SingleValueWidgetProps extends MetricWidgetProps { readonly start?: string; /** - * The end of the time range to use for each widget on the dashboard when the dashboard loads. + * The end of the time range to use for each widget independently from those of the dashboard. * If you specify a value for end, you must also specify a value for start. * Specify an absolute time in the ISO 8601 format. For example, 2018-12-17T06:00:00.000Z. * From c5580819bfa20f7ed2fba49a1b04ac9967bd923f Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:11:49 +0900 Subject: [PATCH 06/12] add validation for end without start --- packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 387f7cc97cc74..1e3d9d664a580 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -241,6 +241,10 @@ export class GaugeWidget extends ConcreteWidget { this.props = props; this.metrics = props.metrics ?? []; this.copyMetricWarnings(...this.metrics); + + if (this.props.end && !this.props.start) { + throw new Error('You must also specify a start time if you specify an end time.'); + } } /** From c76b06afb85ec9a8214e8216d8ba53597dd5775e Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:14:56 +0900 Subject: [PATCH 07/12] add validations for other widgets --- packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 1e3d9d664a580..69807a26a6469 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -434,6 +434,10 @@ export class GraphWidget extends ConcreteWidget { this.leftMetrics = props.left ?? []; this.rightMetrics = props.right ?? []; this.copyMetricWarnings(...this.leftMetrics, ...this.rightMetrics); + + if (this.props.end && !this.props.start) { + throw new Error('You must also specify a start time if you specify an end time.'); + } } /** @@ -568,6 +572,10 @@ export class SingleValueWidget extends ConcreteWidget { if (props.setPeriodToTimeRange && props.sparkline) { throw new Error('You cannot use setPeriodToTimeRange with sparkline'); } + + if (this.props.end && !this.props.start) { + throw new Error('You must also specify a start time if you specify an end time.'); + } } public toJson(): any[] { From b61144b2b4a970edb9bd4b67425de2a288283f71 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:16:19 +0900 Subject: [PATCH 08/12] change if statements --- packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 69807a26a6469..73d0f79d247df 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -242,7 +242,7 @@ export class GaugeWidget extends ConcreteWidget { this.metrics = props.metrics ?? []; this.copyMetricWarnings(...this.metrics); - if (this.props.end && !this.props.start) { + if (props.end && !props.start) { throw new Error('You must also specify a start time if you specify an end time.'); } } @@ -435,7 +435,7 @@ export class GraphWidget extends ConcreteWidget { this.rightMetrics = props.right ?? []; this.copyMetricWarnings(...this.leftMetrics, ...this.rightMetrics); - if (this.props.end && !this.props.start) { + if (props.end && !props.start) { throw new Error('You must also specify a start time if you specify an end time.'); } } @@ -573,7 +573,7 @@ export class SingleValueWidget extends ConcreteWidget { throw new Error('You cannot use setPeriodToTimeRange with sparkline'); } - if (this.props.end && !this.props.start) { + if (props.end && !props.start) { throw new Error('You must also specify a start time if you specify an end time.'); } } From 96151c89956c5422d7bcdb5ea6594eb64e27aa4e Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:24:22 +0900 Subject: [PATCH 09/12] add tests --- .../aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 6 +-- .../aws-cloudwatch/test/graphs.test.ts | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 73d0f79d247df..61818b47e65f9 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -243,7 +243,7 @@ export class GaugeWidget extends ConcreteWidget { this.copyMetricWarnings(...this.metrics); if (props.end && !props.start) { - throw new Error('You must also specify a start time if you specify an end time.'); + throw new Error('You must specify a start if you specify an end'); } } @@ -436,7 +436,7 @@ export class GraphWidget extends ConcreteWidget { this.copyMetricWarnings(...this.leftMetrics, ...this.rightMetrics); if (props.end && !props.start) { - throw new Error('You must also specify a start time if you specify an end time.'); + throw new Error('You must specify a start if you specify an end'); } } @@ -574,7 +574,7 @@ export class SingleValueWidget extends ConcreteWidget { } if (props.end && !props.start) { - throw new Error('You must also specify a start time if you specify an end time.'); + throw new Error('You must specify a start if you specify an end'); } } diff --git a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts index ff15eaa37c510..597e99946bf33 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts @@ -941,4 +941,44 @@ describe('Graphs', () => { }, }]); }); + + test('cannot specify an end without a start in GraphWidget', () => { + // GIVEN + const stack = new Stack(); + + // THEN + expect(() => { + new GraphWidget({ + left: [new Metric({ namespace: 'CDK', metricName: 'Test' })], + view: GraphWidgetView.PIE, + end: '2018-12-17T06:00:00.000Z', + }); + }).toThrow(/You must specify a start if you specify an end/); + }); + + test('cannot specify an end without a start in SingleValueWidget', () => { + // GIVEN + const stack = new Stack(); + + // THEN + expect(() => { + new SingleValueWidget({ + metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], + end: '2018-12-17T06:00:00.000Z', + }); + }).toThrow(/You must specify a start if you specify an end/); + }); + + test('cannot specify an end without a start in GaugeWidget', () => { + // GIVEN + const stack = new Stack(); + + // THEN + expect(() => { + new GaugeWidget({ + metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], + end: '2018-12-17T06:00:00.000Z', + }); + }).toThrow(/You must specify a start if you specify an end/); + }); }); From 4cb8339ae98b2676563dd38085e0f4f3f24b9694 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:54:52 +0900 Subject: [PATCH 10/12] change if conditions --- packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 61818b47e65f9..37055254e58a2 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -242,7 +242,7 @@ export class GaugeWidget extends ConcreteWidget { this.metrics = props.metrics ?? []; this.copyMetricWarnings(...this.metrics); - if (props.end && !props.start) { + if (props.end !== undefined && props.start === undefined) { throw new Error('You must specify a start if you specify an end'); } } @@ -435,7 +435,7 @@ export class GraphWidget extends ConcreteWidget { this.rightMetrics = props.right ?? []; this.copyMetricWarnings(...this.leftMetrics, ...this.rightMetrics); - if (props.end && !props.start) { + if (props.end !== undefined && props.start === undefined) { throw new Error('You must specify a start if you specify an end'); } } @@ -573,7 +573,7 @@ export class SingleValueWidget extends ConcreteWidget { throw new Error('You cannot use setPeriodToTimeRange with sparkline'); } - if (props.end && !props.start) { + if (props.end !== undefined && props.start === undefined) { throw new Error('You must specify a start if you specify an end'); } } From 72706d058cba57a6725aa9a240750a78b0fad9c9 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Wed, 13 Sep 2023 14:59:12 +0900 Subject: [PATCH 11/12] change error messages --- packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 6 +++--- packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 37055254e58a2..8ad479f5056ad 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -243,7 +243,7 @@ export class GaugeWidget extends ConcreteWidget { this.copyMetricWarnings(...this.metrics); if (props.end !== undefined && props.start === undefined) { - throw new Error('You must specify a start if you specify an end'); + throw new Error('You must also specify a start if you specify an end'); } } @@ -436,7 +436,7 @@ export class GraphWidget extends ConcreteWidget { this.copyMetricWarnings(...this.leftMetrics, ...this.rightMetrics); if (props.end !== undefined && props.start === undefined) { - throw new Error('You must specify a start if you specify an end'); + throw new Error('You must also specify a start if you specify an end'); } } @@ -574,7 +574,7 @@ export class SingleValueWidget extends ConcreteWidget { } if (props.end !== undefined && props.start === undefined) { - throw new Error('You must specify a start if you specify an end'); + throw new Error('You must also specify a start if you specify an end'); } } diff --git a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts index 597e99946bf33..7fb2ce8bcd69c 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts @@ -953,7 +953,7 @@ describe('Graphs', () => { view: GraphWidgetView.PIE, end: '2018-12-17T06:00:00.000Z', }); - }).toThrow(/You must specify a start if you specify an end/); + }).toThrow(/You must also specify a start if you specify an end/); }); test('cannot specify an end without a start in SingleValueWidget', () => { @@ -966,7 +966,7 @@ describe('Graphs', () => { metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], end: '2018-12-17T06:00:00.000Z', }); - }).toThrow(/You must specify a start if you specify an end/); + }).toThrow(/You must also specify a start if you specify an end/); }); test('cannot specify an end without a start in GaugeWidget', () => { @@ -979,6 +979,6 @@ describe('Graphs', () => { metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], end: '2018-12-17T06:00:00.000Z', }); - }).toThrow(/You must specify a start if you specify an end/); + }).toThrow(/You must also specify a start if you specify an end/); }); }); From 21077901758d1b95a23b09465511f4d3ef8d2728 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Thu, 14 Sep 2023 00:36:02 +0900 Subject: [PATCH 12/12] changed error massages --- packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts | 6 +++--- packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 8ad479f5056ad..e5172a57b5c4a 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -243,7 +243,7 @@ export class GaugeWidget extends ConcreteWidget { this.copyMetricWarnings(...this.metrics); if (props.end !== undefined && props.start === undefined) { - throw new Error('You must also specify a start if you specify an end'); + throw new Error('If you specify a value for end, you must also specify a value for start.'); } } @@ -436,7 +436,7 @@ export class GraphWidget extends ConcreteWidget { this.copyMetricWarnings(...this.leftMetrics, ...this.rightMetrics); if (props.end !== undefined && props.start === undefined) { - throw new Error('You must also specify a start if you specify an end'); + throw new Error('If you specify a value for end, you must also specify a value for start.'); } } @@ -574,7 +574,7 @@ export class SingleValueWidget extends ConcreteWidget { } if (props.end !== undefined && props.start === undefined) { - throw new Error('You must also specify a start if you specify an end'); + throw new Error('If you specify a value for end, you must also specify a value for start.'); } } diff --git a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts index 7fb2ce8bcd69c..afe053d83612c 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts @@ -953,7 +953,7 @@ describe('Graphs', () => { view: GraphWidgetView.PIE, end: '2018-12-17T06:00:00.000Z', }); - }).toThrow(/You must also specify a start if you specify an end/); + }).toThrow(/If you specify a value for end, you must also specify a value for start./); }); test('cannot specify an end without a start in SingleValueWidget', () => { @@ -966,7 +966,7 @@ describe('Graphs', () => { metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], end: '2018-12-17T06:00:00.000Z', }); - }).toThrow(/You must also specify a start if you specify an end/); + }).toThrow(/If you specify a value for end, you must also specify a value for start./); }); test('cannot specify an end without a start in GaugeWidget', () => { @@ -979,6 +979,6 @@ describe('Graphs', () => { metrics: [new Metric({ namespace: 'CDK', metricName: 'Test' })], end: '2018-12-17T06:00:00.000Z', }); - }).toThrow(/You must also specify a start if you specify an end/); + }).toThrow(/If you specify a value for end, you must also specify a value for start./); }); });