Skip to content

Commit 1321c9d

Browse files
committed
1. Add README & Integ tests 2. Address comments
1 parent 9dc00fc commit 1321c9d

File tree

7 files changed

+62
-68
lines changed

7 files changed

+62
-68
lines changed

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.log-group.js.snapshot/aws-cdk-log-group-integ.assets.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.log-group.js.snapshot/aws-cdk-log-group-integ.template.json

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
]
113113
}
114114
},
115+
"FieldIndexPolicies": [
116+
{
117+
"Fields": [
118+
"Operation",
119+
"RequestId"
120+
]
121+
}
122+
],
115123
"RetentionInDays": 731
116124
},
117125
"UpdateReplacePolicy": "Retain",

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.log-group.js.snapshot/manifest.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.log-group.js.snapshot/tree.json

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.log-group.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Bucket } from 'aws-cdk-lib/aws-s3';
22
import { App, Stack, StackProps } from 'aws-cdk-lib';
33
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
4-
import { LogGroup, DataProtectionPolicy, DataIdentifier, CustomDataIdentifier } from 'aws-cdk-lib/aws-logs';
4+
import { LogGroup, DataProtectionPolicy, DataIdentifier, CustomDataIdentifier, FieldIndexPolicy } from 'aws-cdk-lib/aws-logs';
55

66
class LogGroupIntegStack extends Stack {
77
constructor(scope: App, id: string, props?: StackProps) {
@@ -19,8 +19,13 @@ class LogGroupIntegStack extends Stack {
1919
s3BucketAuditDestination: bucket,
2020
});
2121

22+
const fieldIndexPolicy = new FieldIndexPolicy({
23+
fields: ['Operation', 'RequestId'],
24+
});
25+
2226
new LogGroup(this, 'LogGroupLambda', {
2327
dataProtectionPolicy: dataProtectionPolicy,
28+
fieldIndexPolicies: [fieldIndexPolicy],
2429
});
2530
}
2631
}

Diff for: packages/aws-cdk-lib/aws-logs/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,43 @@ new logs.LogGroup(this, 'LogGroupLambda', {
441441
});
442442
```
443443

444+
## Field Index Policies
445+
446+
Creates or updates a field index policy for the specified log group. You can use field index policies to create field indexes on fields found in log events in the log group. Creating field indexes lowers the costs for CloudWatch Logs Insights queries that reference those field indexes, because these queries attempt to skip the processing of log events that are known to not match the indexed field. Good fields to index are fields that you often need to query for and fields that have high cardinality of values.
447+
448+
For more information, see [Create field indexes to improve query performance and reduce costs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatchLogs-Field-Indexing.html).
449+
450+
Only log groups in the Standard log class support field index policies.
451+
Currently, this array supports only one field index policy object.
452+
453+
Example:
454+
455+
```ts
456+
import { Bucket } from '@aws-cdk/aws-s3';
457+
import { LogGroup } from '@aws-cdk/logs';
458+
import * as kinesisfirehose from '@aws-cdk/aws-kinesisfirehose';
459+
460+
461+
const logGroupDestination = new LogGroup(this, 'LogGroupLambdaAudit', {
462+
logGroupName: 'auditDestinationForCDK',
463+
});
464+
465+
const s3Destination = new Bucket(this, 'audit-bucket-id');
466+
467+
const deliveryStream = new firehose.DeliveryStream(this, 'Delivery Stream', {
468+
destinations: [s3Destination],
469+
});
470+
471+
const fieldIndexPolicy = new FieldIndexPolicy({
472+
fields: ['Operation', 'RequestId'],
473+
});
474+
475+
new LogGroup(this, 'LogGroupLambda', {
476+
logGroupName: 'cdkIntegLogGroup',
477+
fieldIndexPolicies: [fieldIndexPolicy],
478+
});
479+
```
480+
444481
## Notes
445482

446483
Be aware that Log Group ARNs will always have the string `:*` appended to

Diff for: packages/aws-cdk-lib/aws-logs/test/loggroup.test.ts

-64
Original file line numberDiff line numberDiff line change
@@ -950,70 +950,6 @@ test('set field index policy with four fields indexed', () => {
950950
});
951951
});
952952

953-
test('set field index policy positive test', () => {
954-
// GIVEN
955-
const stack = new Stack();
956-
const fieldIndexPolicy = new FieldIndexPolicy({
957-
fields: ['Operation', 'RequestId', 'timestamp', 'message'],
958-
});
959-
960-
// WHEN
961-
const logGroupName = 'test-field-index-policy';
962-
new LogGroup(stack, 'LogGroup', {
963-
logGroupName: logGroupName,
964-
fieldIndexPolicies: [fieldIndexPolicy],
965-
});
966-
967-
// THEN
968-
Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {
969-
LogGroupName: logGroupName,
970-
FieldIndexPolicies: [{
971-
Fields: [
972-
'Operation',
973-
'RequestId',
974-
'timestamp',
975-
'message',
976-
],
977-
}],
978-
});
979-
});
980-
981-
test('set multiple field index policies', () => {
982-
let message;
983-
try {
984-
// GIVEN
985-
const stack = new Stack();
986-
const fieldIndexPolicy = new FieldIndexPolicy({
987-
fields: ['Operation', 'RequestId', 'timestamp', 'message'],
988-
});
989-
990-
// WHEN
991-
const logGroupName = 'test-field-multiple-field-index-policies';
992-
new LogGroup(stack, 'LogGroup', {
993-
logGroupName: logGroupName,
994-
fieldIndexPolicies: [fieldIndexPolicy, fieldIndexPolicy],
995-
});
996-
997-
// THEN
998-
Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {
999-
LogGroupName: logGroupName,
1000-
FieldIndexPolicies: [{
1001-
Fields: [
1002-
'Operation',
1003-
'RequestId',
1004-
'timestamp',
1005-
'message',
1006-
],
1007-
}],
1008-
});
1009-
} catch (e) {
1010-
message = (e as Error).message;
1011-
}
1012-
1013-
expect(message).toBeDefined();
1014-
expect(message).toEqual('Only one field index policy is currently supported');
1015-
});
1016-
1017953
test('set more than 20 field indexes in a field index policy', () => {
1018954
let message;
1019955
try {

0 commit comments

Comments
 (0)