You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(cloudwatch): MathExpression id contract is not clear (#19825)
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*
@@ -203,6 +203,10 @@ export class Alarm extends AlarmBase {
203
203
label: `${this.metric}${OPERATOR_SYMBOLS[comparisonOperator]}${props.threshold} for ${datapoints} datapoints within ${describePeriod(props.evaluationPeriods*metricPeriod(props.metric).toSeconds())}`,
warnings.push(`Math expression '${this.expression}' references unknown identifiers: ${missingIdentifiers.join(', ')}. Please add them to the 'usingMetrics' map.`);
587
+
}
588
+
589
+
// Also copy warnings from deeper levels so graphs, alarms only have to inspect the top-level objects
590
+
for(constmofObject.values(this.usingMetrics)){
591
+
warnings.push(...m.warnings??[]);
592
+
}
593
+
594
+
if(warnings.length>0){
595
+
this.warnings=warnings;
596
+
}
571
597
}
572
598
573
599
/**
@@ -677,15 +703,27 @@ export class MathExpression implements IMetric {
0 commit comments