From d8cfa246db3942338b0fe2ec3707eadb1bc35431 Mon Sep 17 00:00:00 2001 From: Amri Date: Wed, 23 Oct 2019 17:01:36 +0200 Subject: [PATCH] (feat) aws-cloudwatch: add support for time range value fixes #4647 --- packages/@aws-cdk/aws-cloudwatch/lib/graph.ts | 10 ++++++- .../aws-cloudwatch/test/test.graphs.ts | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts b/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts index c97463a218cbd..145f662feb3cd 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts @@ -201,6 +201,13 @@ export interface SingleValueWidgetProps extends MetricWidgetProps { * Metrics to display */ readonly metrics: IMetric[]; + + /** + * Whether to show the value from the entire time range. + * + * @default false + */ + readonly setPeriodToTimeRange?: boolean; } /** @@ -225,7 +232,8 @@ export class SingleValueWidget extends ConcreteWidget { view: 'singleValue', title: this.props.title, region: this.props.region || cdk.Aws.REGION, - metrics: this.props.metrics.map(m => metricJson(m, 'left')) + metrics: this.props.metrics.map(m => metricJson(m, 'left')), + setPeriodToTimeRange: this.props.setPeriodToTimeRange } }]; } diff --git a/packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts b/packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts index 2d5a2a9375343..c9d57f1a4ca35 100644 --- a/packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts +++ b/packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts @@ -288,4 +288,33 @@ export = { test.done(); }, + + 'add setPeriodToTimeRange to singleValueWidget'(test: Test) { + // GIVEN + const stack = new Stack(); + const metric = new Metric({ namespace: 'CDK', metricName: 'Test' }); + + // WHEN + const widget = new SingleValueWidget({ + metrics: [ metric ], + setPeriodToTimeRange: true + }); + + // THEN + test.deepEqual(stack.resolve(widget.toJson()), [{ + type: 'metric', + width: 6, + height: 3, + properties: { + view: 'singleValue', + region: { Ref: 'AWS::Region' }, + metrics: [ + ['CDK', 'Test', { yAxis: 'left', period: 300, stat: 'Average' }], + ], + setPeriodToTimeRange: true + } + }]); + + test.done(); + }, };