Skip to content

Commit

Permalink
fix(neptune-alpha): multiple cloudwatchLogsExports cannot be set wh…
Browse files Browse the repository at this point in the history
…en configuring log retention (#28643)

This PR includes a breaking change to the aws-neptune-alpha module.

I have resolved an issue where it was not possible to set multiple `cloudwatchLogsExports` when configuring log retention for a `DatabaseCluster`.

The root cause of the problem was that the LogRetention creation included `[object object]` in the construct's ID. With the current fix, the given `logType` can now be correctly included in the `LogRetention`.
```diff
- new logs.LogRetention(this, `${logType}LogRetention`, {..} // "DatabaseobjectObjectLogRetentionA247AF0C"
+ new logs.LogRetention(this, `${logType.value}LogRetention`, {..} // "DatabaseauditLogRetention8A29F5CC"
```

BREAKING CHANGE: Corrected LogRetention IDs for DatabaseCluster. Previously, regardless of the log type, the string ‘objectObject’ was always included, but after the correction, the log type is now included.


Closes #26295.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
badmintoncryer authored and SankyRed committed Feb 8, 2024
1 parent c459d72 commit d9401db
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 462 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-neptune-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
const retention = props.cloudwatchLogsRetention;
if (retention) {
props.cloudwatchLogsExports?.forEach(logType => {
new logs.LogRetention(this, `${logType}LogRetention`, {
new logs.LogRetention(this, `${logType.value}LogRetention`, {
logGroupName: `/aws/neptune/${this.clusterIdentifier}/${logType.value}`,
role: props.cloudwatchLogsRetentionRole,
retention,
Expand Down
49 changes: 49 additions & 0 deletions packages/@aws-cdk/aws-neptune-alpha/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,55 @@ describe('DatabaseCluster', () => {
});
}).toThrow(/ServerlessScalingConfiguration minCapacity 10 must be less than serverlessScalingConfiguration maxCapacity 5/);
});

test('cloudwatchLogsExports log retention is enabled when configured for multiple logs exports', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Cluster', {
vpc,
instanceType: InstanceType.R5_LARGE,
cloudwatchLogsExports: [LogType.AUDIT, new LogType('slowquery')],
cloudwatchLogsRetention: logs.RetentionDays.ONE_MONTH,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Neptune::DBCluster', {
EnableCloudwatchLogsExports: ['audit', 'slowquery'],
});
Template.fromStack(stack).hasResourceProperties('Custom::LogRetention', {
LogGroupName: {
'Fn::Join': [
'',
[
'/aws/neptune/',
{
Ref: 'ClusterEB0386A7',
},
'/audit',
],
],
},
RetentionInDays: 30,
});
Template.fromStack(stack).hasResourceProperties('Custom::LogRetention', {
LogGroupName: {
'Fn::Join': [
'',
[
'/aws/neptune/',
{
Ref: 'ClusterEB0386A7',
},
'/slowquery',
],
],
},
RetentionInDays: 30,
});
});
});

function testStack() {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
"Type": "AWS::Neptune::DBClusterParameterGroup",
"Properties": {
"Description": "A nice parameter group",
"Family": "neptune1",
"Family": "neptune1.2",
"Parameters": {
"neptune_enable_audit_log": "1",
"neptune_query_timeout": "100000"
Expand Down Expand Up @@ -505,6 +505,7 @@
"EnableCloudwatchLogsExports": [
"audit"
],
"EngineVersion": "1.2.1.0",
"KmsKeyId": {
"Fn::GetAtt": [
"DbSecurity381C2C15",
Expand All @@ -524,7 +525,7 @@
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"DatabaseobjectObjectLogRetentionA247AF0C": {
"DatabaseauditLogRetention8A29F5CC": {
"Type": "Custom::LogRetention",
"Properties": {
"ServiceToken": {
Expand Down Expand Up @@ -631,7 +632,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "a8515c042d9c942705087943220417be929ac44f968d8fcef2681681b400c0c0.zip"
"S3Key": "e4afb15788ec44ed9ff3377e1d131ba2768d7b2e2931bc000d1f2005879b3035.zip"
},
"Role": {
"Fn::GetAtt": [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d9401db

Please sign in to comment.