-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cloudwatch): support anomaly detection alarms #19956
feat(cloudwatch): support anomaly detection alarms #19956
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @brandondahler! Thanks for picking this up. The README looks excellent, and I have a few preliminary comments regarding the implementation.
packages/@aws-cdk/aws-cloudwatch/lib/anomaly-detection-alarm.ts
Outdated
Show resolved
Hide resolved
return actionArn; | ||
} | ||
|
||
private renderMetric(metric: IMetric, threshold: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: how much of this is copied directly from Alarm.renderMetric
and how much is original?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It originally was copied directly from Alarm.renderMetric
.
I then:
- Added code to assign/generate an id for the anomaly band expression
- Added code to resolve the target metric's id, generating it earlier than originally if it isn't assigned in the case of a MathExpression
- Updated the returns of the callbacks to include the
thresholdMetricId
value that was assigned/generated in the output. - Updated the returns of the callbacks for
dispatchMetric
to include the extra metric:{ expression: `ANOMALY_DETECTION_BAND(${metricId}, ${threshold})`, id: thresholdMetricId, label: 'Expected', returnData: true, },
I'll work through those suggestions soon. FYSA - In general most of this code was copied from Alarm, so the naming and documentation comments are likely also applicable there. I'm fine with making them for this new construct but that will make this construct diverge from how the normal Alarm construct is named / documented. |
4d5f00c
to
f0a98bd
Compare
Review comments addressed, rebased on latest master branch. |
Looks like its just under the wire on branch coverage, I'll review what branch coverage I'm missing soon. |
f0a98bd
to
0526376
Compare
Improved unit test coverage. |
0526376
to
a8edcff
Compare
Cleaned up some nits around documentation that I found after self-review. |
How is the usage of the const metric = new Metric(...);
const anomalyDetector = new CfnAnomalyDetector(this, "AnomalyDetector", {
metricName: invocationsMetric.metricName,
namespace: invocationsMetric.namespace,
stat: "Sum",
});
const alarm = new AnomalyDetectionAlarm(this, "Alarm", {
metric: metric,
...
}); An idea, does it make sense to construct |
My understanding from the documentation and testing is that CfnAnomalyDetector isn’t necessary for alarm usage. That simplifies usage down to the same as a normal alarm.
The only significant difference is that threshold represents the number of standard deviations the band should use and the comparison operator determines whether it should use the upper, lower, or both thresholds. |
I've looked a lot closer on how the documentation says things work around anomaly detection alarms and how that interacts with I believe that effectively how CloudWatch with an anomaly detection alarm works is that each time it tries to evaluate the upper and lower bound, if the anomaly detector doesn't already exist (or was deleted) it'll call Since the creation isn't technically required, the question becomes "Should we create/delete it because it makes things easier for customers in some manner?" The documentation makes reference to deleting unused anomaly detectors due to them having a recurring cost; however, the pricing page makes no mention of ongoing cost of anomaly detector resources existing (only the +2 metric cost associated with running an alarm). I believe the documentation that references that cost is just out of date. Due to the lack of extra cost, I don't think it is necessary to manage creating and deleting the anomaly detectors that are otherwise auto-created by CloudWatch. The only other consideration I found was that explicitly creating the anomaly detector allowed customers to exclude anomalous time ranges and configure the detector for a specific timezone (for DST purposes). The ability to configure the anomaly detector is an important feature that helps ensure that the anomaly detector doesn't train on bad data; however, I don't think configuring it within the TL;DR - I don't think that |
a8edcff
to
52d3f7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like our branch change to v2 caused a branch conflict. Can you please take a look at getting that resolved?
Copy, I'll get it fixed when I get some time -- hopefully in the next week or two. |
Allows customers to create Alarms with anomaly detection enabled. Supports both direct metrics and math expressions. Closes aws#10540
52d3f7e
to
94d1368
Compare
Rebased onto latest main |
Pull request has been modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! This is just an initial passthrough, I didn't get too into the weeds at this point. Please address the inline comments and then I'll provide a more thorough review.
Also, thank you for the extensive unit testing here!
@@ -51,18 +51,24 @@ export enum ComparisonOperator { | |||
/** | |||
* Specified statistic is lower than or greater than the anomaly model band. | |||
* Used only for alarms based on anomaly detection models | |||
* | |||
* @deprecated Use AnomalyDetectionAlarm instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a reason to do this. Can you explain why you want to deprecate these when they're used more widely than just in this context?
/** | ||
* Specify how missing data points are treated during alarm evaluation | ||
*/ | ||
export enum TreatMissingData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this move makes sense. This is directly related to creating an alarm.
* | ||
* @resource AWS::CloudWatch::Alarm | ||
*/ | ||
export class AnomalyDetectionAlarm extends AlarmBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like a lot of this is duplicating what's in the Alarm
class. We should abstract the duplications out of both into a class that these can extend.
@Mergifyio update |
✅ Branch has been successfully updated |
If/when you rebase without a code change, please use the Mergify commands instead of merging in other ways. It will keep my review active so I'll be able to more easily see when you've made updates to PR. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Our autoclose/autowarn action doesn't seem to be picking this PR up. It would normally warn after 21 days and then close after 28. Since this has been dormant this long, I'm going to go ahead and close this. If you would like to continue working on it, we certainly welcome that. Please open a new PR addressing the last round of feed back and we'll re-review. |
Hi, is there any update to this issue? Do we plan to provide user a more convenient way to create anomaly detection alarms? |
Do we already have some clear way on how to create anomaly detection alarms now or has this never been picked up ? |
Closes #10540
Implementation Notes
TreatMissingData
has to be moved fromalarm.ts
tometric.ts
as it not longer is specific to onlyAlarm
.Alarm
'sComparisonOperator
enum.AnomalyDetectionComparisonOperator
enum to contain the anomaly-based comparison operators.AnomalyDetectionAlarm
is mostly copied fromAlarm
, main change required was to update how renderMetric works.private/metric-util
file or not.All Submissions:
Adding new Unconventional Dependencies:
New Features
yarn integ
to deploy the infrastructure and generate the snapshot (i.e.yarn integ
without--dry-run
)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license