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 id contract is not clear #19825

Merged
merged 7 commits into from
Apr 12, 2022

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Apr 8, 2022

It is intended that all metric identifiers referenced in a
MathExpression are included in the usingMetrics map. This
allows passing around complex metrics as a single object,
because the math expression object carries around its dependencies
with it.

This is slightly different than what people might be used
to from raw CloudWatch, where there is no hierarchy and all
metrics are supposed to be listed in the graph widget or alarm
with a unique ID, and then referenced by ID.

We can't make this contract obvious anymore by adding a hard
validation, but we can add warnings to hint people at the right
way to reference metrics in math expressions.

Fixes #13942, closes #17126.


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

It is intended that all metric identifiers referenced in a
MathExpression are included in the `usingMetrics` map. This
allows passing around complex metrics as a single object,
because the math expression object carries around its dependencies
with it.

This is slightly different than what people might be used
to from raw CloudWatch, where there is no hierarchy and all
metrics are supposed to be listed in the graph widget or alarm
with a unique ID, and then referenced by ID.

We can't make this contract obvious anymore by adding a hard
validation, but we can add warnings to hint people at the right
way to reference metrics in math expressions.

Fixes #13942, closes #17126.
@rix0rrr rix0rrr requested a review from a team April 8, 2022 12:49
@rix0rrr rix0rrr self-assigned this Apr 8, 2022
@gitpod-io
Copy link

gitpod-io bot commented Apr 8, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team April 8, 2022 12:49
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Apr 8, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Apr 8, 2022
Comment on lines +145 to +150
function recurse(w: IWidget) {
ret.push(w);
if (hasSubWidgets(w)) {
w.widgets.forEach(recurse);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a chance that we have a circular dependency in any widgets? That is, is it possible for a widget to be a subwidget of itself? If so we should add a depth check and throw a useful error message if we catch one.

Copy link
Contributor Author

@rix0rrr rix0rrr Apr 11, 2022

Choose a reason for hiding this comment

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

You can write code to do that, but it already won't work today with a stack blowing error. I'm not too concerned that someone would do it in practice and then not know what's going on.

Good catch though, I like the way you're thinking about correctness 😎

@rix0rrr rix0rrr requested a review from comcalvi April 11, 2022 13:19
@mergify
Copy link
Contributor

mergify bot commented Apr 11, 2022

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: d54c3cb
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 5472b11 into master Apr 12, 2022
@mergify mergify bot deleted the huijbers/math-id-check branch April 12, 2022 00:50
@mergify
Copy link
Contributor

mergify bot commented Apr 12, 2022

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).

StevePotter pushed a commit to StevePotter/aws-cdk that referenced this pull request Apr 27, 2022
It is intended that all metric identifiers referenced in a
MathExpression are included in the `usingMetrics` map. This
allows passing around complex metrics as a single object,
because the math expression object carries around its dependencies
with it.

This is slightly different than what people might be used
to from raw CloudWatch, where there is no hierarchy and all
metrics are supposed to be listed in the graph widget or alarm
with a unique ID, and then referenced by ID.

We can't make this contract obvious anymore by adding a hard
validation, but we can add warnings to hint people at the right
way to reference metrics in math expressions.

Fixes aws#13942, closes aws#17126.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-cloudwatch): Missing ids when creating math expressions
3 participants