-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(kinesisfirehose-destinations): refactor logging to combine logG…
…roup and logging properties into loggingConfig (#31488) ### Reason for this change The `logging` and `logGroup` properties contain a restriction where a `logGroup` cannot be provided if `logging` is set to `false`. This was previously handled by error handling but we want to change this to make it impossible for a user to run into that scenario in the first place. ### Description of changes BREAKING CHANGE: the `logging` and `logGroup` properties in `DestinationLoggingProps` have been removed and replaced with a single optional property `loggingConfig` which accepts a class of type `LoggingConfig`. #### Details Combine the `logging` and `logGroup` properties into a single new optional property called `loggingConfig` which accepts a class of type `LoggingConfig`. `LoggingConfig` is an abstract class which can be instantiated through either an instance of `EnableLogging` or `DisableLogging` which can be used in the following 3 ways: ```ts import * as logs from 'aws-cdk-lib/aws-logs'; const logGroup = new logs.LogGroup(this, 'Log Group'); declare const bucket: s3.Bucket; // 1. Enable logging with no parameters - a log group will be created for you const destinationWithLogging = new destinations.S3Bucket(bucket, { loggingConfig: new destinations.EnableLogging(), }); // 2. Enable a logging and pass in a logGroup to be used const destinationWithLoggingAndMyLogGroup = new destinations.S3Bucket(bucket, { loggingConfig: new destinations.EnableLogging(logGroup), }); // 3. Disable logging (does not accept any parameters so it is now impossible to provide a logGroup in this case) const destinationWithoutLogging = new destinations.S3Bucket(bucket, { loggingConfig: new destinations.DisableLogging(), }); ``` ### Description of how you validated changes unit + 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* …yptionKey
- Loading branch information
Showing
8 changed files
with
84 additions
and
54 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/lib/index.ts
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './common'; | ||
export * from './s3-bucket'; | ||
export * from './logging-config'; |
55 changes: 55 additions & 0 deletions
55
packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/lib/logging-config.ts
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,55 @@ | ||
import * as logs from 'aws-cdk-lib/aws-logs'; | ||
|
||
/** | ||
* Configuration interface for logging errors when data transformation or delivery fails. | ||
* | ||
* This interface defines whether logging is enabled and optionally allows specifying a | ||
* CloudWatch Log Group for storing error logs. | ||
*/ | ||
export interface ILoggingConfig { | ||
/** | ||
* If true, log errors when data transformation or data delivery fails. | ||
* | ||
* `true` when using `EnableLogging`, `false` when using `DisableLogging`. | ||
*/ | ||
readonly logging: boolean; | ||
|
||
/** | ||
* The CloudWatch log group where log streams will be created to hold error logs. | ||
* | ||
* @default - if `logging` is set to `true`, a log group will be created for you. | ||
*/ | ||
readonly logGroup?: logs.ILogGroup; | ||
} | ||
|
||
/** | ||
* Enables logging for error logs with an optional custom CloudWatch log group. | ||
* | ||
* When this class is used, logging is enabled (`logging: true`) and | ||
* you can optionally provide a CloudWatch log group for storing the error logs. | ||
* | ||
* If no log group is provided, a default one will be created automatically. | ||
*/ | ||
export class EnableLogging implements ILoggingConfig { | ||
public readonly logGroup?: logs.ILogGroup; | ||
public readonly logging: boolean; | ||
|
||
constructor(logGroup?: logs.ILogGroup) { | ||
this.logGroup = logGroup; | ||
this.logging = true; | ||
} | ||
} | ||
|
||
/** | ||
* Disables logging for error logs. | ||
* | ||
* When this class is used, logging is disabled (`logging: false`) | ||
* and no CloudWatch log group can be specified. | ||
*/ | ||
export class DisableLogging implements ILoggingConfig { | ||
public readonly logging: boolean; | ||
|
||
constructor() { | ||
this.logging = false; | ||
} | ||
} |
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
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