Skip to content

Commit

Permalink
fix(cloudwatch): MathExpression period of <5 minutes is not respected (
Browse files Browse the repository at this point in the history
…#13078)

fixes #9156

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
otaviomacedo authored Feb 25, 2021
1 parent 624a93d commit d9ee914
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudwatch/lib/private/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function metricGraphJson(metric: IMetric, yAxis?: string, id?: string) {

withExpression(expr) {
options.expression = expr.expression;
if (expr.period && expr.period !== 300) { options.period = expr.period; }
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
{
"Ref": "AWS::Region"
},
"\",\"metrics\":[[{\"label\":\"Total Messages\",\"expression\":\"m1+m2\"}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
"\",\"metrics\":[[{\"label\":\"Total Messages\",\"expression\":\"m1+m2\",\"period\":60}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
{
"Fn::GetAtt": [
"queue",
Expand Down Expand Up @@ -120,7 +120,7 @@
{
"Ref": "AWS::Region"
},
"\",\"metrics\":[[{\"label\":\"Total Messages\",\"expression\":\"m1+m2\"}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
"\",\"metrics\":[[{\"label\":\"Total Messages\",\"expression\":\"m1+m2\",\"period\":60}],[\"AWS/SQS\",\"ApproximateNumberOfMessagesVisible\",\"QueueName\",\"",
{
"Fn::GetAtt": [
"queue",
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/test/test.metric-math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ export = {
test.done();
},

'top level period in a MathExpression is respected in its metrics'(test: Test) {
const graph = new GraphWidget({
left: [
a,
new MathExpression({
expression: 'a + b',
usingMetrics: { a, b },
period: Duration.minutes(1),
}),
],
});

// THEN
graphMetricsAre(test, graph, [
['Test', 'ACount'],
[{ label: 'a + b', expression: 'a + b', period: 60 }],
['Test', 'ACount', { visible: false, id: 'a', period: 60 }],
['Test', 'BCount', { visible: false, id: 'b', period: 60 }],
]);
test.done();
},

'MathExpression controls period of metrics transitively used in it'(test: Test) {
// Same as the previous test, but recursively

Expand Down

0 comments on commit d9ee914

Please sign in to comment.