Skip to content

Commit e3f505e

Browse files
feat(cloudwatch): add search expression to graph widget in cloudwatch dashboard (#34933)
### 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 Added`SearchExpression` class to enable native support for search expression within `GraphWidget`. ### Description of how you validated changes Added unit tests and integration tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 21a7a49 commit e3f505e

17 files changed

+1307
-43
lines changed

deprecated_apis.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ aws-cdk-lib.aws_cloudwatch.IMetric#toAlarmConfig
418418
aws-cdk-lib.aws_cloudwatch.IMetric#toGraphConfig
419419
aws-cdk-lib.aws_cloudwatch.MathExpression#toAlarmConfig
420420
aws-cdk-lib.aws_cloudwatch.MathExpression#toGraphConfig
421+
aws-cdk-lib.aws_cloudwatch.SearchExpression#toAlarmConfig
422+
aws-cdk-lib.aws_cloudwatch.SearchExpression#toGraphConfig
421423
aws-cdk-lib.aws_cloudwatch.Metric#toAlarmConfig
422424
aws-cdk-lib.aws_cloudwatch.Metric#toGraphConfig
423425
aws-cdk-lib.aws_cloudwatch.MetricAlarmConfig

packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.search-expression.js.snapshot/SearchExpressionIntegTestDefaultTestDeployAssert9E90EDA4.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.search-expression.js.snapshot/SearchExpressionIntegTestDefaultTestDeployAssert9E90EDA4.template.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.search-expression.js.snapshot/SearchExpressionStack.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"Resources": {
3+
"SearchExpressionDashboardC39DD5E9": {
4+
"Type": "AWS::CloudWatch::Dashboard",
5+
"Properties": {
6+
"DashboardBody": {
7+
"Fn::Join": [
8+
"",
9+
[
10+
"{\"widgets\":[{\"type\":\"metric\",\"width\":24,\"height\":6,\"x\":0,\"y\":0,\"properties\":{\"view\":\"timeSeries\",\"title\":\"Minimal vs Custom Properties\",\"region\":\"",
11+
{
12+
"Ref": "AWS::Region"
13+
},
14+
"\",\"metrics\":[[{\"label\":\"SEARCH('{AWS/EC2,InstanceId} CPUUtilization', 'Average', 300)\",\"expression\":\"SEARCH('{AWS/EC2,InstanceId} CPUUtilization', 'Average', 300)\"}],[{\"label\":\"Custom Lambda Duration\",\"color\":\"#e377c2\",\"expression\":\"SEARCH('{AWS/Lambda,FunctionName} Duration', 'Average', 300)\",\"accountId\":\"123456789012\",\"region\":\"us-west-2\",\"period\":600,\"yAxis\":\"right\"}],[{\"label\":\"Cross-Account Cross-Region S3\",\"color\":\"#9467bd\",\"expression\":\"SEARCH('{AWS/S3,BucketName} BucketSizeBytes', 'Average', 86400)\",\"accountId\":\"123456789012\",\"region\":\"ap-southeast-1\",\"period\":3600,\"yAxis\":\"right\"}]],\"yAxis\":{}}}]}"
15+
]
16+
]
17+
},
18+
"DashboardName": "SearchExpressionTestDashboard"
19+
}
20+
}
21+
},
22+
"Parameters": {
23+
"BootstrapVersion": {
24+
"Type": "AWS::SSM::Parameter::Value<String>",
25+
"Default": "/cdk-bootstrap/hnb659fds/version",
26+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
27+
}
28+
},
29+
"Rules": {
30+
"CheckBootstrapVersion": {
31+
"Assertions": [
32+
{
33+
"Assert": {
34+
"Fn::Not": [
35+
{
36+
"Fn::Contains": [
37+
[
38+
"1",
39+
"2",
40+
"3",
41+
"4",
42+
"5"
43+
],
44+
{
45+
"Ref": "BootstrapVersion"
46+
}
47+
]
48+
}
49+
]
50+
},
51+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
52+
}
53+
]
54+
}
55+
}
56+
}

packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.search-expression.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.search-expression.js.snapshot/integ.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)