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

fix(cloudwatch): MathExpression period of <5 minutes is not respected #13078

Merged
merged 5 commits into from
Feb 25, 2021
Merged

fix(cloudwatch): MathExpression period of <5 minutes is not respected #13078

merged 5 commits into from
Feb 25, 2021

Conversation

otaviomacedo
Copy link
Contributor

@otaviomacedo otaviomacedo commented Feb 16, 2021

fixes #9156


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Feb 16, 2021

@github-actions github-actions bot added the @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch label Feb 16, 2021
@@ -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; }
Copy link
Contributor

Choose a reason for hiding this comment

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

I omitted this originally because what would happen is the expression period would be propagated down to the queried metrics.

Have we confirmed this is really necessary? Does it actually solve the problem it says it's addressing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean... I know I suggested this fix in the linked bug report.

But I'm very much interested in WHY this change is necessary.

It might also be because of the period field in the enclosing graph, for example.

Looking for someone to do a slightly deeper dive and experimenting a bit with the combinations and telling us WHAT EXACTLY the behavior of CloudWatch is (and by extension, what the construct library needs to produce).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I can create a minimal stack with a graph widget and deploy to my AWS account to see the difference between the two cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor Author

@otaviomacedo otaviomacedo Feb 20, 2021

Choose a reason for hiding this comment

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

When you define a metric using MathExpression, CDK will generate a new invisible metric for each component of the expression. For example, let's say you want to create a widget with three metrics for a DynamoDB table: one for ConsumedReadCapacityUnits, one for ConsumedWriteCapacityUnits and one for the sum of the other two. The generated CloudFormation template will have five metrics altogether:

  1. A visible one for ConsumedReadCapacityUnits
  2. A visible one for ConsumedWriteCapacityUnits
  3. An invisible one for ConsumedReadCapacityUnits
  4. An invisible one for ConsumedWriteCapacityUnits
  5. A visible one for ConsumedReadCapacityUnits + ConsumedWriteCapacityUnits

Metric 5 is the sum of metrics 3 and 4.

As it is now, if you specify a period in a MathExpression, that period is not being respected in the aggregate metric, but it is already being propagated down to its components. Note that this only affects the components of the math expression. Their visible counterparts remain unchanged. In the example above, only metrics 3 and 4 have the period changed. Since they are invisible, there is no noticeable effect in the final widget, which shows data at a default interval for the aggregate metric. For DynamoDB tables, for example, this default is 10 minutes.

This change solves the problem by overriding the period in the aggregate metric and not changing anything else in the final CloudFormation template. I also deployed stacks with different combinations of periods and overrides and the result is as expected.

@mergify mergify bot dismissed rix0rrr’s stale review February 21, 2021 07:47

Pull request has been modified.

@nija-at nija-at changed the title fix(aws-cloudwatch): respect the period of MathExpressions #9156 fix(cloudwatch): respect the period of MathExpressions Feb 24, 2021
@rix0rrr rix0rrr changed the title fix(cloudwatch): respect the period of MathExpressions fix(cloudwatch): MathExpression period of <5 minutes is not respected Feb 25, 2021
@mergify
Copy link
Contributor

mergify bot commented Feb 25, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 0626a61
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Feb 25, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-cloudwatch] The period of a MathExpression is not respected on CloudWatch
3 participants