Skip to content

fix(0288): length-check every stack's alarm descriptions at synth - #435

Merged
karczuRF merged 2 commits into
developfrom
chore/0288_alarm-description-length-guard-covers-every-stack
Nov 30, 2026
Merged

karczuRF merged 2 commits into
developfrom
chore/0288_alarm-description-length-guard-covers-every-stack

Conversation

@karczuRF

Copy link
Copy Markdown
Collaborator

Summary

  • The 1024-character AlarmDescription guard walked only ObservabilityStack, so EventBridgeStack's ten -errors alarms (createWorkerLambda) could pass synth and fail in CloudFormation mid-deploy.
  • The guard moves to infra/src/lib/alarm-guards.ts (same check, same message) and runs once over the whole App in createApp, before app.synth(). Every stack is covered, including ones added later.
  • Negative test: an asset-discovery description pushed to 1491 chars fails synth with prices-production-asset-discovery-errors — 1491 chars; the same edit on develop synthesizes without complaint.
  • All five production templates are byte-identical. CDK nx test and infra:verify-dashboard pass.

Task: lore 0288.

The 1024-character AlarmDescription guard walked only ObservabilityStack, so EventBridgeStack's ten -errors alarms (createWorkerLambda) could pass synth and fail mid-deploy. The guard moves to alarm-guards.ts and runs once over the whole App in createApp, before app.synth(). Templates unchanged.

@stkrolikiewicz stkrolikiewicz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Read the whole diff. Correct for today's tree: the walk over the App reaches every stack and runs before app.synth(). Three non-blocking comments inline; the first is about the moved code, not something this PR introduced.

Comment thread infra/src/lib/alarm-guards.ts Outdated
const description = cdk.Stack.of(alarm).resolve(
cfn.alarmDescription,
) as unknown;
const length = typeof description === 'string' ? description.length : 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking): not new in this PR, but the doc comment above (L22) now promises more than this does. A description with a token resolves to an { 'Fn::Join': … } object, typeof isn't 'string', and the length counts as 0, so it always passes. Every description is a plain string today. Either measure the joined literal parts (an upper bound) or throw on a non-string, or reword the comment.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, confirmed: a 1025-char Fn.join description passed as length 0. The guard now throws on any description that does not resolve to a plain string, naming the alarm, and the doc comment says so instead of promising a measurement. Production synth with it: 90 alarms, all plain strings, longest 1018. 1a7a63b

Comment thread infra/src/lib/alarm-guards.ts Outdated
const MAX = 1024;
const tooLong = scope.node
.findAll()
.filter((c): c is cloudwatch.Alarm => c instanceof cloudwatch.Alarm)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: only L2 cloudwatch.Alarm is walked. A raw CfnAlarm or a CompositeAlarm (same 1024 limit) slips through, so "any stack added later" holds for L2 alarms only. Filtering on CfnAlarm / CfnCompositeAlarm and reading alarmDescription from them would cover all three.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done: the walk filters on CfnAlarm / CfnCompositeAlarm and reads alarmDescription from them, so L2, raw and composite alarms are all measured. 1a7a63b

Comment thread infra/src/lib/app.ts
observability.addDependency(compute);

// Every stack's alarms, measured before anything is synthesized (task 0288).
assertAlarmDescriptionsFitCloudWatch(app);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking): the negative test from the description isn't committed, and nothing in infra runs createApp or the guard in a test. Dropping this line, or moving it below app.synth(), would stay green. A tiny spec with one over-long alarm in a non-Observability stack would pin it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added tools/scripts/alarm-guards.test.mjs on the existing infra node --test target: over-long in a non-Observability stack fails with the guard's message, exactly 1024 passes, a token description is refused, raw CfnAlarm and composite alarms are measured. The last two fail against the previous guard. I left the app.ts call itself unpinned on purpose: createApp imports the stacks as ./stacks/*.js, which only resolve after an infra build, so pinning it needs a built-infra test harness, a bigger step than this PR. The test header says so. 1a7a63b

A description built from a token resolves to an Fn::Join object, which
the guard counted as length 0, so an over-long one passed synth and failed
mid-deploy. It is now refused at synth. The walk also moves from L2
cloudwatch.Alarm to CfnAlarm + CfnCompositeAlarm, so raw and composite
alarms (same 1024 limit) are measured too.

tools/scripts/alarm-guards.test.mjs pins the guard: over-long fails, 1024
passes, a token is refused, raw and composite alarms are measured. The
last two fail against the previous guard. The production synth passes:
90 alarms, all plain strings, longest 1018. Spotted in review of PR #435.
@karczuRF
karczuRF merged commit 9ea7b6c into develop Nov 30, 2026
4 checks passed
karczuRF added a commit that referenced this pull request Nov 30, 2026
All four PRs merged into develop on 2026-11-30 after Stan's review:
- 0253: #432 (d3bee99)
- 0302: #433 (ef601af), writer probe on production recorded
- 0211: #434 (638beb8), overview revision row now links the archive
- 0288: #435 (9ea7b6c)

Each task records the review fixes, status completed, and moves to
archive/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants