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

Reconfigure notification sender worker alarms #1181

Merged
merged 4 commits into from
Nov 13, 2023
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`The MobileAppsRendering stack matches the snapshot 1`] = `
exports[`The Sender Worker stack matches the snapshot 1`] = `
Object {
Comment on lines -3 to 4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong test name! Probably a copy/paste job.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

"Metadata": Object {
"gu:cdk:constructs": Array [],
Expand Down Expand Up @@ -512,7 +512,7 @@ Object {
},
"androidSenderTooFewInvocationsAlarmC306ECD5": Object {
"Properties": Object {
"ActionsEnabled": false,
"ActionsEnabled": true,
"AlarmActions": Array [
Object {
"Ref": "AlarmTopicArn",
Expand All @@ -536,7 +536,7 @@ Object {
"Ref": "AlarmTopicArn",
},
],
"Period": 360,
"Period": 3600,
"Statistic": "Sum",
"Threshold": 0,
"TreatMissingData": "breaching",
Expand Down Expand Up @@ -982,7 +982,7 @@ Object {
},
"androidbetaSenderTooFewInvocationsAlarm7B50CD4B": Object {
"Properties": Object {
"ActionsEnabled": false,
"ActionsEnabled": true,
"AlarmActions": Array [
Object {
"Ref": "AlarmTopicArn",
Expand All @@ -1006,7 +1006,7 @@ Object {
"Ref": "AlarmTopicArn",
},
],
"Period": 360,
"Period": 3600,
"Statistic": "Sum",
"Threshold": 0,
"TreatMissingData": "breaching",
Expand Down Expand Up @@ -1452,7 +1452,7 @@ Object {
},
"androideditionSenderTooFewInvocationsAlarmE4AB00FB": Object {
"Properties": Object {
"ActionsEnabled": false,
"ActionsEnabled": true,
"AlarmActions": Array [
Object {
"Ref": "AlarmTopicArn",
Expand All @@ -1476,7 +1476,7 @@ Object {
"Ref": "AlarmTopicArn",
},
],
"Period": 360,
"Period": 86400,
"Statistic": "Sum",
"Threshold": 0,
"TreatMissingData": "breaching",
Expand Down Expand Up @@ -1922,7 +1922,7 @@ Object {
},
"iosSenderTooFewInvocationsAlarm14117FE9": Object {
"Properties": Object {
"ActionsEnabled": false,
"ActionsEnabled": true,
"AlarmActions": Array [
Object {
"Ref": "AlarmTopicArn",
Expand All @@ -1946,7 +1946,7 @@ Object {
"Ref": "AlarmTopicArn",
},
],
"Period": 360,
"Period": 3600,
"Statistic": "Sum",
"Threshold": 0,
"TreatMissingData": "breaching",
Expand Down Expand Up @@ -2392,7 +2392,7 @@ Object {
},
"ioseditionSenderTooFewInvocationsAlarmD32BB28C": Object {
"Properties": Object {
"ActionsEnabled": false,
"ActionsEnabled": true,
"AlarmActions": Array [
Object {
"Ref": "AlarmTopicArn",
Expand All @@ -2416,7 +2416,7 @@ Object {
"Ref": "AlarmTopicArn",
},
],
"Period": 360,
"Period": 86400,
"Statistic": "Sum",
"Threshold": 0,
"TreatMissingData": "breaching",
Expand Down
2 changes: 1 addition & 1 deletion notificationworkerlambda/cdk/lib/senderworker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Template } from "aws-cdk-lib/assertions";
import { App } from "aws-cdk-lib"
import {SenderWorkerStack} from "./senderworker";

describe('The MobileAppsRendering stack', () => {
describe('The Sender Worker stack', () => {
it('matches the snapshot', () => {
const app = new App();
const stack = new SenderWorkerStack(app, 'SenderWorkerStack', {
Expand Down
17 changes: 11 additions & 6 deletions notificationworkerlambda/cdk/lib/senderworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface SenderWorkerOpts {
platform: string,
paramPrefix: string,
isBatchingSqsMessages: boolean,
dailyAlarmPeriod: boolean
}

class SenderWorker extends cdkcore.Construct {
Expand Down Expand Up @@ -152,9 +153,10 @@ class SenderWorker extends cdkcore.Construct {
comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_OR_EQUAL_TO_THRESHOLD,
evaluationPeriods: 1,
threshold: 0,
metric: senderLambdaCtr.metricInvocations({period: cdk.Duration.seconds(360), statistic: "Sum"}),
// whole day for editions, 60 minutes for others
metric: senderLambdaCtr.metricInvocations({period: cdk.Duration.seconds(props.dailyAlarmPeriod ? 60 * 60 * 24 : 60 * 60), statistic: "Sum"}),
treatMissingData: cloudwatch.TreatMissingData.BREACHING,
actionsEnabled: false // isEnabled
actionsEnabled: true // isEnabled
})
senderTooFewInvocationsAlarm.addAlarmAction(snsTopicAction)
senderTooFewInvocationsAlarm.addOkAction(snsTopicAction)
Expand Down Expand Up @@ -217,14 +219,15 @@ export class SenderWorkerStack extends GuStack {

let workerQueueArns: string[] = []

const addWorker = (workerName: string, paramPrefix: string, handler: string, isBatchingSqsMessages: boolean = false) => {
const addWorker = (workerName: string, paramPrefix: string, handler: string, isBatchingSqsMessages: boolean = false, dailyAlarmPeriod: boolean = false) => {
let worker = new SenderWorker(this, workerName, {
...props,
platform: workerName,
paramPrefix: paramPrefix,
handler: handler,
isBatchingSqsMessages,
...sharedOpts
...sharedOpts,
dailyAlarmPeriod: dailyAlarmPeriod
})
workerQueueArns.push(worker.senderSqs.queueArn)
}
Expand All @@ -236,8 +239,10 @@ export class SenderWorkerStack extends GuStack {

addWorker("ios", "iosLive", "com.gu.notifications.worker.IOSSender::handleChunkTokens")
addWorker("android", "androidLive", "com.gu.notifications.worker.AndroidSender::handleChunkTokens", true)
addWorker("ios-edition", "iosEdition", "com.gu.notifications.worker.IOSSender::handleChunkTokens")
addWorker("android-edition", "androidEdition", "com.gu.notifications.worker.AndroidSender::handleChunkTokens")
// edition apps only send one notification a day in order to get content for that day
addWorker("ios-edition", "iosEdition", "com.gu.notifications.worker.IOSSender::handleChunkTokens", false, true)
addWorker("android-edition", "androidEdition", "com.gu.notifications.worker.AndroidSender::handleChunkTokens", false, true)

addWorker("android-beta", "androidBeta", "com.gu.notifications.worker.AndroidSender::handleChunkTokens")

/*
Expand Down