Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions cdk/lib/__snapshots__/prism.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,20 @@ exports[`The PrismEc2App stack matches the snapshot 1`] = `
"EvaluationPeriods": 60,
"MetricName": "UnHealthyHostCount",
"Namespace": "AWS/ApplicationELB",
"OKActions": [
{
"Fn::Join": [
"",
[
"arn:aws:sns:eu-west-1:",
{
"Ref": "AWS::AccountId",
},
":devx-alerts",
],
],
},
],
"Period": 60,
"Statistic": "Maximum",
"Tags": [
Expand Down
26 changes: 24 additions & 2 deletions cdk/lib/prism.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AccessScope } from '@guardian/cdk/lib/constants';
import { GuUnhealthyInstancesAlarm } from '@guardian/cdk/lib/constructs/cloudwatch';
import {
GuDistributionBucketParameter,
GuPrivateConfigBucketParameter,
Expand All @@ -18,6 +19,7 @@ import {
BlockDeviceVolume,
EbsDeviceVolumeType,
} from 'aws-cdk-lib/aws-autoscaling';
import { SnsAction } from 'aws-cdk-lib/aws-cloudwatch-actions';
import {
InstanceClass,
InstanceSize,
Expand All @@ -26,6 +28,7 @@ import {
UserData,
} from 'aws-cdk-lib/aws-ec2';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import { Topic } from 'aws-cdk-lib/aws-sns';

interface PrismProps extends Omit<GuStackProps, 'description' | 'stack'> {
domainName: string;
Expand All @@ -51,7 +54,8 @@ export class Prism extends GuStack {
});

const { buildIdentifier, instanceMetricGranularity } = props;
const { stack, stage } = this;
const { stack, stage, region, account } = this;
const snsTopicName = 'devx-alerts';

const distBucket = Bucket.fromBucketName(
this,
Expand Down Expand Up @@ -98,7 +102,7 @@ export class Prism extends GuStack {
monitoringConfiguration:
this.stage === 'PROD'
? {
snsTopicName: 'devx-alerts',
snsTopicName,
http5xxAlarm: false,
unhealthyInstancesAlarm: true,
}
Expand Down Expand Up @@ -154,5 +158,23 @@ export class Prism extends GuStack {
const cfnAsg = pattern.autoScalingGroup.node
.defaultChild as CfnAutoScalingGroup;
cfnAsg.healthCheckGracePeriod = Duration.minutes(15).toSeconds();

// Configure OK action to receive a notification once alarm has resolved.
// TODO Set the OK action at the construct level within GuCDK
const maybeUnhealthyInstanceAlarm = this.node.children.filter(
(child): child is GuUnhealthyInstancesAlarm =>
child instanceof GuUnhealthyInstancesAlarm,
);
if (maybeUnhealthyInstanceAlarm.length > 0) {
const snsTopic = Topic.fromTopicArn(
this,
`SnsTopic`,
`arn:aws:sns:${region}:${account}:${snsTopicName}`,
);

maybeUnhealthyInstanceAlarm.forEach((alarm) => {
alarm.addOkAction(new SnsAction(snsTopic));
});
}
}
}