Skip to content

feat(cloudwatch): add PromQL Alarm L2 construct#37793

Merged
mergify[bot] merged 9 commits into
aws:mainfrom
caoxy98:promql-alarm-l2-construct
May 12, 2026
Merged

feat(cloudwatch): add PromQL Alarm L2 construct#37793
mergify[bot] merged 9 commits into
aws:mainfrom
caoxy98:promql-alarm-l2-construct

Conversation

@caoxy98
Copy link
Copy Markdown
Contributor

@caoxy98 caoxy98 commented May 7, 2026

Reason for this change

Add a new PromQLAlarm L2 construct to the aws-cdk-lib/aws-cloudwatch module that enables users to create CloudWatch alarms based on PromQL instant queries. PromQL alarms monitor metrics ingested through the CloudWatch OTLP endpoint and use duration-based state transitions (pending/recovery periods) instead of the evaluation-period/threshold model used by standard CloudWatch alarms.

Description of changes

  • Add PromQLAlarm L2 construct extending AlarmBase with typed props for query, pendingPeriod, recoveryPeriod, and evaluationInterval
  • Add input validation matching coral model constraints
  • Add unit tests covering creation, actions, imports, and validation
  • Export PromQLAlarm from aws-cloudwatch module index

Describe any new or updated permissions being added

N/A

Description of how you validated changes

Unit tests + Integ tests

Checklist


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

@github-actions github-actions Bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ This pull request description does not follow the correct template structure.

PRs without a linked issue will receive lower priority for review and merging. Please update the description to follow the PR template and include a line like Closes #123 in the Issue section. If no existing issue matches your change, create one first.

Copy link
Copy Markdown
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)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.
To suppress a specific rule, see Suppressing Rules.


TestsPassed ✅SkippedFailed
Security Guardian Results48 ran48 passed
TestResult
No test annotations available

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.
To suppress a specific rule, see Suppressing Rules.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates48 ran48 passed
TestResult
No test annotations available

@caoxy98 caoxy98 changed the title Promql alarm l2 construct feat: Promql alarm l2 construct May 7, 2026
@caoxy98 caoxy98 changed the title feat: Promql alarm l2 construct feat(cloudwatch): add PromQL Alarm L2 construct May 7, 2026
@aws-cdk-automation aws-cdk-automation dismissed their stale review May 7, 2026 15:56

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

@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 May 8, 2026
@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 May 8, 2026
Copy link
Copy Markdown
Contributor

@kumsmrit kumsmrit left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution; I have reviewed and added some comments.

import type { IAlarm, IAlarmAction } from '../lib';
import { PromQLAlarm } from '../lib/promql-alarm';

describe('PromQLAlarm', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The construct validates evaluationInterval, pendingPeriod, recoveryPeriod, and query length, but there are no tests verifying these validations throw.
Can we add tests for each of the validation paths?

## PromQL Alarms

PromQL alarms allow you to create CloudWatch alarms using PromQL query expressions. This is useful when working with Prometheus-compatible metrics in CloudWatch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add detail as how is it different from standard CloudWatch alarms?

/**
* Import an existing CloudWatch alarm provided an ARN.
*/
public static fromAlarmArn(scope: Construct, id: string, alarmArn: string): IAlarm {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static fromAlarmArn(scope: Construct, id: string, alarmArn: string): IAlarm {
public static fromPromQLAlarmArn(scope: Construct, id: string, alarmArn: string): IAlarm {

/**
* Import an existing CloudWatch alarm provided a Name.
*/
public static fromAlarmName(scope: Construct, id: string, alarmName: string): IAlarm {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static fromAlarmName(scope: Construct, id: string, alarmName: string): IAlarm {
public static fromPromQLAlarmName(scope: Construct, id: string, alarmName: string): IAlarm {


/**
* A CloudWatch Alarm based on a PromQL query expression.
*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
*
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/alarm-promql.html

alarmDescription: props.alarmDescription,
alarmName: this.physicalName,
actionsEnabled: props.actionsEnabled,
alarmActions: Lazy.list({ produce: () => this.alarmActionArns }),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AlarmBase._alarmActionArns is now an IArrayBox<string> which already implements IResolvable directly, so this can be passed to the L1 without an additional Lazy.list(...) wrapper. Use Token.asList(...) instead.

alarmName: this.physicalName,
actionsEnabled: props.actionsEnabled,
alarmActions: Lazy.list({ produce: () => this.alarmActionArns }),
insufficientDataActions: Lazy.list({ produce: () => this.insufficientDataActionArns }),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use Token.asList(...) instead of Lazy.list(...). Applicable at other places as well.


new IntegTest(app, 'PromQLAlarmIntegTest', {
testCases: [stack],
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider adding assertions to verify if the alarm is created correctly after deployment; That would help validate that the deployed alarm contains the expected EvaluationCriteria.PromQLCriteria.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As discussed, since the parameters are newly added and the sdk version is not updated to have them yet. We'll add the validation once the sdk version is updated later

@kumsmrit kumsmrit self-assigned this May 8, 2026
@mergify mergify Bot dismissed kumsmrit’s stale review May 8, 2026 16:10

Pull request has been modified.

caoxy98 added 7 commits May 12, 2026 16:18
Add PromQLAlarm construct to aws-cloudwatch module enabling customers
to define PromQL-based alarms in their CDK applications.
@caoxy98 caoxy98 force-pushed the promql-alarm-l2-construct branch from 2ef5635 to 4a9a9d0 Compare May 12, 2026 15:18
@caoxy98 caoxy98 temporarily deployed to deployment-integ-test May 12, 2026 15:19 — with GitHub Actions Inactive
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 12, 2026

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
Copy link
Copy Markdown
Contributor

mergify Bot commented May 12, 2026

Merge Queue Status

  • Entered queue2026-05-12 16:15 UTC · Rule: default-squash
  • Checks started · in-place
  • 🚫 Left the queue2026-05-12 17:00 UTC · at 72771a940e69d53ee32dc5c7f0cc3b91ddae1848

This pull request spent 45 minutes 12 seconds in the queue, including 35 minutes 4 seconds running CI.

Required conditions to merge

Reason

The merge conditions cannot be satisfied due to failing checks

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

@mergify mergify Bot had a problem deploying to deployment-integ-test May 12, 2026 16:25 Failure
@mergify mergify Bot temporarily deployed to automation May 12, 2026 16:25 Inactive
@mergify mergify Bot temporarily deployed to automation May 12, 2026 16:26 Inactive
@kumsmrit kumsmrit removed the pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots. label May 12, 2026
@mergify mergify Bot temporarily deployed to deployment-integ-test May 12, 2026 17:21 Inactive
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 12, 2026

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
Copy link
Copy Markdown
Contributor

mergify Bot commented May 12, 2026

Merge Queue Status

  • Entered queue2026-05-12 17:24 UTC · Rule: default-squash
  • Checks passed · in-place
  • Merged2026-05-12 18:46 UTC · at 6f9349db81f221f97d2879c0e6bca633e2dc03c4 · squash

This pull request spent 1 hour 22 minutes 3 seconds in the queue, including 33 minutes 49 seconds running CI.

Required conditions to merge

@mergify mergify Bot temporarily deployed to automation May 12, 2026 18:12 Inactive
@mergify mergify Bot temporarily deployed to automation May 12, 2026 18:12 Inactive
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 12, 2026

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 13a4924 into aws:main May 12, 2026
24 of 25 checks passed
@github-actions
Copy link
Copy Markdown
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 May 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants