Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloudwatch): GraphWidget supports period and statistic #14679

Merged
merged 2 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/lib/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export interface GraphWidgetProps extends MetricWidgetProps {
*/
readonly liveData?: boolean;


/**
* Display this metric
*
Expand All @@ -223,6 +222,23 @@ export interface GraphWidgetProps extends MetricWidgetProps {
* @default false
*/
readonly setPeriodToTimeRange?: boolean;

/**
* The default period for all metrics in this widget.
* The period is the length of time represented by one data point on the graph.
* This default can be overridden within each metric definition.
*
* @default cdk.Duration.seconds(300)
*/
readonly period?: cdk.Duration;

/**
* The default statistic to be displayed for each metric.
* This default can be overridden within the definition of each individual metric
*
* @default - The statistic for each metric is used
Comment on lines +236 to +239
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confusing statements?!

I'm guessing this is the default stat if no stat is specified on the individual metrics. What's the default if no stat is specified on the metric and here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, not sure. It doesn't appear to be documented. In the console, if you remove all stats from the source, it appears to default to Average. However, that could be console-specific behavior.

*/
readonly statistic?: string;
}

/**
Expand Down Expand Up @@ -287,6 +303,8 @@ export class GraphWidget extends ConcreteWidget {
legend: this.props.legendPosition !== undefined ? { position: this.props.legendPosition } : undefined,
liveData: this.props.liveData,
setPeriodToTimeRange: this.props.setPeriodToTimeRange,
period: this.props.period?.toSeconds(),
stat: this.props.statistic,
},
}];
}
Expand Down
31 changes: 30 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack } from '@aws-cdk/core';
import { Duration, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { Alarm, AlarmWidget, Color, GraphWidget, GraphWidgetView, LegendPosition, LogQueryWidget, Metric, Shading, SingleValueWidget, LogQueryVisualizationType } from '../lib';

Expand Down Expand Up @@ -688,4 +688,33 @@ export = {

test.done();
},

'GraphWidget supports stat and period'(test: Test) {
// GIVEN
const stack = new Stack();
const widget = new GraphWidget({
left: [new Metric({ namespace: 'CDK', metricName: 'Test' })],
statistic: 'Average',
period: Duration.days(2),
});

// THEN
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
properties: {
view: 'timeSeries',
region: { Ref: 'AWS::Region' },
metrics: [
['CDK', 'Test'],
],
yAxis: {},
stat: 'Average',
period: 172800,
},
}]);

test.done();
},
};