Skip to content

Conversation

@abidhasan-aws
Copy link
Contributor

@abidhasan-aws abidhasan-aws commented Jul 9, 2025

Issue # (if applicable)

Closes #7237

Reason for this change

Currently, GraphWidget only supports MathExpression or Metric objects. There is no native support for SearchExpression.
Although it is possible to use a search expression through a math expression, doing so requires hacky workarounds and additional boilerplate code.

Description of changes

AddedSearchExpression class to enable native support for search expression within GraphWidget.

Description of how you validated changes

Added unit tests and integration tests.

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 July 9, 2025 12:52
@github-actions github-actions bot added the p2 label Jul 9, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 9, 2025
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)

@abidhasan-aws abidhasan-aws changed the title feat(cloudWatch): add search expression to graph widget in cloudwatch dashboard feat(cloudwatch): add search expression to graph widget in cloudwatch dashboard Jul 9, 2025
@abidhasan-aws abidhasan-aws marked this pull request as ready for review July 9, 2025 15:54
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 and removed p2 labels Jul 9, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review July 10, 2025 16:05

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 10, 2025
@ozelalisen ozelalisen removed their assignment Jul 11, 2025
@github-actions
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.

@abidhasan-aws abidhasan-aws reopened this Jul 11, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 11, 2025
@abidhasan-aws abidhasan-aws marked this pull request as draft July 11, 2025 09:52
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 11, 2025
@abidhasan-aws abidhasan-aws marked this pull request as ready for review July 14, 2025 14:19
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 14, 2025
@Abogical Abogical assigned Abogical and unassigned Abogical Jul 15, 2025
Copy link
Member

@Abogical Abogical 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! Some changes are needed.

Comment on lines 537 to 538
withSearchExpression(_searchExpr, _conf) {
throw new UnscopedValidationError('Search expressions are not supported in CloudWatch Alarms. Use search expressions only in dashboard graphs.');
Copy link
Member

Choose a reason for hiding this comment

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

You can use a scoped Validation Error in this context with the scope of the Alarm.

Suggested change
withSearchExpression(_searchExpr, _conf) {
throw new UnscopedValidationError('Search expressions are not supported in CloudWatch Alarms. Use search expressions only in dashboard graphs.');
withSearchExpression: (_searchExpr, _conf) => { // Use arrow function to not override `this` from the class instance.
throw new ValidationError('Search expressions are not supported in CloudWatch Alarms. Use search expressions only in dashboard graphs.', this);

return { props, primaryId };
},
withSearchExpression() {
throw new UnscopedValidationError('Search expressions are not supported in CloudWatch Alarms. Use search expressions only in dashboard graphs.');
Copy link
Member

Choose a reason for hiding this comment

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

Scoped validation error here as well.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 16, 2025
Comment on lines 79 to 83
withMathExpression(mathExpr) {
applyExpressionOptions(mathExpr);
},
withSearchExpression(searchExpr) {
applyExpressionOptions(searchExpr);
Copy link
Member

Choose a reason for hiding this comment

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

You can also "hoist" the applyExpressionOptions function for cleaner code.

const applyExpressionOptions = (options: any, exprConfig: MetricExpressionConfig) => {
  ...
};

function metricGraphJson(metric: IMetric, yAxis?: string, id?: string) {
  ...
  withMathExpression(mathExpr) {
      applyExpressionOptions(options, mathExpr);
    },
    withSearchExpression(searchExpr) {
      applyExpressionOptions(options, searchExpr);

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Member

@Abogical Abogical 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!

@mergify mergify bot merged commit e3f505e into aws:main Jul 17, 2025
19 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metric SEARCH Expression support for GraphWidget CDK Construct

4 participants