From 8179b2d101a65ec2cc13b7e8f444afcacf631346 Mon Sep 17 00:00:00 2001 From: Sebastien Corbiere Date: Thu, 29 Aug 2024 12:07:09 -0700 Subject: [PATCH] Refactor isAnomalyDetectionOperator method --- packages/aws-cdk-lib/aws-cloudwatch/lib/alarm.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/alarm.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/alarm.ts index 502efdc3b87e1..ea983e63d8e6f 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/alarm.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/alarm.ts @@ -81,6 +81,11 @@ const OPERATOR_SYMBOLS: { [key: string]: string } = { LessThanOrEqualToThreshold: '<=', }; +const ANOMALY_DETECTION_OPERATORS: ComparisonOperator[] = [ + ComparisonOperator.LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD, + ComparisonOperator.GREATER_THAN_UPPER_THRESHOLD, + ComparisonOperator.LESS_THAN_LOWER_THRESHOLD, +]; /** * Specify how missing data points are treated during alarm evaluation */ @@ -151,9 +156,7 @@ export class Alarm extends AlarmBase { * @returns true if the operator is an anomaly detection operator, false otherwise. */ public static isAnomalyDetectionOperator(operator: ComparisonOperator): boolean { - return operator === ComparisonOperator.LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD - || operator === ComparisonOperator.GREATER_THAN_UPPER_THRESHOLD - || operator === ComparisonOperator.LESS_THAN_LOWER_THRESHOLD; + return ANOMALY_DETECTION_OPERATORS.includes(operator); } /**