From 7dcd76f455b5057cf78fde863b537d4f5f2c304a Mon Sep 17 00:00:00 2001 From: Grzegorz Kozub Date: Thu, 4 Jan 2024 11:06:11 +0100 Subject: [PATCH 1/4] feat: Add support for metrics --- API.md | 485 ++++++++++++++++++ CONTRIBUTING.md | 2 +- src/core/flows/flow-base.ts | 38 ++ .../core/flows/on-demand-flow-metrics.test.ts | 81 +++ 4 files changed, 605 insertions(+), 1 deletion(-) create mode 100644 test/core/flows/on-demand-flow-metrics.test.ts diff --git a/API.md b/API.md index dd79813c..eccb92de 100644 --- a/API.md +++ b/API.md @@ -501,6 +501,12 @@ new FlowBase(scope: Construct, id: string, props: FlowBaseProps) | --- | --- | | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | +| metric | *No description.* | +| metricFlowExecutionRecordsProcessed | *No description.* | +| metricFlowExecutionsFailed | *No description.* | +| metricFlowExecutionsStarted | *No description.* | +| metricFlowExecutionsSucceeded | *No description.* | +| metricFlowExecutionTime | *No description.* | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -537,6 +543,84 @@ account for data recovery and cleanup later (`RemovalPolicy.RETAIN`). --- +##### `metric` + +```typescript +public metric(metricName: string, options?: MetricOptions): Metric +``` + +###### `metricName`Required + +- *Type:* string + +--- + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionRecordsProcessed` + +```typescript +public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsFailed` + +```typescript +public metricFlowExecutionsFailed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsStarted` + +```typescript +public metricFlowExecutionsStarted(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsSucceeded` + +```typescript +public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionTime` + +```typescript +public metricFlowExecutionTime(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + ##### `onEvent` ```typescript @@ -1900,6 +1984,12 @@ new OnDemandFlow(scope: Construct, id: string, props: OnDemandFlowProps) | --- | --- | | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | +| metric | *No description.* | +| metricFlowExecutionRecordsProcessed | *No description.* | +| metricFlowExecutionsFailed | *No description.* | +| metricFlowExecutionsStarted | *No description.* | +| metricFlowExecutionsSucceeded | *No description.* | +| metricFlowExecutionTime | *No description.* | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -1936,6 +2026,84 @@ account for data recovery and cleanup later (`RemovalPolicy.RETAIN`). --- +##### `metric` + +```typescript +public metric(metricName: string, options?: MetricOptions): Metric +``` + +###### `metricName`Required + +- *Type:* string + +--- + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionRecordsProcessed` + +```typescript +public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsFailed` + +```typescript +public metricFlowExecutionsFailed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsStarted` + +```typescript +public metricFlowExecutionsStarted(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsSucceeded` + +```typescript +public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionTime` + +```typescript +public metricFlowExecutionTime(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + ##### `onEvent` ```typescript @@ -2187,6 +2355,12 @@ new OnEventFlow(scope: Construct, id: string, props: OnEventFlowProps) | --- | --- | | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | +| metric | *No description.* | +| metricFlowExecutionRecordsProcessed | *No description.* | +| metricFlowExecutionsFailed | *No description.* | +| metricFlowExecutionsStarted | *No description.* | +| metricFlowExecutionsSucceeded | *No description.* | +| metricFlowExecutionTime | *No description.* | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -2225,6 +2399,84 @@ account for data recovery and cleanup later (`RemovalPolicy.RETAIN`). --- +##### `metric` + +```typescript +public metric(metricName: string, options?: MetricOptions): Metric +``` + +###### `metricName`Required + +- *Type:* string + +--- + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionRecordsProcessed` + +```typescript +public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsFailed` + +```typescript +public metricFlowExecutionsFailed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsStarted` + +```typescript +public metricFlowExecutionsStarted(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsSucceeded` + +```typescript +public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionTime` + +```typescript +public metricFlowExecutionTime(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + ##### `onEvent` ```typescript @@ -2512,6 +2764,12 @@ new OnScheduleFlow(scope: Construct, id: string, props: OnScheduleFlowProps) | --- | --- | | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | +| metric | *No description.* | +| metricFlowExecutionRecordsProcessed | *No description.* | +| metricFlowExecutionsFailed | *No description.* | +| metricFlowExecutionsStarted | *No description.* | +| metricFlowExecutionsSucceeded | *No description.* | +| metricFlowExecutionTime | *No description.* | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -2549,6 +2807,84 @@ account for data recovery and cleanup later (`RemovalPolicy.RETAIN`). --- +##### `metric` + +```typescript +public metric(metricName: string, options?: MetricOptions): Metric +``` + +###### `metricName`Required + +- *Type:* string + +--- + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionRecordsProcessed` + +```typescript +public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsFailed` + +```typescript +public metricFlowExecutionsFailed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsStarted` + +```typescript +public metricFlowExecutionsStarted(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsSucceeded` + +```typescript +public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionTime` + +```typescript +public metricFlowExecutionTime(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + ##### `onEvent` ```typescript @@ -4767,6 +5103,12 @@ new TriggeredFlowBase(scope: Construct, id: string, props: FlowBaseProps) | --- | --- | | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | +| metric | *No description.* | +| metricFlowExecutionRecordsProcessed | *No description.* | +| metricFlowExecutionsFailed | *No description.* | +| metricFlowExecutionsStarted | *No description.* | +| metricFlowExecutionsSucceeded | *No description.* | +| metricFlowExecutionTime | *No description.* | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -4804,6 +5146,84 @@ account for data recovery and cleanup later (`RemovalPolicy.RETAIN`). --- +##### `metric` + +```typescript +public metric(metricName: string, options?: MetricOptions): Metric +``` + +###### `metricName`Required + +- *Type:* string + +--- + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionRecordsProcessed` + +```typescript +public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsFailed` + +```typescript +public metricFlowExecutionsFailed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsStarted` + +```typescript +public metricFlowExecutionsStarted(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsSucceeded` + +```typescript +public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionTime` + +```typescript +public metricFlowExecutionTime(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + ##### `onEvent` ```typescript @@ -13570,11 +13990,76 @@ A representation of a mapping operation, that is an operation filtering records | **Name** | **Description** | | --- | --- | +| metricFlowExecutionRecordsProcessed | *No description.* | +| metricFlowExecutionsFailed | *No description.* | +| metricFlowExecutionsStarted | *No description.* | +| metricFlowExecutionsSucceeded | *No description.* | +| metricFlowExecutionTime | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | --- +##### `metricFlowExecutionRecordsProcessed` + +```typescript +public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsFailed` + +```typescript +public metricFlowExecutionsFailed(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsStarted` + +```typescript +public metricFlowExecutionsStarted(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionsSucceeded` + +```typescript +public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + +##### `metricFlowExecutionTime` + +```typescript +public metricFlowExecutionTime(options?: MetricOptions): Metric +``` + +###### `options`Optional + +- *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions + +--- + ##### `onRunCompleted` ```typescript diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a794a1cb..ae5f8ae6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,7 +66,7 @@ The following tools need to be installed on your system prior to building `cdk-a - [.NET SDK >= 6.0.x](https://www.microsoft.com/net/download) - [Python >= 3.6.5, < 4.0](https://www.python.org/downloads/release/python-365/) - [Java Development Kit >= 17.0.0](https://www.oracle.com/java/technologies/downloads/) -- [Golang >= 16.0.0](https://go.dev/doc/install) +- [Golang >= 1.16.0](https://go.dev/doc/install) Install dependencies diff --git a/src/core/flows/flow-base.ts b/src/core/flows/flow-base.ts index 26abd661..254300cd 100644 --- a/src/core/flows/flow-base.ts +++ b/src/core/flows/flow-base.ts @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0 import { Duration, IResource, Lazy, Resource } from 'aws-cdk-lib'; import { CfnFlow } from 'aws-cdk-lib/aws-appflow'; +import { Metric, MetricOptions } from 'aws-cdk-lib/aws-cloudwatch'; import { OnEventOptions, Rule, Schedule } from 'aws-cdk-lib/aws-events'; import { IKey } from 'aws-cdk-lib/aws-kms'; import { Construct, IConstruct } from 'constructs'; @@ -35,6 +36,12 @@ export interface IFlow extends IResource { onRunCompleted(id: string, options?: OnEventOptions): Rule; + metricFlowExecutionsStarted(options?: MetricOptions): Metric; + metricFlowExecutionsFailed(options?: MetricOptions): Metric; + metricFlowExecutionsSucceeded(options?: MetricOptions): Metric; + metricFlowExecutionTime(options?: MetricOptions): Metric; + metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric; + /** * @internal */ @@ -223,6 +230,37 @@ export abstract class FlowBase extends Resource implements IFlow { }); } + public metric(metricName: string, options?: MetricOptions): Metric { + return new Metric({ + namespace: 'AWS/AppFlow', + metricName, + dimensionsMap: { + FlowName: this.name, + }, + ...options, + }); + } + + public metricFlowExecutionsStarted(options?: MetricOptions): Metric { + return this.metric('FlowExecutionsStarted', options); + } + + public metricFlowExecutionsFailed(options?: MetricOptions): Metric { + return this.metric('FlowExecutionsFailed', options); + } + + public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric { + return this.metric('FlowExecutionsSucceeded', options); + } + + public metricFlowExecutionTime(options?: MetricOptions): Metric { + return this.metric('FlowExecutionTime', options); + } + + public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric { + return this.metric('FlowExecutionRecordsProcessed', options); + } + private buildTriggerProperties(scope: IConstruct, id: string, props: TriggerProperties): CfnFlow.ScheduledTriggerPropertiesProperty { const updater = new FlowTimeUpdater(scope, `${id}Updater`, { diff --git a/test/core/flows/on-demand-flow-metrics.test.ts b/test/core/flows/on-demand-flow-metrics.test.ts new file mode 100644 index 00000000..cb2cc48a --- /dev/null +++ b/test/core/flows/on-demand-flow-metrics.test.ts @@ -0,0 +1,81 @@ +/* +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ +import { Stack } from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import { Alarm, Metric } from 'aws-cdk-lib/aws-cloudwatch'; +import { Key } from 'aws-cdk-lib/aws-kms'; +import { Bucket } from 'aws-cdk-lib/aws-s3'; +import { + OnDemandFlow, + S3Source, + S3Destination, + Mapping, +} from '../../../src'; + +describe('OnDemandFlow metrics', () => { + test('', () => { + + const stack = new Stack(undefined, 'TestStack'); + + const bucket = new Bucket(stack, 'TestBucket'); + + const source = new S3Source({ + bucket: bucket, + prefix: 'account', + }); + + const destination = new S3Destination({ + location: { bucket, prefix: 'new-account' }, + }); + + + const flow = new OnDemandFlow(stack, 'OnDemandFlow', { + source, + destination, + key: new Key(stack, 'TestKey'), + mappings: [Mapping.mapAll()], + }); + + addAlarmForMetric(stack, flow.metricFlowExecutionsStarted(), 'FlowExecutionsStartedAlarm'); + addAlarmForMetric(stack, flow.metricFlowExecutionsFailed(), 'FlowExecutionsFailedAlarm'); + addAlarmForMetric(stack, flow.metricFlowExecutionsSucceeded(), 'FlowxecutionsSucceededAlarm'); + addAlarmForMetric(stack, flow.metricFlowExecutionTime(), 'FlowExecutionTimeAlarm'); + addAlarmForMetric(stack, flow.metricFlowExecutionRecordsProcessed(), 'FlowExecutionRecordsProcessedAlarm'); + + const template = Template.fromStack(stack); + console.log(JSON.stringify(template.toJSON())); + + template.resourceCountIs('AWS::CloudWatch::Alarm', 5); + template.hasResourceProperties('AWS::CloudWatch::Alarm', { + MetricName: 'FlowExecutionsStarted', + Namespace: 'AWS/AppFlow', + }); + template.hasResourceProperties('AWS::CloudWatch::Alarm', { + MetricName: 'FlowExecutionsFailed', + Namespace: 'AWS/AppFlow', + }); + template.hasResourceProperties('AWS::CloudWatch::Alarm', { + MetricName: 'FlowExecutionsSucceeded', + Namespace: 'AWS/AppFlow', + }); + template.hasResourceProperties('AWS::CloudWatch::Alarm', { + MetricName: 'FlowExecutionTime', + Namespace: 'AWS/AppFlow', + }); + template.hasResourceProperties('AWS::CloudWatch::Alarm', { + MetricName: 'FlowExecutionRecordsProcessed', + Namespace: 'AWS/AppFlow', + }); + }); +}); + +function addAlarmForMetric(stack: Stack, metric: Metric, name: string) { + new Alarm(stack, name, { + metric, + threshold: 1000, + evaluationPeriods: 2, + }); +} + From 48ba585c4f1f886fb1158c4e2111d55d1d673071 Mon Sep 17 00:00:00 2001 From: kozub Date: Thu, 4 Jan 2024 12:58:09 +0100 Subject: [PATCH 2/4] doc: Update documentation for metrics --- README.md | 36 +++++++++++++++++++++++++++++++++++- src/core/flows/flow-base.ts | 25 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4240ffe8..23db5a71 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,41 @@ const flow = new OnDemandFlow(stack, 'OnDemandFlow', { }); ``` -## EventBridge notifications +## Monitoring + + +### Metrcis + +Each flow reports the following metrics in the `AWS/AppFlow` namespace: + +|Metric name|Description| +|---|---| +|FlowExecutionsStarted|The number of flow runs started.| +|FlowExecutionsFailed|The number of failed flow runs.| +|FlowExecutionsSucceeded|The number of successful flow runs.| +|FlowExecutionTime|The interval, in milliseconds, between the time the flow starts and the time it finishes.| +|FlowExecutionRecordsProcessed|The number of records that Amazon AppFlow attempted to transfer for the flow run. This metric counts all records that Amazon AppFlow processed internally. The processed records include those that transferred successfully and those that failed to transfer because the flow run failed.| + + +It can be consume by CloudWatch alert using as in the example below: + + +```ts +import { IFlow } from '@cdklabs/cdk-appflow'; +import { Stack } from 'aws-cdk-lib'; + +declare const flow: IFlow; +declare const stack: Stack; + +const metric = flow.metricFlowExecutionsStarted() +metric.createAlarm(stack, "FlowExecutionsStartedAlarm", { + threshold: 1000, + evaluationPeriods: 2 +}) +``` + + +### EventBridge notifications Each flow publishes events to the default EventBridge bus: diff --git a/src/core/flows/flow-base.ts b/src/core/flows/flow-base.ts index 254300cd..856da82c 100644 --- a/src/core/flows/flow-base.ts +++ b/src/core/flows/flow-base.ts @@ -36,10 +36,35 @@ export interface IFlow extends IResource { onRunCompleted(id: string, options?: OnEventOptions): Rule; + + /** + * Creates a metric to report the number of flow runs started. + * @param options + */ metricFlowExecutionsStarted(options?: MetricOptions): Metric; + + /** + * Creates a metric to report the number of failed flow runs. + * @param options + */ metricFlowExecutionsFailed(options?: MetricOptions): Metric; + + /** + * Creates a metric to report the number of successful flow runs. + * @param options + */ metricFlowExecutionsSucceeded(options?: MetricOptions): Metric; + + /** + * Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. + * @param options + */ metricFlowExecutionTime(options?: MetricOptions): Metric; + + /** + * Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. + * @param options + */ metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric; /** From 5f3b360579cc6b4a4a856b40814bacf7a100b8c8 Mon Sep 17 00:00:00 2001 From: kozub Date: Thu, 4 Jan 2024 13:36:38 +0100 Subject: [PATCH 3/4] doc: update metrics describtion --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 23db5a71..07872ad0 100644 --- a/README.md +++ b/README.md @@ -154,16 +154,15 @@ const flow = new OnDemandFlow(stack, 'OnDemandFlow', { ### Metrcis -Each flow reports the following metrics in the `AWS/AppFlow` namespace: +Each flow allows to access metrics through the methods: +- `metricFlowExecutionsStarted` +- `metricFlowExecutionsFailed` +- `metricFlowExecutionsSucceeded` +- `metricFlowExecutionTime` +- `metricFlowExecutionRecordsProcessed` -|Metric name|Description| -|---|---| -|FlowExecutionsStarted|The number of flow runs started.| -|FlowExecutionsFailed|The number of failed flow runs.| -|FlowExecutionsSucceeded|The number of successful flow runs.| -|FlowExecutionTime|The interval, in milliseconds, between the time the flow starts and the time it finishes.| -|FlowExecutionRecordsProcessed|The number of records that Amazon AppFlow attempted to transfer for the flow run. This metric counts all records that Amazon AppFlow processed internally. The processed records include those that transferred successfully and those that failed to transfer because the flow run failed.| +For detailed information about AppFlow metrics refer to [the documentation](https://docs.aws.amazon.com/appflow/latest/userguide/monitoring-cloudwatch.html). It can be consume by CloudWatch alert using as in the example below: @@ -175,11 +174,12 @@ import { Stack } from 'aws-cdk-lib'; declare const flow: IFlow; declare const stack: Stack; -const metric = flow.metricFlowExecutionsStarted() +const metric = flow.metricFlowExecutionsStarted(); + metric.createAlarm(stack, "FlowExecutionsStartedAlarm", { threshold: 1000, evaluationPeriods: 2 -}) +}); ``` From 49375f226d58873c7ea5e5df0d8d992aad9b18bb Mon Sep 17 00:00:00 2001 From: kozub Date: Thu, 4 Jan 2024 14:25:44 +0100 Subject: [PATCH 4/4] chore: fix estint --- API.md | 155 ++++++++++++++++++++++++++++-------- README.md | 1 - src/core/flows/flow-base.ts | 10 +-- 3 files changed, 129 insertions(+), 37 deletions(-) diff --git a/API.md b/API.md index 106fbade..5e13b823 100644 --- a/API.md +++ b/API.md @@ -149,7 +149,40 @@ const flow = new OnDemandFlow(stack, 'OnDemandFlow', { }); ``` -## EventBridge notifications +## Monitoring + + +### Metrcis + +Each flow allows to access metrics through the methods: +- `metricFlowExecutionsStarted` +- `metricFlowExecutionsFailed` +- `metricFlowExecutionsSucceeded` +- `metricFlowExecutionTime` +- `metricFlowExecutionRecordsProcessed` + + +For detailed information about AppFlow metrics refer to [the documentation](https://docs.aws.amazon.com/appflow/latest/userguide/monitoring-cloudwatch.html). + +It can be consume by CloudWatch alert using as in the example below: + + +```ts +import { IFlow } from '@cdklabs/cdk-appflow'; + +declare const flow: IFlow; +declare const stack: Stack; + +const metric = flow.metricFlowExecutionsStarted(); + +metric.createAlarm(stack, "FlowExecutionsStartedAlarm", { + threshold: 1000, + evaluationPeriods: 2 +}); +``` + + +### EventBridge notifications Each flow publishes events to the default EventBridge bus: @@ -802,11 +835,11 @@ new FlowBase(scope: Construct, id: string, props: FlowBaseProps) | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | | metric | *No description.* | -| metricFlowExecutionRecordsProcessed | *No description.* | -| metricFlowExecutionsFailed | *No description.* | -| metricFlowExecutionsStarted | *No description.* | -| metricFlowExecutionsSucceeded | *No description.* | -| metricFlowExecutionTime | *No description.* | +| metricFlowExecutionRecordsProcessed | Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. | +| metricFlowExecutionsFailed | Creates a metric to report the number of failed flow runs. | +| metricFlowExecutionsStarted | Creates a metric to report the number of flow runs started. | +| metricFlowExecutionsSucceeded | Creates a metric to report the number of successful flow runs. | +| metricFlowExecutionTime | Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -867,6 +900,8 @@ public metric(metricName: string, options?: MetricOptions): Metric public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -879,6 +914,8 @@ public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric public metricFlowExecutionsFailed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of failed flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -891,6 +928,8 @@ public metricFlowExecutionsFailed(options?: MetricOptions): Metric public metricFlowExecutionsStarted(options?: MetricOptions): Metric ``` +Creates a metric to report the number of flow runs started. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -903,6 +942,8 @@ public metricFlowExecutionsStarted(options?: MetricOptions): Metric public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric ``` +Creates a metric to report the number of successful flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -915,6 +956,8 @@ public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric public metricFlowExecutionTime(options?: MetricOptions): Metric ``` +Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -2585,11 +2628,11 @@ new OnDemandFlow(scope: Construct, id: string, props: OnDemandFlowProps) | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | | metric | *No description.* | -| metricFlowExecutionRecordsProcessed | *No description.* | -| metricFlowExecutionsFailed | *No description.* | -| metricFlowExecutionsStarted | *No description.* | -| metricFlowExecutionsSucceeded | *No description.* | -| metricFlowExecutionTime | *No description.* | +| metricFlowExecutionRecordsProcessed | Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. | +| metricFlowExecutionsFailed | Creates a metric to report the number of failed flow runs. | +| metricFlowExecutionsStarted | Creates a metric to report the number of flow runs started. | +| metricFlowExecutionsSucceeded | Creates a metric to report the number of successful flow runs. | +| metricFlowExecutionTime | Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -2650,6 +2693,8 @@ public metric(metricName: string, options?: MetricOptions): Metric public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -2662,6 +2707,8 @@ public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric public metricFlowExecutionsFailed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of failed flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -2674,6 +2721,8 @@ public metricFlowExecutionsFailed(options?: MetricOptions): Metric public metricFlowExecutionsStarted(options?: MetricOptions): Metric ``` +Creates a metric to report the number of flow runs started. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -2686,6 +2735,8 @@ public metricFlowExecutionsStarted(options?: MetricOptions): Metric public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric ``` +Creates a metric to report the number of successful flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -2698,6 +2749,8 @@ public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric public metricFlowExecutionTime(options?: MetricOptions): Metric ``` +Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -2956,11 +3009,11 @@ new OnEventFlow(scope: Construct, id: string, props: OnEventFlowProps) | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | | metric | *No description.* | -| metricFlowExecutionRecordsProcessed | *No description.* | -| metricFlowExecutionsFailed | *No description.* | -| metricFlowExecutionsStarted | *No description.* | -| metricFlowExecutionsSucceeded | *No description.* | -| metricFlowExecutionTime | *No description.* | +| metricFlowExecutionRecordsProcessed | Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. | +| metricFlowExecutionsFailed | Creates a metric to report the number of failed flow runs. | +| metricFlowExecutionsStarted | Creates a metric to report the number of flow runs started. | +| metricFlowExecutionsSucceeded | Creates a metric to report the number of successful flow runs. | +| metricFlowExecutionTime | Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -3023,6 +3076,8 @@ public metric(metricName: string, options?: MetricOptions): Metric public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3035,6 +3090,8 @@ public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric public metricFlowExecutionsFailed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of failed flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3047,6 +3104,8 @@ public metricFlowExecutionsFailed(options?: MetricOptions): Metric public metricFlowExecutionsStarted(options?: MetricOptions): Metric ``` +Creates a metric to report the number of flow runs started. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3059,6 +3118,8 @@ public metricFlowExecutionsStarted(options?: MetricOptions): Metric public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric ``` +Creates a metric to report the number of successful flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3071,6 +3132,8 @@ public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric public metricFlowExecutionTime(options?: MetricOptions): Metric ``` +Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3365,11 +3428,11 @@ new OnScheduleFlow(scope: Construct, id: string, props: OnScheduleFlowProps) | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | | metric | *No description.* | -| metricFlowExecutionRecordsProcessed | *No description.* | -| metricFlowExecutionsFailed | *No description.* | -| metricFlowExecutionsStarted | *No description.* | -| metricFlowExecutionsSucceeded | *No description.* | -| metricFlowExecutionTime | *No description.* | +| metricFlowExecutionRecordsProcessed | Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. | +| metricFlowExecutionsFailed | Creates a metric to report the number of failed flow runs. | +| metricFlowExecutionsStarted | Creates a metric to report the number of flow runs started. | +| metricFlowExecutionsSucceeded | Creates a metric to report the number of successful flow runs. | +| metricFlowExecutionTime | Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -3431,6 +3494,8 @@ public metric(metricName: string, options?: MetricOptions): Metric public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3443,6 +3508,8 @@ public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric public metricFlowExecutionsFailed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of failed flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3455,6 +3522,8 @@ public metricFlowExecutionsFailed(options?: MetricOptions): Metric public metricFlowExecutionsStarted(options?: MetricOptions): Metric ``` +Creates a metric to report the number of flow runs started. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3467,6 +3536,8 @@ public metricFlowExecutionsStarted(options?: MetricOptions): Metric public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric ``` +Creates a metric to report the number of successful flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -3479,6 +3550,8 @@ public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric public metricFlowExecutionTime(options?: MetricOptions): Metric ``` +Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -5704,11 +5777,11 @@ new TriggeredFlowBase(scope: Construct, id: string, props: FlowBaseProps) | toString | Returns a string representation of this construct. | | applyRemovalPolicy | Apply the given removal policy to this resource. | | metric | *No description.* | -| metricFlowExecutionRecordsProcessed | *No description.* | -| metricFlowExecutionsFailed | *No description.* | -| metricFlowExecutionsStarted | *No description.* | -| metricFlowExecutionsSucceeded | *No description.* | -| metricFlowExecutionTime | *No description.* | +| metricFlowExecutionRecordsProcessed | Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. | +| metricFlowExecutionsFailed | Creates a metric to report the number of failed flow runs. | +| metricFlowExecutionsStarted | Creates a metric to report the number of flow runs started. | +| metricFlowExecutionsSucceeded | Creates a metric to report the number of successful flow runs. | +| metricFlowExecutionTime | Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. | | onEvent | *No description.* | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -5770,6 +5843,8 @@ public metric(metricName: string, options?: MetricOptions): Metric public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -5782,6 +5857,8 @@ public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric public metricFlowExecutionsFailed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of failed flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -5794,6 +5871,8 @@ public metricFlowExecutionsFailed(options?: MetricOptions): Metric public metricFlowExecutionsStarted(options?: MetricOptions): Metric ``` +Creates a metric to report the number of flow runs started. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -5806,6 +5885,8 @@ public metricFlowExecutionsStarted(options?: MetricOptions): Metric public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric ``` +Creates a metric to report the number of successful flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -5818,6 +5899,8 @@ public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric public metricFlowExecutionTime(options?: MetricOptions): Metric ``` +Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -15228,11 +15311,11 @@ A representation of a mapping operation, that is an operation filtering records | **Name** | **Description** | | --- | --- | -| metricFlowExecutionRecordsProcessed | *No description.* | -| metricFlowExecutionsFailed | *No description.* | -| metricFlowExecutionsStarted | *No description.* | -| metricFlowExecutionsSucceeded | *No description.* | -| metricFlowExecutionTime | *No description.* | +| metricFlowExecutionRecordsProcessed | Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. | +| metricFlowExecutionsFailed | Creates a metric to report the number of failed flow runs. | +| metricFlowExecutionsStarted | Creates a metric to report the number of flow runs started. | +| metricFlowExecutionsSucceeded | Creates a metric to report the number of successful flow runs. | +| metricFlowExecutionTime | Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. | | onRunCompleted | *No description.* | | onRunStarted | *No description.* | @@ -15244,6 +15327,8 @@ A representation of a mapping operation, that is an operation filtering records public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -15256,6 +15341,8 @@ public metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric public metricFlowExecutionsFailed(options?: MetricOptions): Metric ``` +Creates a metric to report the number of failed flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -15268,6 +15355,8 @@ public metricFlowExecutionsFailed(options?: MetricOptions): Metric public metricFlowExecutionsStarted(options?: MetricOptions): Metric ``` +Creates a metric to report the number of flow runs started. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -15280,6 +15369,8 @@ public metricFlowExecutionsStarted(options?: MetricOptions): Metric public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric ``` +Creates a metric to report the number of successful flow runs. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions @@ -15292,6 +15383,8 @@ public metricFlowExecutionsSucceeded(options?: MetricOptions): Metric public metricFlowExecutionTime(options?: MetricOptions): Metric ``` +Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. + ###### `options`Optional - *Type:* aws-cdk-lib.aws_cloudwatch.MetricOptions diff --git a/README.md b/README.md index 07872ad0..d0f05a6e 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,6 @@ It can be consume by CloudWatch alert using as in the example below: ```ts import { IFlow } from '@cdklabs/cdk-appflow'; -import { Stack } from 'aws-cdk-lib'; declare const flow: IFlow; declare const stack: Stack; diff --git a/src/core/flows/flow-base.ts b/src/core/flows/flow-base.ts index 856da82c..5837afa4 100644 --- a/src/core/flows/flow-base.ts +++ b/src/core/flows/flow-base.ts @@ -39,31 +39,31 @@ export interface IFlow extends IResource { /** * Creates a metric to report the number of flow runs started. - * @param options + * @param options */ metricFlowExecutionsStarted(options?: MetricOptions): Metric; /** * Creates a metric to report the number of failed flow runs. - * @param options + * @param options */ metricFlowExecutionsFailed(options?: MetricOptions): Metric; /** * Creates a metric to report the number of successful flow runs. - * @param options + * @param options */ metricFlowExecutionsSucceeded(options?: MetricOptions): Metric; /** * Creates a metric to report the interval, in milliseconds, between the time the flow starts and the time it finishes. - * @param options + * @param options */ metricFlowExecutionTime(options?: MetricOptions): Metric; /** * Creates a metric to report the number of records that Amazon AppFlow attempted to transfer for the flow run. - * @param options + * @param options */ metricFlowExecutionRecordsProcessed(options?: MetricOptions): Metric;