Skip to content

Commit 7cbe8ac

Browse files
authored
feat(logs): add unit to metric filter (#23608)
Allows attaching unit to a metric filter. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent df569d7 commit 7cbe8ac

29 files changed

+689
-68
lines changed

packages/@aws-cdk/aws-logs/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ const mf = new logs.MetricFilter(this, 'MetricFilter', {
165165
metricValue: '$.latency',
166166
dimensions: {
167167
ErrorCode: '$.errorCode',
168-
}
168+
},
169+
unit: Unit.MILLISECONDS,
169170
});
170171

171172
//expose a metric from the metric filter

packages/@aws-cdk/aws-logs/lib/log-group.ts

+8
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,12 @@ export interface MetricFilterOptions {
545545
* @default - No dimensions attached to metrics.
546546
*/
547547
readonly dimensions?: Record<string, string>;
548+
549+
/**
550+
* The unit to assign to the metric.
551+
*
552+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-logs-metricfilter-metrictransformation.html#cfn-logs-metricfilter-metrictransformation-unit
553+
* @default - No unit attached to metrics.
554+
*/
555+
readonly unit?: cloudwatch.Unit;
548556
}

packages/@aws-cdk/aws-logs/lib/metric-filter.ts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class MetricFilter extends Resource {
4949
metricValue: props.metricValue ?? '1',
5050
defaultValue: props.defaultValue,
5151
dimensions: props.dimensions ? Object.entries(props.dimensions).map(([key, value]) => ({ key, value })) : undefined,
52+
unit: props.unit,
5253
}],
5354
});
5455
}

packages/@aws-cdk/aws-logs/test/integ.expose-metric.js.snapshot/aws-cdk-expose-metric-integ.assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "22.0.0",
33
"files": {
44
"eca17ca94625bc7a08a880410570afed5eecf3d9a01b6c401155caa073187adb": {
55
"source": {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"20.0.0"}
1+
{"version":"22.0.0"}

packages/@aws-cdk/aws-logs/test/integ.expose-metric.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "22.0.0",
33
"testCases": {
44
"integ.expose-metric": {
55
"stacks": [

packages/@aws-cdk/aws-logs/test/integ.expose-metric.js.snapshot/manifest.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
2-
"version": "20.0.0",
2+
"version": "22.0.0",
33
"artifacts": {
4-
"Tree": {
5-
"type": "cdk:tree",
6-
"properties": {
7-
"file": "tree.json"
8-
}
9-
},
104
"aws-cdk-expose-metric-integ.assets": {
115
"type": "cdk:asset-manifest",
126
"properties": {
@@ -71,6 +65,12 @@
7165
]
7266
},
7367
"displayName": "aws-cdk-expose-metric-integ"
68+
},
69+
"Tree": {
70+
"type": "cdk:tree",
71+
"properties": {
72+
"file": "tree.json"
73+
}
7474
}
7575
}
7676
}

packages/@aws-cdk/aws-logs/test/integ.expose-metric.js.snapshot/tree.json

+27-11
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
"id": "App",
55
"path": "",
66
"children": {
7-
"Tree": {
8-
"id": "Tree",
9-
"path": "Tree",
10-
"constructInfo": {
11-
"fqn": "constructs.Construct",
12-
"version": "10.1.85"
13-
}
14-
},
157
"aws-cdk-expose-metric-integ": {
168
"id": "aws-cdk-expose-metric-integ",
179
"path": "aws-cdk-expose-metric-integ",
@@ -103,17 +95,41 @@
10395
"fqn": "@aws-cdk/aws-cloudwatch.Alarm",
10496
"version": "0.0.0"
10597
}
98+
},
99+
"BootstrapVersion": {
100+
"id": "BootstrapVersion",
101+
"path": "aws-cdk-expose-metric-integ/BootstrapVersion",
102+
"constructInfo": {
103+
"fqn": "@aws-cdk/core.CfnParameter",
104+
"version": "0.0.0"
105+
}
106+
},
107+
"CheckBootstrapVersion": {
108+
"id": "CheckBootstrapVersion",
109+
"path": "aws-cdk-expose-metric-integ/CheckBootstrapVersion",
110+
"constructInfo": {
111+
"fqn": "@aws-cdk/core.CfnRule",
112+
"version": "0.0.0"
113+
}
106114
}
107115
},
116+
"constructInfo": {
117+
"fqn": "@aws-cdk/core.Stack",
118+
"version": "0.0.0"
119+
}
120+
},
121+
"Tree": {
122+
"id": "Tree",
123+
"path": "Tree",
108124
"constructInfo": {
109125
"fqn": "constructs.Construct",
110-
"version": "10.1.85"
126+
"version": "10.1.189"
111127
}
112128
}
113129
},
114130
"constructInfo": {
115-
"fqn": "constructs.Construct",
116-
"version": "10.1.85"
131+
"fqn": "@aws-cdk/core.App",
132+
"version": "0.0.0"
117133
}
118134
}
119135
}

