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

cloudwatch: CDK detects false-positive missing identifiers on metric expressions #33591

Closed
1 task
garciparedes opened this issue Feb 26, 2025 · 4 comments · Fixed by #33592
Closed
1 task
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch bug This issue is a bug. effort/small Small work item – less than a day of effort p2 pr/needs-review

Comments

@garciparedes
Copy link
Contributor

garciparedes commented Feb 26, 2025

Describe the bug

I have a metric expression defined as SUM(METRICS("prefix")) where some of my metrics contains the "prefix" string.

When I synthetize the CDK, I started getting warning like this:

[Warning at $SECRET Math expression 'SUM(METRICS("prefix"))' references unknown identifiers: prefix. Please add them to the 'usingMetrics' map. [ack: CloudWatch:Math:UnknownIdentifier]

However, those are false-positives and should be skipped in the following line:

if (!this.expression.toUpperCase().match('\\s*INSIGHT_RULE_METRIC|SELECT|SEARCH|METRICS\\s.*') && missingIdentifiers.length > 0) {

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

Given that the METRICS operation accept part identifier names, it should not produce any warnings.

Current Behavior

It produces warnings.

Reproduction Steps

Partially define a identifier in a SUM(METRICS("partial")) expression.

Possible Solution

Update regular expression to properly handle the keywords that skip the warning:

'\\b(INSIGHT_RULE_METRIC|SELECT|SEARCH|METRICS)\\b'

Additional Information/Context

No response

CDK CLI Version

2.173.4

Framework Version

No response

Node.js Version

18

OS

OS X

Language

TypeScript

Language Version

No response

Other information

No response

@garciparedes garciparedes added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2025
@github-actions github-actions bot added the @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch label Feb 26, 2025
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Feb 26, 2025
…h:UnknownIdentifier warnings (aws#33591)

Signed-off-by: Sergio García Prado <[email protected]>
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Feb 26, 2025
…h:UnknownIdentifier warnings (aws#33591)

Signed-off-by: Sergio García Prado <[email protected]>
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Feb 26, 2025
…h:UnknownIdentifier warnings (aws#33591)

Signed-off-by: Sergio García Prado <[email protected]>
@ashishdhingra
Copy link
Contributor

Looking at the documentation for METRICS() function at Using math expressions with CloudWatch metrics, it mentions that:


You can use the METRICS() function with a string to return only the graphed metrics that contain that string in their Id field. For example, the expression SUM(METRICS("errors")) returns a time series that is the sum of the values of all the graphed metrics that have ‘errors’ in their Id field. You can also use SUM([METRICS(“4xx”), METRICS(“5xx”)]) to match multiple strings.


So the check at

if (!this.expression.toUpperCase().match('\\s*INSIGHT_RULE_METRIC|SELECT|SEARCH|METRICS\\s.*') && missingIdentifiers.length > 0) {
appears to be incorrect.

@ashishdhingra ashishdhingra added p2 effort/small Small work item – less than a day of effort pr/needs-review and removed needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2025
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Feb 27, 2025
…h:UnknownIdentifier warnings (aws#33591)

Signed-off-by: Sergio García Prado <[email protected]>
garciparedes added a commit to garciparedes/aws-cdk that referenced this issue Feb 27, 2025
…h:UnknownIdentifier warnings (aws#33591)

Signed-off-by: Sergio García Prado <[email protected]>
@garciparedes
Copy link
Contributor Author

Yeah, seems like there is a set of functions that can be used in the CloudWatch Metric expressions where partial identifiers are supported.

Copy link

github-actions bot commented Mar 3, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

1 similar comment
Copy link

github-actions bot commented Mar 3, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch bug This issue is a bug. effort/small Small work item – less than a day of effort p2 pr/needs-review
Projects
None yet
2 participants