Skip to content

Commit 481a9d2

Browse files
feat: cloudwatch logs transformer support (#34863)
### Issue # (if applicable) Closes #34861. ### Reason for this change Creates CDK constructs for CloudWatch Logs Transformers. Transformers already have CFN constructs and this achieves functional parity. ### Description of changes Added a `Transformer` construct which is an abstraction over `cfnTransformer`. Created a factory class `ProcessorFactory` with static methods to create each of the 5 overarching types of processors described in https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatch-Logs-Transformation-Processors.html, namely: `ParserProcessor`, `VendedLogParser`, `StringMutatorProcessor`, `JsonMutatorProcessor` and `DataConverterProcessor`. These classes implement a `_bind()` method responsible for returning the props expected by CFN constructs for each processor of the respective types. These classes are further split into their processors defined by enums (`ParserProcessorType`, `VendedLogType`, `StringMutatorType`, `JsonMutatorType`, `DataConverterType`) and properties for each processor. A `Transformer` expects a `transformerConfig` which is a list of processors. Processors can be created using the static methods `createParserProcessor`, `createVendedLogParser`, `createStringMutatorProcessor`, `createJsonMutatorProcessor` and `createDataConverterProcessor` in the `ProcessorFactory`, by passing the type (from the enums defined above) and the relevant props for that processor. `ValidationError` is thrown if the expected/required props are not passed. Further validations are performed for limit breaches or positions of parsers being incorrect. ### Describe any new or updated permissions being added - ### Description of how you validated changes Added unit tests for each processor and each validation. Added integ test. ### 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 4c7d9f4 commit 481a9d2

24 files changed

+3274
-1
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.loggroup-transformer.js.snapshot/aws-cdk-transformer-integ.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,82 @@
1+
{
2+
"Resources": {
3+
"MyLogGroup5C0DAD85": {
4+
"Type": "AWS::Logs::LogGroup",
5+
"Properties": {
6+
"RetentionInDays": 731
7+
},
8+
"UpdateReplacePolicy": "Retain",
9+
"DeletionPolicy": "Retain"
10+
},
11+
"MyLogGroupResourceTransformer00531468": {
12+
"Type": "AWS::Logs::Transformer",
13+
"Properties": {
14+
"LogGroupIdentifier": {
15+
"Ref": "MyLogGroup5C0DAD85"
16+
},
17+
"TransformerConfig": [
18+
{
19+
"ParseJSON": {
20+
"Source": "customField"
21+
}
22+
},
23+
{
24+
"AddKeys": {
25+
"Entries": [
26+
{
27+
"Key": "test_key1",
28+
"OverwriteIfExists": true,
29+
"Value": "test_value1"
30+
},
31+
{
32+
"Key": "test_key2",
33+
"OverwriteIfExists": false,
34+
"Value": "test_value2"
35+
},
36+
{
37+
"Key": "test_key3",
38+
"OverwriteIfExists": false,
39+
"Value": "test_value3"
40+
}
41+
]
42+
}
43+
}
44+
]
45+
}
46+
}
47+
},
48+
"Parameters": {
49+
"BootstrapVersion": {
50+
"Type": "AWS::SSM::Parameter::Value<String>",
51+
"Default": "/cdk-bootstrap/hnb659fds/version",
52+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
53+
}
54+
},
55+
"Rules": {
56+
"CheckBootstrapVersion": {
57+
"Assertions": [
58+
{
59+
"Assert": {
60+
"Fn::Not": [
61+
{
62+
"Fn::Contains": [
63+
[
64+
"1",
65+
"2",
66+
"3",
67+
"4",
68+
"5"
69+
],
70+
{
71+
"Ref": "BootstrapVersion"
72+
}
73+
]
74+
}
75+
]
76+
},
77+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
78+
}
79+
]
80+
}
81+
}
82+
}

packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.loggroup-transformer.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-logs/test/integ.loggroup-transformer.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.

packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.loggroup-transformer.js.snapshot/manifest.json

Lines changed: 130 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-logs/test/integ.loggroup-transformer.js.snapshot/transformercreateDefaultTestDeployAssertB915E804.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-logs/test/integ.loggroup-transformer.js.snapshot/transformercreateDefaultTestDeployAssertB915E804.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-logs/test/integ.loggroup-transformer.js.snapshot/tree.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
2+
import { App, Stack, StackProps } from 'aws-cdk-lib';
3+
import { JsonMutatorType, LogGroup, ParserProcessorType, ParserProcessor, JsonMutatorProcessor } from 'aws-cdk-lib/aws-logs';
4+
5+
class TransformerIntegStack extends Stack {
6+
constructor(scope: App, id: string, props?: StackProps) {
7+
super(scope, id, props);
8+
9+
const logGroup = new LogGroup(this, 'MyLogGroup');
10+
const jsonParser = new ParserProcessor({
11+
type: ParserProcessorType.JSON,
12+
jsonOptions: { source: 'customField' },
13+
});
14+
15+
const addKeysProcesor = new JsonMutatorProcessor({
16+
type: JsonMutatorType.ADD_KEYS,
17+
addKeysOptions: {
18+
entries: [
19+
{ key: 'test_key1', value: 'test_value1', overwriteIfExists: true },
20+
{ key: 'test_key2', value: 'test_value2' },
21+
{ key: 'test_key3', value: 'test_value3', overwriteIfExists: false },
22+
],
23+
},
24+
});
25+
26+
logGroup.addTransformer('Transformer', {
27+
transformerName: 'MyTransformer',
28+
transformerConfig: [jsonParser, addKeysProcesor],
29+
});
30+
}
31+
}
32+
33+
const app = new App();
34+
const testCase = new TransformerIntegStack(app, 'aws-cdk-transformer-integ');
35+
new IntegTest(app, 'transformer-create', {
36+
testCases: [testCase],
37+
});

packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.transformer.js.snapshot/aws-cdk-transformer-integ.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.

0 commit comments

Comments
 (0)