packages/@aws-cdk/aws-logs/test/integ.metricfilter-dimensions.js.snapshot/aws-cdk-metricfilter-dimensions-integ.assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "21.0.0",
2+
"version": "22.0.0",
33
"files": {
44
"3d99811cf4d8b2d453d889e936569b925ead97bdb93a86d122b34d68818be01d": {
55
"source": {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"21.0.0"}
1+
{"version":"22.0.0"}

packages/@aws-cdk/aws-logs/test/integ.metricfilter-dimensions.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "21.0.0",
2+
"version": "22.0.0",
33
"testCases": {
44
"metricfilter-dimensions/DefaultTest": {
55
"stacks": [

packages/@aws-cdk/aws-logs/test/integ.metricfilter-dimensions.js.snapshot/manifest.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
2-
"version": "21.0.0",
2+
"version": "22.0.0",
33
"artifacts": {
4-
"Tree": {
5-
"type": "cdk:tree",
6-
"properties": {
7-
"file": "tree.json"
8-
}
9-
},
104
"aws-cdk-metricfilter-dimensions-integ.assets": {
115
"type": "cdk:asset-manifest",
126
"properties": {
@@ -112,6 +106,12 @@
112106
]
113107
},
114108
"displayName": "metricfilter-dimensions/DefaultTest/DeployAssert"
109+
},
110+
"Tree": {
111+
"type": "cdk:tree",
112+
"properties": {
113+
"file": "tree.json"
114+
}
115115
}
116116
}
117117
}

packages/@aws-cdk/aws-logs/test/integ.metricfilter-dimensions.js.snapshot/metricfilterdimensionsDefaultTestDeployAssertF7E39B09.assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "21.0.0",
2+
"version": "22.0.0",
33
"files": {
44
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
55
"source": {

packages/@aws-cdk/aws-logs/test/integ.metricfilter-dimensions.js.snapshot/tree.json

+43-9
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
"id": "App",
55
"path": "",
66
"children": {
7-
"Tree": {
8-
"id": "Tree",
9-
"path": "Tree",
10-
"constructInfo": {
11-
"fqn": "constructs.Construct",
12-
"version": "10.1.95"
13-
}
14-
},
157
"aws-cdk-metricfilter-dimensions-integ": {
168
"id": "aws-cdk-metricfilter-dimensions-integ",
179
"path": "aws-cdk-metricfilter-dimensions-integ",
@@ -79,6 +71,22 @@
7971
"fqn": "@aws-cdk/aws-logs.MetricFilter",
8072
"version": "0.0.0"
8173
}
74+
},
75+
"BootstrapVersion": {
76+
"id": "BootstrapVersion",
77+
"path": "aws-cdk-metricfilter-dimensions-integ/BootstrapVersion",
78+
"constructInfo": {
79+
"fqn": "@aws-cdk/core.CfnParameter",
80+
"version": "0.0.0"
81+
}
82+
},
83+
"CheckBootstrapVersion": {
84+
"id": "CheckBootstrapVersion",
85+
"path": "aws-cdk-metricfilter-dimensions-integ/CheckBootstrapVersion",
86+
"constructInfo": {
87+
"fqn": "@aws-cdk/core.CfnRule",
88+
"version": "0.0.0"
89+
}
8290
}
8391
},
8492
"constructInfo": {
@@ -99,12 +107,30 @@
99107
"path": "metricfilter-dimensions/DefaultTest/Default",
100108
"constructInfo": {
101109
"fqn": "constructs.Construct",
102-
"version": "10.1.95"
110+
"version": "10.1.189"
103111
}
104112
},
105113
"DeployAssert": {
106114
"id": "DeployAssert",
107115
"path": "metricfilter-dimensions/DefaultTest/DeployAssert",
116+
"children": {
117+
"BootstrapVersion": {
118+
"id": "BootstrapVersion",
119+
"path": "metricfilter-dimensions/DefaultTest/DeployAssert/BootstrapVersion",
120+
"constructInfo": {
121+
"fqn": "@aws-cdk/core.CfnParameter",
122+
"version": "0.0.0"
123+
}
124+
},
125+
"CheckBootstrapVersion": {
126+
"id": "CheckBootstrapVersion",
127+
"path": "metricfilter-dimensions/DefaultTest/DeployAssert/CheckBootstrapVersion",
128+
"constructInfo": {
129+
"fqn": "@aws-cdk/core.CfnRule",
130+
"version": "0.0.0"
131+
}
132+
}
133+
},
108134
"constructInfo": {
109135
"fqn": "@aws-cdk/core.Stack",
110136
"version": "0.0.0"
@@ -121,6 +147,14 @@
121147
"fqn": "@aws-cdk/integ-tests.IntegTest",
122148
"version": "0.0.0"
123149
}
150+
},
151+
"Tree": {
152+
"id": "Tree",
153+
"path": "Tree",
154+
"constructInfo": {
155+
"fqn": "constructs.Construct",
156+
"version": "10.1.189"
157+
}
124158
}
125159
},
126160
"constructInfo": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "22.0.0",
3+
"files": {
4+
"1018bc494b7d127e812267baabd1be681787fdf8c894e89c52f41c3caa74fe6d": {
5+
"source": {
6+
"path": "aws-cdk-metricfilter-unit-integ.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "1018bc494b7d127e812267baabd1be681787fdf8c894e89c52f41c3caa74fe6d.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"Resources": {
3+
"LogGroupF5B46931": {
4+
"Type": "AWS::Logs::LogGroup",
5+
"Properties": {
6+
"RetentionInDays": 731
7+
},
8+
"UpdateReplacePolicy": "Delete",
9+
"DeletionPolicy": "Delete"
10+
},
11+
"MetricFilter1B93B6E5": {
12+
"Type": "AWS::Logs::MetricFilter",
13+
"Properties": {
14+
"FilterPattern": "{ $.latency = \"*\" }",
15+
"LogGroupName": {
16+
"Ref": "LogGroupF5B46931"
17+
},
18+
"MetricTransformations": [
19+
{
20+
"Dimensions": [
21+
{
22+
"Key": "ErrorCode",
23+
"Value": "$.errorCode"
24+
}
25+
],
26+
"MetricName": "Latency",
27+
"MetricNamespace": "MyApp",
28+
"MetricValue": "$.latency",
29+
"Unit": "Milliseconds"
30+
}
31+
]
32+
}
33+
}
34+
},
35+
"Parameters": {
36+
"BootstrapVersion": {
37+
"Type": "AWS::SSM::Parameter::Value<String>",
38+
"Default": "/cdk-bootstrap/hnb659fds/version",
39+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
40+
}
41+
},
42+
"Rules": {
43+
"CheckBootstrapVersion": {
44+
"Assertions": [
45+
{
46+
"Assert": {
47+
"Fn::Not": [
48+
{
49+
"Fn::Contains": [
50+
[
51+
"1",
52+
"2",
53+
"3",
54+
"4",
55+
"5"
56+
],
57+
{
58+
"Ref": "BootstrapVersion"
59+
}
60+
]
61+
}
62+
]
63+
},
64+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
65+
}
66+
]
67+
}
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"22.0.0"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "22.0.0",
3+
"testCases": {
4+
"metricfilter-unit/DefaultTest": {
5+
"stacks": [
6+
"aws-cdk-metricfilter-unit-integ"
7+
],
8+
"assertionStack": "metricfilter-unit/DefaultTest/DeployAssert",
9+
"assertionStackName": "metricfilterunitDefaultTestDeployAssertB2F4057A"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)