forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logs): add support for fieldIndexPolicies in log group L2 Constr…
…uct (aws#33416) ### Issue # (if applicable) aws#33366 Closes aws#33366 ### Reason for this change Field Indexing for CloudWatch Logs (CWL) was launched in Nov 2024. A lot of CWL customers are asking for indexing support in L2 construct. This feature will enable that property under FieldIndexPolicies as a JSON object in the LogGroup construct. ### Description of changes The change here is just populating the `fieldIndexPolicies` property of the LogGroup CFN with the list of fields provided by the user. The format of this property will be like this: ``` const fieldIndexPolicy = new FieldIndexPolicy({ fields: ['Operation', 'RequestId'], }); new LogGroup(this, 'LogGroupLambda', { dataProtectionPolicy: dataProtectionPolicy, fieldIndexPolicies: [fieldIndexPolicy], }); ``` ### Describe any new or updated permissions being added No new permissions have been added. ### Description of how you validated changes Added unit tests. Will add integ tests after getting a confirmation from the CDK team on the implementation. ### 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*
- Loading branch information
1 parent
ba2dfd1
commit 6c882e0
Showing
10 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...-integ/test/aws-logs/test/integ.log-group.js.snapshot/aws-cdk-log-group-integ.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...-cdk-testing/framework-integ/test/aws-logs/test/integ.log-group.js.snapshot/manifest.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...@aws-cdk-testing/framework-integ/test/aws-logs/test/integ.log-group.js.snapshot/tree.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Construct } from 'constructs'; | ||
|
||
/** | ||
* Creates a field index policy for CloudWatch Logs log groups. | ||
*/ | ||
export class FieldIndexPolicy { | ||
private readonly fieldIndexPolicyProps: FieldIndexPolicyProps; | ||
|
||
constructor(props: FieldIndexPolicyProps) { | ||
if (props.fields.length > 20) { | ||
throw new Error('A maximum of 20 fields can be indexed per log group'); | ||
} | ||
this.fieldIndexPolicyProps = props; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public _bind(_scope: Construct) { | ||
return { Fields: this.fieldIndexPolicyProps.fields }; | ||
} | ||
} | ||
|
||
/** | ||
* Properties for creating field index policies | ||
*/ | ||
export interface FieldIndexPolicyProps { | ||
/** | ||
* List of fields to index in log events. | ||
* | ||
* @default no fields | ||
*/ | ||
readonly fields: string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters