Skip to content

Commit c897f44

Browse files
authored
feat(docdb): added ability to enable performance insights (#24039)
Added the ability to enable performance insights in the L2 construct for DocumentDB Cluster so it can be enabled programmatically in all instances inside the cluster. > [CONTRIBUTING GUIDE]: https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md > [DESIGN GUIDELINES]: https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md Closes #24036. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7c7ad6d commit c897f44

12 files changed

+131
-34
lines changed

packages/@aws-cdk/aws-docdb/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,23 @@ const cluster = new docdb.DatabaseCluster(this, 'Database', {
161161
cloudWatchLogsRetentionRole: myLogsPublishingRole, // Optional - a role will be created if not provided
162162
});
163163
```
164+
165+
## Enable Performance Insights
166+
167+
By enabling this feature it will be cascaded and enabled in all instances inside the cluster:
168+
169+
```ts
170+
declare const vpc: ec2.Vpc;
171+
172+
const cluster = new docdb.DatabaseCluster(this, 'Database', {
173+
masterUser: {
174+
username: 'myuser',
175+
},
176+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.MEMORY5, ec2.InstanceSize.LARGE),
177+
vpcSubnets: {
178+
subnetType: ec2.SubnetType.PUBLIC,
179+
},
180+
vpc,
181+
enablePerformanceInsights: true, // Enable Performance Insights in all instances under this cluster
182+
});
183+
```

packages/@aws-cdk/aws-docdb/lib/cluster.ts

+8
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ export interface DatabaseClusterProps {
183183
* @default - a new role is created.
184184
*/
185185
readonly cloudWatchLogsRetentionRole?: IRole;
186+
187+
/**
188+
* A value that indicates whether to enable Performance Insights for the instances in the DB Cluster.
189+
*
190+
* @default - false
191+
*/
192+
readonly enablePerformanceInsights?: boolean;
186193
}
187194

188195
/**
@@ -509,6 +516,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
509516
dbInstanceIdentifier: instanceIdentifier,
510517
// Instance properties
511518
dbInstanceClass: databaseInstanceType(props.instanceType),
519+
enablePerformanceInsights: props.enablePerformanceInsights,
512520
});
513521

514522
instance.applyRemovalPolicy(props.removalPolicy, {

packages/@aws-cdk/aws-docdb/lib/instance.ts

+8
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ export interface DatabaseInstanceProps {
165165
* @default RemovalPolicy.Retain
166166
*/
167167
readonly removalPolicy?: cdk.RemovalPolicy
168+
169+
/**
170+
* A value that indicates whether to enable Performance Insights for the DB Instance.
171+
*
172+
* @default - false
173+
*/
174+
readonly enablePerformanceInsights?: boolean;
168175
}
169176

170177
/**
@@ -208,6 +215,7 @@ export class DatabaseInstance extends DatabaseInstanceBase implements IDatabaseI
208215
availabilityZone: props.availabilityZone,
209216
dbInstanceIdentifier: props.dbInstanceName,
210217
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
218+
enablePerformanceInsights: props.enablePerformanceInsights,
211219
});
212220

213221
this.cluster = props.cluster;

packages/@aws-cdk/aws-docdb/test/cluster.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,29 @@ describe('DatabaseCluster', () => {
706706
});
707707
});
708708

709+
test('can enable Performance Insights on instances', () => {
710+
// GIVEN
711+
const stack = testStack();
712+
const vpc = new ec2.Vpc(stack, 'VPC');
713+
714+
// WHEN
715+
new DatabaseCluster(stack, 'Database', {
716+
masterUser: {
717+
username: 'admin',
718+
},
719+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
720+
vpc,
721+
enablePerformanceInsights: true,
722+
});
723+
724+
// THEN
725+
Template.fromStack(stack).hasResource('AWS::DocDB::DBInstance', {
726+
Properties: {
727+
EnablePerformanceInsights: true,
728+
},
729+
});
730+
});
731+
709732
test('single user rotation', () => {
710733
// GIVEN
711734
const stack = testStack();

packages/@aws-cdk/aws-docdb/test/instance.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ describe('DatabaseInstance', () => {
172172
Value: `${instanceEndpointAddress}:${port}`,
173173
});
174174
});
175+
176+
test('can enable performance insights on instances', () => {
177+
// GIVEN
178+
const stack = testStack();
179+
180+
// WHEN
181+
new DatabaseInstance(stack, 'Instance', {
182+
cluster: stack.cluster,
183+
instanceType: SINGLE_INSTANCE_TYPE,
184+
enablePerformanceInsights: true,
185+
});
186+
187+
// THEN
188+
Template.fromStack(stack).hasResource('AWS::DocDB::DBInstance', {
189+
Properties: {
190+
EnablePerformanceInsights: true,
191+
},
192+
});
193+
});
175194
});
176195

177196
class TestStack extends cdk.Stack {

packages/@aws-cdk/aws-docdb/test/integ.cluster.js.snapshot/aws-cdk-docdb-integ.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "20.0.0",
2+
"version": "30.1.0",
33
"files": {
4-
"811c147f8ed74c3803d8df4f44e3f6a7e7779b21e729fc8cb3b66a685054a393": {
4+
"f7cbfe0c634dda7840ec3c05f938c0badf4e3f4f4b183a058b1245d482d019bd": {
55
"source": {
66
"path": "aws-cdk-docdb-integ.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "811c147f8ed74c3803d8df4f44e3f6a7e7779b21e729fc8cb3b66a685054a393.json",
12+
"objectKey": "f7cbfe0c634dda7840ec3c05f938c0badf4e3f4f4b183a058b1245d482d019bd.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-docdb/test/integ.cluster.js.snapshot/aws-cdk-docdb-integ.template.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@
533533
"DBClusterIdentifier": {
534534
"Ref": "DatabaseB269D8BB"
535535
},
536-
"DBInstanceClass": "db.r5.large"
536+
"DBInstanceClass": "db.r5.large",
537+
"EnablePerformanceInsights": true
537538
},
538539
"DependsOn": [
539540
"VPCPublicSubnet1DefaultRoute91CEF279",
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"20.0.0"}
1+
{"version":"30.1.0"}

packages/@aws-cdk/aws-docdb/test/integ.cluster.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "30.1.0",
33
"testCases": {
44
"integ.cluster": {
55
"stacks": [

packages/@aws-cdk/aws-docdb/test/integ.cluster.js.snapshot/manifest.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
2-
"version": "20.0.0",
2+
"version": "30.1.0",
33
"artifacts": {
4-
"Tree": {
5-
"type": "cdk:tree",
6-
"properties": {
7-
"file": "tree.json"
8-
}
9-
},
104
"aws-cdk-docdb-integ.assets": {
115
"type": "cdk:asset-manifest",
126
"properties": {
@@ -23,7 +17,7 @@
2317
"validateOnSynth": false,
2418
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2519
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/811c147f8ed74c3803d8df4f44e3f6a7e7779b21e729fc8cb3b66a685054a393.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f7cbfe0c634dda7840ec3c05f938c0badf4e3f4f4b183a058b1245d482d019bd.json",
2721
"requiresBootstrapStackVersion": 6,
2822
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2923
"additionalDependencies": [
@@ -233,6 +227,12 @@
233227
]
234228
},
235229
"displayName": "aws-cdk-docdb-integ"
230+
},
231+
"Tree": {
232+
"type": "cdk:tree",
233+
"properties": {
234+
"file": "tree.json"
235+
}
236236
}
237237
}
238238
}

packages/@aws-cdk/aws-docdb/test/integ.cluster.js.snapshot/tree.json

+37-20
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
"id": "App",
55
"path": "",
66
"children": {
7-
"Tree": {
8-
"id": "Tree",
9-
"path": "Tree",
10-
"constructInfo": {
11-
"fqn": "constructs.Construct",
12-
"version": "10.1.85"
13-
}
14-
},
157
"aws-cdk-docdb-integ": {
168
"id": "aws-cdk-docdb-integ",
179
"path": "aws-cdk-docdb-integ",
@@ -91,8 +83,8 @@
9183
"id": "Acl",
9284
"path": "aws-cdk-docdb-integ/VPC/PublicSubnet1/Acl",
9385
"constructInfo": {
94-
"fqn": "constructs.Construct",
95-
"version": "10.1.85"
86+
"fqn": "@aws-cdk/core.Resource",
87+
"version": "0.0.0"
9688
}
9789
},
9890
"RouteTable": {
@@ -258,8 +250,8 @@
258250
"id": "Acl",
259251
"path": "aws-cdk-docdb-integ/VPC/PublicSubnet2/Acl",
260252
"constructInfo": {
261-
"fqn": "constructs.Construct",
262-
"version": "10.1.85"
253+
"fqn": "@aws-cdk/core.Resource",
254+
"version": "0.0.0"
263255
}
264256
},
265257
"RouteTable": {
@@ -425,8 +417,8 @@
425417
"id": "Acl",
426418
"path": "aws-cdk-docdb-integ/VPC/PrivateSubnet1/Acl",
427419
"constructInfo": {
428-
"fqn": "constructs.Construct",
429-
"version": "10.1.85"
420+
"fqn": "@aws-cdk/core.Resource",
421+
"version": "0.0.0"
430422
}
431423
},
432424
"RouteTable": {
@@ -544,8 +536,8 @@
544536
"id": "Acl",
545537
"path": "aws-cdk-docdb-integ/VPC/PrivateSubnet2/Acl",
546538
"constructInfo": {
547-
"fqn": "constructs.Construct",
548-
"version": "10.1.85"
539+
"fqn": "@aws-cdk/core.Resource",
540+
"version": "0.0.0"
549541
}
550542
},
551543
"RouteTable": {
@@ -880,7 +872,8 @@
880872
"dbClusterIdentifier": {
881873
"Ref": "DatabaseB269D8BB"
882874
},
883-
"dbInstanceClass": "db.r5.large"
875+
"dbInstanceClass": "db.r5.large",
876+
"enablePerformanceInsights": true
884877
}
885878
},
886879
"constructInfo": {
@@ -893,17 +886,41 @@
893886
"fqn": "@aws-cdk/aws-docdb.DatabaseCluster",
894887
"version": "0.0.0"
895888
}
889+
},
890+
"BootstrapVersion": {
891+
"id": "BootstrapVersion",
892+
"path": "aws-cdk-docdb-integ/BootstrapVersion",
893+
"constructInfo": {
894+
"fqn": "@aws-cdk/core.CfnParameter",
895+
"version": "0.0.0"
896+
}
897+
},
898+
"CheckBootstrapVersion": {
899+
"id": "CheckBootstrapVersion",
900+
"path": "aws-cdk-docdb-integ/CheckBootstrapVersion",
901+
"constructInfo": {
902+
"fqn": "@aws-cdk/core.CfnRule",
903+
"version": "0.0.0"
904+
}
896905
}
897906
},
907+
"constructInfo": {
908+
"fqn": "@aws-cdk/core.Stack",
909+
"version": "0.0.0"
910+
}
911+
},
912+
"Tree": {
913+
"id": "Tree",
914+
"path": "Tree",
898915
"constructInfo": {
899916
"fqn": "constructs.Construct",
900-
"version": "10.1.85"
917+
"version": "10.1.270"
901918
}
902919
}
903920
},
904921
"constructInfo": {
905-
"fqn": "constructs.Construct",
906-
"version": "10.1.85"
922+
"fqn": "@aws-cdk/core.App",
923+
"version": "0.0.0"
907924
}
908925
}
909926
}

packages/@aws-cdk/aws-docdb/test/integ.cluster.ts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class TestStack extends cdk.Stack {
4141
parameterGroup: params,
4242
kmsKey,
4343
removalPolicy: cdk.RemovalPolicy.DESTROY,
44+
enablePerformanceInsights: true,
4445
});
4546

4647
cluster.connections.allowDefaultPortFromAnyIpv4('Open to the world');

0 commit comments

Comments
 (0)