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(scheduler): metrics for all schedules #27544

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/@aws-cdk/aws-scheduler-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,16 @@ EventBridge Scheduler publishes additional metrics when your schedule exhausts i

### Metrics for all schedules

TODO: Not yet implemented. See section in [L2 Event Bridge Scheduler RFC](https://github.com/aws/aws-cdk-rfcs/blob/master/text/0474-event-bridge-scheduler-l2.md)
Class `Schedule` provides static methods for accessing all schedules metrics with default configuration,
such as `metricAllErrors` for viewing errors when executing targets.

```ts
new cloudwatch.Alarm(this, 'SchedulesErrorAlarm', {
metric: Schedule.metricAllErrors(),
threshold: 0,
evaluationPeriods: 1
kaizencc marked this conversation as resolved.
Show resolved Hide resolved
});
```

### Metrics for a Group

Expand Down
94 changes: 94 additions & 0 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IResource, Resource } from 'aws-cdk-lib';
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
import { CfnSchedule } from 'aws-cdk-lib/aws-scheduler';
import { Construct } from 'constructs';
import { IGroup } from './group';
Expand Down Expand Up @@ -72,6 +73,99 @@ export interface ScheduleProps {
* An EventBridge Schedule
*/
export class Schedule extends Resource implements ISchedule {
/**
* Return the given named metric for all schedules.
*
* @default - sum over 5 minutes
*/
public static metricAll(metricName: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return new cloudwatch.Metric({
namespace: 'AWS/Scheduler',
metricName,
statistic: 'sum',
...props,
});
}

/**
* Metric for the number of invocations that were throttled across all schedules.
*
* @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/scheduler-quotas.html
*
* @default - sum over 5 minutes
*/
public static metricAllThrottled(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('InvocationThrottleCount', props);
}

/**
* Metric for all invocation attempts across all schedules.
*
* @default - sum over 5 minutes
*/
public static metricAllAttempts(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('InvocationAttemptCount', props);
}
/**
* Emitted when the target returns an exception after EventBridge Scheduler calls the target API across all schedules.
*
* @default - sum over 5 minutes
*/
public static metricAllErrors(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('TargetErrorCount', props);
}

/**
* Metric for invocation failures due to API throttling by the target across all schedules.
*
* @default - sum over 5 minutes
*/
public static metricAllTargetThrottled(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('TargetErrorThrottledCount', props);
}

/**
* Metric for dropped invocations when EventBridge Scheduler stops attempting to invoke the target after a schedule's retry policy has been exhausted.
* Metric is calculated for all schedules.
*
* @default - sum over 5 minutes
*/
public static metricAllDropped(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('InvocationDroppedCount', props);
}

/**
* Metric for invocations delivered to the DLQ across all schedules.
*
* @default - sum over 5 minutes
*/
public static metricAllSentToDLQ(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('InvocationsSentToDeadLetterCount', props);
}

/**
* Metric for failed invocations that also failed to deliver to DLQ across all schedules.
*
* @default - sum over 5 minutes
*/
public static metricAllFailedToBeSentToDLQ(errorCode?: string, props?: cloudwatch.MetricOptions): cloudwatch.Metric {
if (!errorCode) {
return this.metricAll(`InvocationsFailedToBeSentToDeadLetterCount_${errorCode}`, props);
}

return this.metricAll('InvocationsFailedToBeSentToDeadLetterCount', props);
}

/**
* Metric for delivery of failed invocations to DLQ when the payload of the event sent to the DLQ exceeds the maximum size allowed by Amazon SQS.
* Metric is calculated for all schedules.
*
* @default - sum over 5 minutes
*/
public static metricAllSentToDLQTrunacted(props?: cloudwatch.MetricOptions): cloudwatch.Metric {
return this.metricAll('InvocationsSentToDeadLetterCount_Truncated_MessageSizeExceeded', props);
}

/**
* The schedule group associated with this schedule.
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@
}
}
}
},
"AllSchedulerErrorsAlarmA3246F8C": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
"EvaluationPeriods": 1,
"MetricName": "TargetErrorCount",
"Namespace": "AWS/Scheduler",
"Period": 300,
"Statistic": "Sum",
"Threshold": 1
}
}
},
"Parameters": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-scheduler-alpha/test/integ.schedule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import * as cdk from 'aws-cdk-lib';
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as scheduler from '../lib';
Expand Down Expand Up @@ -42,6 +43,12 @@ new scheduler.Schedule(stack, 'DisabledSchedule', {
enabled: false,
});

new cloudwatch.Alarm(stack, 'AllSchedulerErrorsAlarm', {
metric: scheduler.Schedule.metricAllErrors(),
threshold: 1,
evaluationPeriods: 1,
});

new IntegTest(app, 'integtest-schedule', {
testCases: [stack],
});