diff --git a/API.md b/API.md index 7665512f8..af726273b 100644 --- a/API.md +++ b/API.md @@ -94,6 +94,7 @@ Any object. | highSeverityAlarms | aws-cdk-lib.aws_cloudwatch.IAlarm[] | Returns a list of all high-severity alarms from this ConstructHub instance. | | ingestionQueue | aws-cdk-lib.aws_sqs.IQueue | *No description.* | | lowSeverityAlarms | aws-cdk-lib.aws_cloudwatch.IAlarm[] | Returns a list of all low-severity alarms from this ConstructHub instance. | +| mediumSeverityAlarms | aws-cdk-lib.aws_cloudwatch.IAlarm[] | Returns a list of all low-severity alarms from this ConstructHub instance. | | regenerateAllDocumentationPerPackage | aws-cdk-lib.aws_stepfunctions.IStateMachine | The function operators can use to reprocess a specific package version through the backend data pipeline. | --- @@ -175,6 +176,22 @@ that something unusual (not necessarily bad) is happening. --- +##### `mediumSeverityAlarms`Required + +```typescript +public readonly mediumSeverityAlarms: IAlarm[]; +``` + +- *Type:* aws-cdk-lib.aws_cloudwatch.IAlarm[] + +Returns a list of all low-severity alarms from this ConstructHub instance. + +These do not necessitate immediate attention, as they do not have direct +customer-visible impact, or handling is not time-sensitive. They indicate +that something unusual (not necessarily bad) is happening. + +--- + ##### `regenerateAllDocumentationPerPackage`Required ```typescript @@ -327,6 +344,8 @@ const alarmActions: AlarmActions = { ... } | --- | --- | --- | | highSeverity | string | The ARN of the CloudWatch alarm action to take for alarms of high-severity alarms. | | highSeverityAction | aws-cdk-lib.aws_cloudwatch.IAlarmAction | The CloudWatch alarm action to take for alarms of high-severity alarms. | +| mediumSeverity | string | The ARN of the CloudWatch alarm action to take for alarms of medium-severity alarms. | +| mediumSeverityAction | aws-cdk-lib.aws_cloudwatch.IAlarmAction | The CloudWatch alarm action to take for alarms of medium-severity alarms. | | normalSeverity | string | The ARN of the CloudWatch alarm action to take for alarms of normal severity. | | normalSeverityAction | aws-cdk-lib.aws_cloudwatch.IAlarmAction | The CloudWatch alarm action to take for alarms of normal severity. | @@ -364,6 +383,38 @@ This must be an ARN that can be used with CloudWatch alarms. --- +##### `mediumSeverity`Optional + +```typescript +public readonly mediumSeverity: string; +``` + +- *Type:* string + +The ARN of the CloudWatch alarm action to take for alarms of medium-severity alarms. + +This must be an ARN that can be used with CloudWatch alarms. + +> [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions) + +--- + +##### `mediumSeverityAction`Optional + +```typescript +public readonly mediumSeverityAction: IAlarmAction; +``` + +- *Type:* aws-cdk-lib.aws_cloudwatch.IAlarmAction + +The CloudWatch alarm action to take for alarms of medium-severity alarms. + +This must be an ARN that can be used with CloudWatch alarms. + +> [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions) + +--- + ##### `normalSeverity`Optional ```typescript @@ -13679,6 +13730,7 @@ ConstructHub monitoring features exposed to extension points. | --- | --- | | addHighSeverityAlarm | Adds a high-severity alarm. | | addLowSeverityAlarm | Adds a low-severity alarm. | +| addMediumSeverityAlarm | Adds a medium-severity alarm. | --- @@ -13736,6 +13788,33 @@ the alarm to be added. --- +##### `addMediumSeverityAlarm` + +```typescript +public addMediumSeverityAlarm(title: string, alarm: AlarmBase): void +``` + +Adds a medium-severity alarm. + +If this alarm goes off, the action specified in +`mediumSeverityAlarmAction` is triggered. + +###### `title`Required + +- *Type:* string + +a user-friendly title for the alarm (not currently used). + +--- + +###### `alarm`Required + +- *Type:* aws-cdk-lib.aws_cloudwatch.AlarmBase + +the alarm to be added. + +--- + ### IOverviewDashboard diff --git a/src/__tests__/monitoring.test.ts b/src/__tests__/monitoring.test.ts index 205cb2de0..ea355598b 100644 --- a/src/__tests__/monitoring.test.ts +++ b/src/__tests__/monitoring.test.ts @@ -108,10 +108,14 @@ test('monitoring exposes a list of high severity alarms', () => { const alarm2 = topic .metricSMSMonthToDateSpentUSD() .createAlarm(stack, 'Alarm2', { threshold: 100, evaluationPeriods: 1 }); + const alarm3 = topic + .metricSMSMonthToDateSpentUSD() + .createAlarm(stack, 'Alarm3', { threshold: 500, evaluationPeriods: 1 }); // WHEN monitoring.addHighSeverityAlarm('My Alarm', alarm1); monitoring.addLowSeverityAlarm('My Other Alarm', alarm2); + monitoring.addMediumSeverityAlarm('My Third Alarm', alarm3); expect(monitoring.highSeverityAlarms.map((alarm) => alarm.alarmArn)).toEqual([ alarm1.alarmArn, @@ -119,6 +123,9 @@ test('monitoring exposes a list of high severity alarms', () => { expect(monitoring.lowSeverityAlarms.map((alarm) => alarm.alarmArn)).toEqual([ alarm2.alarmArn, ]); + expect( + monitoring.mediumSeverityAlarms.map((alarm) => alarm.alarmArn) + ).toEqual([alarm3.alarmArn]); }); test('web canaries can ping URLs and raise high severity alarms', () => { @@ -230,3 +237,32 @@ test('high-severity alarm actions are registered', () => { AlarmActions: [highSeverity, highSeverityActionArn], }); }); + +test('medium-severity alarm actions are registered', () => { + // GIVEN + const stack = new Stack(undefined, 'TestStack'); + const alarm = new Alarm(stack, 'Alarm', { + evaluationPeriods: 1, + metric: new Metric({ + metricName: 'FakeMetricName', + namespace: 'FakeNamespace', + }), + threshold: 0, + }); + + const mediumSeverity = 'fake::arn::of::an::action'; + const mediumSeverityActionArn = 'fake::arn::of::bound:alarm::action'; + const mediumSeverityAction: IAlarmAction = { + bind: () => ({ alarmActionArn: mediumSeverityActionArn }), + }; + + // WHEN + new Monitoring(stack, 'Monitoring', { + alarmActions: { mediumSeverity, mediumSeverityAction }, + }).addMediumSeverityAlarm('Alarm', alarm); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::CloudWatch::Alarm', { + AlarmActions: [mediumSeverity, mediumSeverityActionArn], + }); +}); diff --git a/src/api.ts b/src/api.ts index 818a7bd17..3ae83fa8a 100644 --- a/src/api.ts +++ b/src/api.ts @@ -57,6 +57,23 @@ export interface AlarmActions { */ readonly highSeverityAction?: IAlarmAction; + /** + * The ARN of the CloudWatch alarm action to take for alarms of medium-severity + * alarms. + * + * This must be an ARN that can be used with CloudWatch alarms. + * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions + */ + readonly mediumSeverity?: string; + + /** + * The CloudWatch alarm action to take for alarms of medium-severity alarms. + * + * This must be an ARN that can be used with CloudWatch alarms. + * @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-actions + */ + readonly mediumSeverityAction?: IAlarmAction; + /** * The ARN of the CloudWatch alarm action to take for alarms of normal * severity. diff --git a/src/construct-hub.ts b/src/construct-hub.ts index 1e1a9567a..12d3ada09 100644 --- a/src/construct-hub.ts +++ b/src/construct-hub.ts @@ -350,13 +350,13 @@ export class ConstructHub extends Construct implements iam.IGrantable { // Create an internal CodeArtifact repository if we run in network-controlled mode, or if a domain is provided. const codeArtifact = isolation === Isolation.NO_INTERNET_ACCESS || - props.codeArtifactDomain != null + props.codeArtifactDomain != null ? new Repository(this, 'CodeArtifact', { - description: 'Proxy to npmjs.com for ConstructHub', - domainName: props.codeArtifactDomain?.name, - domainExists: props.codeArtifactDomain != null, - upstreams: props.codeArtifactDomain?.upstreams, - }) + description: 'Proxy to npmjs.com for ConstructHub', + domainName: props.codeArtifactDomain?.name, + domainExists: props.codeArtifactDomain != null, + upstreams: props.codeArtifactDomain?.upstreams, + }) : undefined; const { vpc, vpcEndpoints, vpcSubnets, vpcSecurityGroups } = this.createVpc( isolation, @@ -557,6 +557,17 @@ export class ConstructHub extends Construct implements iam.IGrantable { return this.monitoring.highSeverityAlarms; } + /** + * Returns a list of all low-severity alarms from this ConstructHub instance. + * These do not necessitate immediate attention, as they do not have direct + * customer-visible impact, or handling is not time-sensitive. They indicate + * that something unusual (not necessarily bad) is happening. + */ + public get mediumSeverityAlarms(): cw.IAlarm[] { + // Note: the array is already returned by-copy by Monitoring, so not copying again. + return this.monitoring.mediumSeverityAlarms; + } + /** * Returns a list of all low-severity alarms from this ConstructHub instance. * These do not necessitate immediate attention, as they do not have direct @@ -572,7 +583,7 @@ export class ConstructHub extends Construct implements iam.IGrantable { * Returns a list of all alarms configured by this ConstructHub instance. */ public get allAlarms(): cw.IAlarm[] { - return [...this.highSeverityAlarms, ...this.lowSeverityAlarms]; + return [...this.highSeverityAlarms, ...this.lowSeverityAlarms, ...this.mediumSeverityAlarms]; } public get grantPrincipal(): iam.IPrincipal { diff --git a/src/monitoring/api.ts b/src/monitoring/api.ts index 31d783143..da326224a 100644 --- a/src/monitoring/api.ts +++ b/src/monitoring/api.ts @@ -14,6 +14,15 @@ export interface IMonitoring { */ addHighSeverityAlarm(title: string, alarm: AlarmBase): void; + /** + * Adds a medium-severity alarm. If this alarm goes off, the action specified in + * `mediumSeverityAlarmAction` is triggered. + * + * @param title a user-friendly title for the alarm (not currently used). + * @param alarm the alarm to be added. + */ + addMediumSeverityAlarm(title: string, alarm: AlarmBase): void; + /** * Adds a low-severity alarm. If this alarm goes off, the action specified in * `normalAlarmAction` is triggered. diff --git a/src/monitoring/index.ts b/src/monitoring/index.ts index 9fe05744d..799df2edb 100644 --- a/src/monitoring/index.ts +++ b/src/monitoring/index.ts @@ -27,6 +27,7 @@ export interface MonitoringProps { export class Monitoring extends Construct implements IMonitoring { private alarmActions?: AlarmActions; private _highSeverityAlarms: cw.AlarmBase[]; + private _mediumSeverityAlarms: cw.AlarmBase[]; private _lowSeverityAlarms: cw.AlarmBase[]; /** @@ -55,6 +56,7 @@ export class Monitoring extends Construct implements IMonitoring { this._highSeverityAlarms = []; this._lowSeverityAlarms = []; + this._mediumSeverityAlarms = []; this.highSeverityDashboard = new cw.Dashboard( this, @@ -103,10 +105,28 @@ export class Monitoring extends Construct implements IMonitoring { this._lowSeverityAlarms.push(alarm); } + public addMediumSeverityAlarm(_title: string, alarm: cw.AlarmBase) { + const actionArn = this.alarmActions?.mediumSeverity; + if (actionArn) { + alarm.addAlarmAction({ + bind: () => ({ alarmActionArn: actionArn }), + }); + } + const action = this.alarmActions?.mediumSeverityAction; + if (action) { + alarm.addAlarmAction(action); + } + this._mediumSeverityAlarms.push(alarm); + } + public get highSeverityAlarms() { return [...this._highSeverityAlarms]; } + public get mediumSeverityAlarms() { + return [...this._mediumSeverityAlarms]; + } + public get lowSeverityAlarms() { return [...this._lowSeverityAlarms]; } diff --git a/test/integ.transliterator.ecstask.ts b/test/integ.transliterator.ecstask.ts index 8c747d8ad..4f021b6fb 100644 --- a/test/integ.transliterator.ecstask.ts +++ b/test/integ.transliterator.ecstask.ts @@ -24,6 +24,7 @@ const transliterator = new Transliterator(stack, 'Transliterator', { bucket, monitoring: { addHighSeverityAlarm: () => {}, + addMediumSeverityAlarm: () => {}, addLowSeverityAlarm: () => {}, }, });