Skip to content
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): construct for alarms based on anomaly detection (#10540) #29594

Closed
wants to merge 1 commit into from

Conversation

vgolemis
Copy link

@vgolemis vgolemis commented Mar 24, 2024

feat(cloudwatch): construct for alarms based on anomaly detection (#10540)

Issue # (if applicable)

Closes #10540.

Reason for this change

Introduce new construct AnomalyDetectionAlarm that covers the gap of creating an Alarm based on anomaly detection.

Description of changes

  • Documentation for the API of AnomalyDetectionAlarm
  • New class AnomalyDetectionAlarm that creates an alarm that utilizes [CloudWatch anomaly detection](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Anomaly_Detection.html
    • The underlying resource is a AWS::CloudWatch::Alarm
    • It can create the Alarm either directly if the metric property has an ANOMALY_DETECTION_BAND metric expression or can generate it. The user can provide the generateAnomalyDetectionExpression property to define this behavior.
    • Validates the the ComparisonOperator provided applies to the anomaly detection scenario.
    • The thresholdMetricId was not exposed to the user because the IMetric interface does not provide a property to define the id of the metric. This is done when defining the MetricDataQueryProperty; decided to not force the user to provide the array of MetricDataQueryProperty.
    • The threshold property is mandatory by the CreateAlarmOptions. It was repurposed to define the anomaly detection threshold if the function generates the ANOMALY_DETECTION_BAND metric expression.
    • The implementation of the renderMetric() verifies the expressions provided are correct and forces the appropriate reference ids to be in place.
  • The static methods fromAlarmName() and fromAlarmArn() were the same for Alarm and CompositeAlarm so moved the to the AlarmBase so all of the classes can access them.

Description of how you validated changes

Integration test and Unit tests and have been added for the AnomalyDetectionAlarm. Verified the existing tests for the Alarm and CompositeAlarm are not impacted.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team March 24, 2024 19:11
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Mar 24, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation dismissed their stale review March 24, 2024 21:52

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@vgolemis vgolemis force-pushed the issue-10540 branch 3 times, most recently from a90de74 to b2fbb31 Compare March 25, 2024 00:57
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 0a30d8f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@vgolemis vgolemis marked this pull request as ready for review March 25, 2024 02:04
This was referenced Mar 25, 2024
@paulhcsun paulhcsun added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 24, 2024
Copy link
Contributor

@comcalvi comcalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there no CfnAnomalyDetector in this construct? Can you help me understand how this works? I thought the AnomalyDetectorAlarm required a reference to the metric of an AnomalyDetector

Comment on lines +48 to +54
public static fromAlarmName(scope: Construct, id: string, alarmName: string): IAlarm {
const stack = Stack.of(scope);

return this.fromAlarmArn(scope, id, stack.formatArn({
service: 'cloudwatch',
resource: 'alarm',
resourceName: alarmName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we move these from methods out of the Base class? These methods should always be named fromXyzArn or fromXyzName, where Xyz is the name of the construct; Alarm, for example, but also fromAnomalyDetectionAlarm

/**
* Properties for Anomaly Detection Alarms
*/
export interface AnomalyDetectionAlarmProps extends AlarmProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AnomalyDetectionAlarmProps extend the AlarmProps, but the AnomalyDetectionAlarm does not extend Alarm.

Why is the AnomalyDetectionAlarm a separate construct? It looks like it's a strict superset of the Alarm we have already, which suggests that instead of making a new construct we could add a prop to Alarm.

To make this decision we have to understand what the differences between an AnomalyDetectionAlarm and an Alarm are. Are there any properties unique to the AnomalyDetectionAlarm which conflict with the props of a regular Alarm? (Props 'A' and 'B' are said to conflict if I can (or should) specify 'A' or 'B', but not both).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 25, 2024
@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-cloudwatch] Missing ThresholdMetricId
4 participants