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): period of each metric in usingMetrics for MathExpression is ignored (#30986)
### Issue # (if applicable)
Closes #<issue number here>.
### Reason for this change
The `usingMetrics` property (`Record<string, IMetric>`) in `MathExpressionProps` has Metric objects with a `period`.
On the other hand, in the `MathExpression` construct, the `period` of each metric in the `usingMetrics` is ignored and instead overridden by the `period` of the `MathExpression`. Even if the `period` of the `MathExpression` is not specified, it is overridden by its default value.
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts#L606-L608
However the statement is not written in the JSDoc.
https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts#L566
```ts
new MathExpression({
expression: "m1+m2",
label: "AlbErrors",
usingMetrics: {
m1: metrics.custom("HTTPCode_ELB_500_Count", {
period: Duration.minutes(1), // <- ignored and overridden by default value `Duration.minutes(5)` of `period` in the `MathExpressionOptions`
statistic: "Sum",
label: "HTTPCode_ELB_500_Count",
}),
m2: metrics.custom("HTTPCode_ELB_502_Count", {
period: Duration.minutes(1), // <- ignored and overridden by default value `Duration.minutes(5)` of `period` in the `MathExpressionOptions`
statistic: "Sum",
label: "HTTPCode_ELB_502_Count",
}),
},
}),
```
### Description of changes
The current documentation could be confusing to users, so add this description. Also added warnings in the situation.
### Description of how you validated changes
### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
warnings['CloudWatch:Math:MetricsPeriodsOverridden']=`Periods of metrics in 'usingMetrics' for Math expression '${this.expression}' have been overridden to ${this.period.toSeconds()} seconds.`;
warnings['CloudWatch:Math:UnknownIdentifier']=`Math expression '${this.expression}' references unknown identifiers: ${missingIdentifiers.join(', ')}. Please add them to the 'usingMetrics' map.`;
630
665
}
@@ -879,23 +914,33 @@ function ifUndefined<T>(x: T | undefined, def: T | undefined): T | undefined {
'CloudWatch:Math:MetricsPeriodsOverridden': 'Periods of metrics in \'usingMetrics\' for Math expression \'m1 + m2\' have been overridden to 180 seconds.',
153
+
});
154
+
});
155
+
156
+
test('warn if a period is specified in usingMetrics and not equal to the default value of the period for MathExpression',()=>{
'CloudWatch:Math:MetricsPeriodsOverridden': 'Periods of metrics in \'usingMetrics\' for Math expression \'e1 + m1\' have been overridden to 180 seconds.',
0 commit comments