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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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": {
Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 27 additions & 11 deletions
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

Lines changed: 1 addition & 1 deletion
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": {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"21.0.0"}
1+
{"version":"22.0.0"}

0 commit comments

Comments
 (0)