Skip to content

Commit c4b93e7

Browse files
committed
fix(cloudwatch): update regex expression that prevents CloudWatch:Math:UnknownIdentifier warnings (#33591)
Signed-off-by: Sergio García Prado <[email protected]>
1 parent 6df9bfe commit c4b93e7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ export class MathExpression implements IMetric {
707707
// we can add warnings.
708708
const missingIdentifiers = allIdentifiersInExpression(this.expression).filter(i => !this.usingMetrics[i]);
709709

710-
if (!this.expression.toUpperCase().match('\\s*INSIGHT_RULE_METRIC|SELECT|SEARCH|METRICS\\s.*') && missingIdentifiers.length > 0) {
710+
if (!this.expression.toUpperCase().match('\\b(INSIGHT_RULE_METRIC|SELECT|SEARCH|METRICS)\\b') && missingIdentifiers.length > 0) {
711711
warnings['CloudWatch:Math:UnknownIdentifier'] = `Math expression '${this.expression}' references unknown identifiers: ${missingIdentifiers.join(', ')}. Please add them to the 'usingMetrics' map.`;
712712
}
713713

packages/aws-cdk-lib/aws-cloudwatch/test/metric-math.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ describe('Metric Math', () => {
8080
expect(m.warningsV2).toBeUndefined();
8181
});
8282

83+
test('metrics METRICS expression with parameter does not produce warning for unknown identifier', () => {
84+
const m = new MathExpression({
85+
expression: 'SUM(METRICS("parameter"))',
86+
usingMetrics: {},
87+
});
88+
89+
expect(m.warningsV2).toBeUndefined();
90+
});
91+
8392
test('metrics search expression does not produce warning for unknown identifier', () => {
8493
const m = new MathExpression({
8594
expression: "SEARCH('{dimension_one, dimension_two} my_metric', 'Average', 300)",

0 commit comments

Comments
 (0)