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): time range support for GraphWidget #14659

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/lib/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ export interface GraphWidgetProps extends MetricWidgetProps {
* @default TimeSeries
*/
readonly view?: GraphWidgetView;

/**
* Whether to show the value from the entire time range. Only applicable for Bar and Pie charts.
*
* If false, values will be from the most recent period of your chosen time range;
* if true, shows the value from the entire time range.
*
* @default false
*/
readonly setPeriodToTimeRange?: boolean;
njlynch marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -276,6 +286,7 @@ export class GraphWidget extends ConcreteWidget {
},
legend: this.props.legendPosition !== undefined ? { position: this.props.legendPosition } : undefined,
liveData: this.props.liveData,
setPeriodToTimeRange: this.props.setPeriodToTimeRange,
},
}];
}
Expand Down Expand Up @@ -447,4 +458,4 @@ function mapAnnotation(yAxis: string): ((x: HorizontalAnnotation) => any) {
return (a: HorizontalAnnotation) => {
return { ...a, yAxis };
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,25 @@
"QueueName"
]
},
"\",{\"label\":\"NotVisible Messages\",\"period\":30,\"yAxis\":\"right\"}]],\"annotations\":{\"horizontal\":[{\"label\":\"Total Messages >= 100 for 3 datapoints within 3 minutes\",\"value\":100,\"yAxis\":\"left\"}]},\"yAxis\":{}}},{\"type\":\"metric\",\"width\":6,\"height\":3,\"x\":0,\"y\":12,\"properties\":{\"view\":\"singleValue\",\"title\":\"Current total messages in queue\",\"region\":\"",
"\",{\"label\":\"NotVisible Messages\",\"period\":30,\"yAxis\":\"right\"}]],\"annotations\":{\"horizontal\":[{\"label\":\"Total Messages >= 100 for 3 datapoints within 3 minutes\",\"value\":100,\"yAxis\":\"left\"}]},\"yAxis\":{}}},{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":12,\"properties\":{\"view\":\"pie\",\"title\":\"Percentage of messages in each queue as pie chart\",\"region\":\"",
{
"Ref": "AWS::Region"
},
"\",\"metrics\":[[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
{
"Fn::GetAtt": [
"queue",
"QueueName"
]
},
"\",{\"label\":\"Visible Messages\",\"period\":10}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesNotVisible\",\"QueueName\",\"",
{
"Fn::GetAtt": [
"queue",
"QueueName"
]
},
"\",{\"label\":\"NotVisible Messages\",\"period\":30}]],\"yAxis\":{},\"setPeriodToTimeRange\":true}},{\"type\":\"metric\",\"width\":6,\"height\":3,\"x\":0,\"y\":18,\"properties\":{\"view\":\"singleValue\",\"title\":\"Current total messages in queue\",\"region\":\"",
{
"Ref": "AWS::Region"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ dashboard.addWidgets(new cloudwatch.GraphWidget({
leftAnnotations: [alarm.toAnnotation()],
}));

dashboard.addWidgets(new cloudwatch.GraphWidget({
title: 'Percentage of messages in each queue as pie chart',
left: [metricA, metricB],
view: cloudwatch.GraphWidgetView.PIE,
setPeriodToTimeRange: true,
}));

dashboard.addWidgets(new cloudwatch.SingleValueWidget({
title: 'Current total messages in queue',
metrics: [sumExpression],
Expand Down
30 changes: 29 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,32 @@ export = {

test.done();
},
};

'add setPeriodToTimeRange to GraphWidget'(test: Test) {
// GIVEN
const stack = new Stack();
const widget = new GraphWidget({
left: [new Metric({ namespace: 'CDK', metricName: 'Test' })],
view: GraphWidgetView.PIE,
setPeriodToTimeRange: true,
});

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

test.done();
},
};