-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Describe the bug
It seems with 2.198.0 AnomalyDetectionAlarm was introduced. In the past we used the normal Alarm and adjusted then the CfnAlarm via escape hatches. So we tried to update to the AnomalyDetectionAlarm construct. Sadly we receive some warnings:
[Warning at /.../.../...] Periods of metrics in 'usingMetrics' for Math expression 'ANOMALY_DETECTION_BAND(m0, 2)' have been overridden to 300 seconds. [ack: CloudWatch:Math:MetricsPeriodsOverridden]
This happens although the userd Metric itself has the period of 60s defined. The only way to get rid of this was to set the period directly on the AnomalyDetectionAlarm. This method is deprecated though with the information to use the period of the used Metric.
What is the intended way to solve this issue?
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
The period of the metric is used for the math expression period
Current Behavior
Currently the period of the metric is not used and the construct falls back to the default of 5m period.
Reproduction Steps
Define a AnomalyDetectionAlarm as in the documentation:
// Create a metric
Metric metric = Metric.Builder.create()
.namespace("AWS/EC2")
.metricName("CPUUtilization")
.statistic("Average")
.period(Duration.minutes(5))
.build();
// Create an anomaly detection alarm
AnomalyDetectionAlarm alarm = AnomalyDetectionAlarm.Builder.create(this, "AnomalyAlarm")
.metric(metric)
.evaluationPeriods(1)
// Number of standard deviations for the band (default: 2)
.stdDevs(2)
// Alarm outside on either side of the band, or just below or above it (default: outside)
.comparisonOperator(ComparisonOperator.LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD)
.alarmDescription("Alarm when metric is outside the expected band")
.build();Possible Solution
No response
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.199.0
AWS CDK CLI version
2.1017.1
Node.js Version
22.x
OS
Mac OSX
Language
Java
Language Version
21
Other information
No response