Skip to content

Commit e2aa338

Browse files
authored
feat(cloudwatch): anomaly detection alarms (#31232)
### Issue #10540 Closes #10540. ### Reason for this change This change adds proper support for creating CloudWatch anomaly detection alarms, fixing a long-standing issue where alarms using anomaly detection with range-based comparison operators would fail at deployment time with the error: ComparisonOperators for ranges require ThresholdMetricId to be set (Service: AmazonCloudWatch; Status Code: 400; Error Code: ValidationError) ### Description of changes 1. **New `AnomalyDetectionAlarm` class**: a dedicated class for anomaly detection alarms that handles all the complexity of setting up the anomaly detection band and configuring the alarm correctly. 2. **Enhanced helper methods**: Added the `anomalyDetectionFor` helper method on `Metric` class to handle the creation of the MathExpression wrapper using the function `ANOMALY_DETECTION_BAND`. 3. **Improved validation**: Added proper validation to ensure users don't mix standard alarm operators with anomaly detection metrics or vice versa. ### Description of how you validated changes - Added comprehensive unit tests for the new `AnomalyDetectionAlarm` class - Executed the integration test (`packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.anomaly-detection-alarm.ts`) on a test account ### 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*
1 parent 67c8e5a commit e2aa338

33 files changed

+32599
-776
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.anomaly-detection-alarm.js.snapshot/AnomalyDetectionAlarmIntegTestDefaultTestDeployAssert033A4433.assets.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)