Skip to content

Conversation

phuhung273
Copy link
Contributor

Issue # (if applicable)

Closes #34662

Reason for this change

Invalid template for empty operands

Description of changes

Set to FALSE when empty operands. Alarm is in OK state

Describe any new or updated permissions being added

Description of how you validated changes

Unit + Integ

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team June 19, 2025 00:55
@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK labels Jun 19, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 19, 2025
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 318e90e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@kumvprat kumvprat self-assigned this Aug 22, 2025
@@ -111,6 +111,10 @@ export class AlarmRule {
private static concat(operator: Operator, ...operands: IAlarmRule[]): IAlarmRule {
return new class implements IAlarmRule {
public renderAlarmRule(): string {
if (operands.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Overall the idea looks good but I have a few questions :

  • When creating empty alarms it might be better to return an empty string instead of something that cannot be interpreted.
  • Will this lead to composite alarms being created but with empty details, for example will the 'FALSE' value returned keep alarm in an alarmed state ?
  • Can we have a warning or a log statement so that the CDK user can track/debug as to why an alarm was created with no underlying alarm ?

All of this is assuming it does create an alarm in the user's account, if Cloudformation ignore such alarms and doesn't create any resources behind it

Copy link
Contributor Author

@phuhung273 phuhung273 Aug 24, 2025

Choose a reason for hiding this comment

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

Thank you for taking a look at this. Here are the explanations:

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the main reason behind the reported issue was :

We could consider having CDK throw an error if expression is undefined so users don't need to wait till deployment time to find out the alarm rule is invalid. Maybe something like

The current changes would create an alarm which will not be usable or will not be useful, maybe changing the concat function to handle the operands.length === 0 check and then not generating a IAlarmRule instance might be better choice. Again I am not aware of the full implication, so open to have a discussion around it(I assume you might know better as you have looked at the code)

Main point being that we don't want users to have a new unused/(not useful) alarm unknowingly showing up in their AWS account

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After reconsider, i agree with that. Throwing when empty is definitely a better option. Updated.

@@ -59,6 +59,14 @@ class CompositeAlarmIntegrationTest extends Stack {
alarmRule,
actionsSuppressor: alarm5,
});

new CompositeAlarm(this, 'EmptyAnyOf', {
Copy link
Contributor

Choose a reason for hiding this comment

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

With the empty alarm cases can we have assertions on the CfnOutput and/or on api calls ?
For example if these alarms only exist in template and not actually create a resource we can have an assertion that checks that these alarms are not created at all(since they are basically empty shells)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, I've added API assertion that composite alarm with FALSE rule must be created, and the state is OK.

@phuhung273 phuhung273 force-pushed the composite-alarm-empty-rule branch from 318e90e to 8aaa94d Compare August 24, 2025 14:44
@phuhung273 phuhung273 force-pushed the composite-alarm-empty-rule branch from 8aaa94d to 3600e13 Compare August 27, 2025 10:43
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

(This review is outdated)

@phuhung273
Copy link
Contributor Author

Exemption Request: throwing error doesn't need integration

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Aug 27, 2025
@kumvprat kumvprat added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Aug 27, 2025
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 27, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review August 27, 2025 15:07

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Copy link
Contributor

mergify bot commented Aug 27, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@kumvprat
Copy link
Contributor

@phuhung273 Please edit the PR description to remove the line : Set to FALSE when empty operands. Alarm is in OK state

Copy link
Contributor

mergify bot commented Aug 27, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit a01aa38 into aws:main Aug 27, 2025
18 checks passed
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 2025
@phuhung273 phuhung273 deleted the composite-alarm-empty-rule branch August 27, 2025 23:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-cloudwatch): AlarmRule static methods can synth into an invalid template
3 participants