From 6bd7215e5f23fcbb3e6f8d01178a6c37594a14f6 Mon Sep 17 00:00:00 2001 From: kazuho cryer-shinozuka Date: Thu, 6 Jul 2023 18:11:54 +0900 Subject: [PATCH] feat: Enable configuration of evaluation periods in watchLambdaFunction (#1182) --- API.md | 16 ++++++++++++---- src/lambda.ts | 24 +++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/API.md b/API.md index 6d738f0c..704384f4 100644 --- a/API.md +++ b/API.md @@ -154,9 +154,11 @@ new WatchLambdaFunction(scope: Construct, id: string, props: WatchLambdaFunction * **scope** ([Construct](#constructs-construct)) *No description* * **id** (string) *No description* * **props** ([WatchLambdaFunctionProps](#cdk-watchful-watchlambdafunctionprops)) *No description* + * **durationEvaluationPeriods** (number) Number of periods to evaluate for the duration alarms. __*Default*__: 3 * **durationThresholdPercent** (number) Threshold for the duration alarm as percentage of the function's timeout value. __*Default*__: 80 + * **errorsEvaluationPeriods** (number) Number of periods to evaluate for the errors alarms. __*Default*__: 3 * **errorsPerMinuteThreshold** (number) Number of allowed errors per minute. __*Default*__: 0 - * **evaluationPeriods** (number) Number of periods to evaluate for the alarms. __*Default*__: 3 + * **throttlesEvaluationPeriods** (number) Number of periods to evaluate for the throttles alarms. __*Default*__: 3 * **throttlesPerMinuteThreshold** (number) Number of allowed throttles per minute. __*Default*__: 0 * **fn** ([aws_lambda.Function](#aws-cdk-lib-aws-lambda-function)) *No description* * **title** (string) *No description* @@ -383,9 +385,11 @@ watchLambdaFunction(title: string, fn: Function, options?: WatchLambdaFunctionOp * **title** (string) *No description* * **fn** ([aws_lambda.Function](#aws-cdk-lib-aws-lambda-function)) *No description* * **options** ([WatchLambdaFunctionOptions](#cdk-watchful-watchlambdafunctionoptions)) *No description* + * **durationEvaluationPeriods** (number) Number of periods to evaluate for the duration alarms. __*Default*__: 3 * **durationThresholdPercent** (number) Threshold for the duration alarm as percentage of the function's timeout value. __*Default*__: 80 + * **errorsEvaluationPeriods** (number) Number of periods to evaluate for the errors alarms. __*Default*__: 3 * **errorsPerMinuteThreshold** (number) Number of allowed errors per minute. __*Default*__: 0 - * **evaluationPeriods** (number) Number of periods to evaluate for the alarms. __*Default*__: 3 + * **throttlesEvaluationPeriods** (number) Number of periods to evaluate for the throttles alarms. __*Default*__: 3 * **throttlesPerMinuteThreshold** (number) Number of allowed throttles per minute. __*Default*__: 0 __Returns__: @@ -684,9 +688,11 @@ Name | Type | Description Name | Type | Description -----|------|------------- +**durationEvaluationPeriods**?🔹 | number | Number of periods to evaluate for the duration alarms.
__*Default*__: 3 **durationThresholdPercent**?🔹 | number | Threshold for the duration alarm as percentage of the function's timeout value.
__*Default*__: 80 +**errorsEvaluationPeriods**?🔹 | number | Number of periods to evaluate for the errors alarms.
__*Default*__: 3 **errorsPerMinuteThreshold**?🔹 | number | Number of allowed errors per minute.
__*Default*__: 0 -**evaluationPeriods**?🔹 | number | Number of periods to evaluate for the alarms.
__*Default*__: 3 +**throttlesEvaluationPeriods**?🔹 | number | Number of periods to evaluate for the throttles alarms.
__*Default*__: 3 **throttlesPerMinuteThreshold**?🔹 | number | Number of allowed throttles per minute.
__*Default*__: 0 @@ -703,9 +709,11 @@ Name | Type | Description **fn**🔹 | [aws_lambda.Function](#aws-cdk-lib-aws-lambda-function) | **title**🔹 | string | **watchful**🔹 | [IWatchful](#cdk-watchful-iwatchful) | +**durationEvaluationPeriods**?🔹 | number | Number of periods to evaluate for the duration alarms.
__*Default*__: 3 **durationThresholdPercent**?🔹 | number | Threshold for the duration alarm as percentage of the function's timeout value.
__*Default*__: 80 +**errorsEvaluationPeriods**?🔹 | number | Number of periods to evaluate for the errors alarms.
__*Default*__: 3 **errorsPerMinuteThreshold**?🔹 | number | Number of allowed errors per minute.
__*Default*__: 0 -**evaluationPeriods**?🔹 | number | Number of periods to evaluate for the alarms.
__*Default*__: 3 +**throttlesEvaluationPeriods**?🔹 | number | Number of periods to evaluate for the throttles alarms.
__*Default*__: 3 **throttlesPerMinuteThreshold**?🔹 | number | Number of allowed throttles per minute.
__*Default*__: 0 diff --git a/src/lambda.ts b/src/lambda.ts index eae07851..e69419be 100644 --- a/src/lambda.ts +++ b/src/lambda.ts @@ -33,11 +33,25 @@ export interface WatchLambdaFunctionOptions { readonly durationThresholdPercent?: number; /** - * Number of periods to evaluate for the alarms. + * Number of periods to evaluate for the errors alarms. * * @default 3 */ - readonly evaluationPeriods?: number; + readonly errorsEvaluationPeriods?: number; + + /** + * Number of periods to evaluate for the throttles alarms. + * + * @default 3 + */ + readonly throttlesEvaluationPeriods?: number; + + /** + * Number of periods to evaluate for the duration alarms. + * + * @default 3 + */ + readonly durationEvaluationPeriods?: number; } export interface WatchLambdaFunctionProps extends WatchLambdaFunctionOptions { @@ -70,16 +84,16 @@ export class WatchLambdaFunction extends Construct { const { errorsMetric, errorsAlarm } = this.createErrorsMonitor( props.errorsPerMinuteThreshold, - props.evaluationPeriods, + props.errorsEvaluationPeriods, ); const { throttlesMetric, throttlesAlarm } = this.createThrottlesMonitor( props.throttlesPerMinuteThreshold, - props.evaluationPeriods, + props.throttlesEvaluationPeriods, ); const { durationMetric, durationAlarm } = this.createDurationMonitor( timeoutSec, props.durationThresholdPercent, - props.evaluationPeriods, + props.durationEvaluationPeriods, ); const invocationsMetric = this.metrics.metricInvocations( this.fn.functionName,