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(aws-cloudwatch): can specify an id in math expression metrics #17126

Closed
wants to merge 10 commits into from

Conversation

corymhall
Copy link
Contributor

add the ability to assign a unique id to a math expression metric.
Currently if you are creating multiple math expression metrics they will
all get the id of m1 which makes it difficult to differentiate them in
the console or reference them in other math expression metrics

fixes #13942


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 Oct 22, 2021

@github-actions github-actions bot added the @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch label Oct 22, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Oct 27, 2021
Copy link
Contributor

@madeline-k madeline-k left a comment

Choose a reason for hiding this comment

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

This is great!

To help out users when they don't specify any ids, I think we should also implement behavior similar to the Cloudwatch console where as you add MathExpressions to a graph widget, they are automatically assigned ids starting with e1, e2, and incrementing from there. This would ensure that customers graphs render correctly even if they do not manually specify ids themselves.

We can either merge as is, and open another issue for the default id behavior. Or you can add to this PR. Let me know what you'd like to do!

packages/@aws-cdk/aws-cloudwatch/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-cloudwatch/lib/metric.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-cloudwatch/test/metric-math.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-cloudwatch/test/metric-math.test.ts Outdated Show resolved Hide resolved
@@ -173,6 +176,31 @@ export class MetricSet<A> {
if (!entry.id && id) {
entry.id = id;
this.metricById.set(id, entry);
// if we don't have an id and this is a math expression
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@madeline-k I've implemented the auto assign id logic here. Rather than try and figure out if an id has already been manually assigned, I decided to instead just reserve an id format for auto assigned ids.

Also, since this logic is at the metric level, it also applies to Alarms in addition to Graphs. Alarms already had their own similar auto assign id logic which this will overwrite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm I may have to rethink that since we have integration tests in other modules reference the Alarm id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@madeline-k I updated the logic so that it only applies to Graphs, but did end up having to update the kinesis integration tests.

corymhall and others added 5 commits November 17, 2021 15:48
add the ability to assign a unique id to a math expression metric.
Currently if you are creating multiple math expression metrics they will
all get the id of m1 which makes it difficult to differentiate them in
the console or reference them in other math expression metrics

fixes #13942
Co-authored-by: Madeline Kusters <80541297+madeline-k@users.noreply.github.com>
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@rix0rrr rix0rrr added bug This issue is a bug. p2 and removed @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch contribution/core This is a PR that came from AWS. labels Mar 4, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 4, 2022
rix0rrr added a commit that referenced this pull request 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.
@mergify mergify bot closed this in #19825 Apr 12, 2022
mergify bot pushed a commit that referenced this pull request Apr 12, 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*
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. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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