From 13ea7a73484b82f5a8cec3ab6d2183c6eaf7faef Mon Sep 17 00:00:00 2001 From: Craig McNicholas Date: Thu, 27 Jul 2023 00:14:30 +0100 Subject: [PATCH 1/4] fix: #348 topic display name too long --- src/constructs/aws/Queue.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/constructs/aws/Queue.ts b/src/constructs/aws/Queue.ts index 133e28db..e1dcdd39 100644 --- a/src/constructs/aws/Queue.ts +++ b/src/constructs/aws/Queue.ts @@ -232,9 +232,19 @@ export class Queue extends AwsConstruct { const alarmEmail = configuration.alarm; if (alarmEmail !== undefined) { + // generate the display name, AWS restriction is 100 chars + let displayName = `[Alert][${id}] failed jobs in dlq.`; + if (displayName.length > 100) { + // if the length is too long then try to pretty print + displayName = `[Alert][${id.substring( + 0, + id.length - (displayName.length - 100 - 3) + )}...] failed jobs in dlq.`; + } + const alarmTopic = new Topic(this, "AlarmTopic", { topicName: `${this.provider.stackName}-${id}-dlq-alarm-topic`, - displayName: `[Alert][${id}] There are failed jobs in the dead letter queue.`, + displayName, }); new Subscription(this, "AlarmTopicSubscription", { topic: alarmTopic, From 8c42e97214d1f666c620cf15de4c8c09e1c954d0 Mon Sep 17 00:00:00 2001 From: Craig McNicholas Date: Thu, 27 Jul 2023 00:24:16 +0100 Subject: [PATCH 2/4] fix: test --- test/unit/queues.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/queues.test.ts b/test/unit/queues.test.ts index 1ada3e5e..dbe7c125 100644 --- a/test/unit/queues.test.ts +++ b/test/unit/queues.test.ts @@ -418,7 +418,7 @@ describe("queues", () => { Properties: { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment TopicName: expect.stringMatching(/test-queues-\w+-dev-emails-dlq-alarm-topic/), - DisplayName: "[Alert][emails] There are failed jobs in the dead letter queue.", + DisplayName: "[Alert][emails] failed jobs in dlq.", }, }); expect(cfTemplate.Resources[computeLogicalId("emails", "AlarmTopicSubscription")]).toMatchObject({ From f2f787d9a10db91e84164c9c5908d4c28769c46e Mon Sep 17 00:00:00 2001 From: Craig McNicholas Date: Wed, 2 Aug 2023 22:17:49 +0100 Subject: [PATCH 3/4] chore: change requests to simplify shortening This will truncate the entire message --- src/constructs/aws/Queue.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/constructs/aws/Queue.ts b/src/constructs/aws/Queue.ts index e1dcdd39..87d9d128 100644 --- a/src/constructs/aws/Queue.ts +++ b/src/constructs/aws/Queue.ts @@ -233,14 +233,7 @@ export class Queue extends AwsConstruct { const alarmEmail = configuration.alarm; if (alarmEmail !== undefined) { // generate the display name, AWS restriction is 100 chars - let displayName = `[Alert][${id}] failed jobs in dlq.`; - if (displayName.length > 100) { - // if the length is too long then try to pretty print - displayName = `[Alert][${id.substring( - 0, - id.length - (displayName.length - 100 - 3) - )}...] failed jobs in dlq.`; - } + const displayName = `[Alert][${id}] failed jobs in dlq.`.substring(0, 100); const alarmTopic = new Topic(this, "AlarmTopic", { topicName: `${this.provider.stackName}-${id}-dlq-alarm-topic`, From 8c8b7a2676ed18f3575edce71962c4085f1e212a Mon Sep 17 00:00:00 2001 From: Craig McNicholas Date: Wed, 2 Aug 2023 22:30:11 +0100 Subject: [PATCH 4/4] chore: updated message for CR's --- src/constructs/aws/Queue.ts | 2 +- test/unit/queues.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constructs/aws/Queue.ts b/src/constructs/aws/Queue.ts index 87d9d128..9e89c141 100644 --- a/src/constructs/aws/Queue.ts +++ b/src/constructs/aws/Queue.ts @@ -233,7 +233,7 @@ export class Queue extends AwsConstruct { const alarmEmail = configuration.alarm; if (alarmEmail !== undefined) { // generate the display name, AWS restriction is 100 chars - const displayName = `[Alert][${id}] failed jobs in dlq.`.substring(0, 100); + const displayName = `[Alert][${id}] failed jobs in the DLQ.`.substring(0, 100); const alarmTopic = new Topic(this, "AlarmTopic", { topicName: `${this.provider.stackName}-${id}-dlq-alarm-topic`, diff --git a/test/unit/queues.test.ts b/test/unit/queues.test.ts index dbe7c125..a7239d3b 100644 --- a/test/unit/queues.test.ts +++ b/test/unit/queues.test.ts @@ -418,7 +418,7 @@ describe("queues", () => { Properties: { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment TopicName: expect.stringMatching(/test-queues-\w+-dev-emails-dlq-alarm-topic/), - DisplayName: "[Alert][emails] failed jobs in dlq.", + DisplayName: "[Alert][emails] failed jobs in the DLQ.", }, }); expect(cfTemplate.Resources[computeLogicalId("emails", "AlarmTopicSubscription")]).toMatchObject({