Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docdb): added ability to enable performance insights #24039

Merged
merged 8 commits into from Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-docdb/README.md
Expand Up @@ -161,3 +161,23 @@ const cluster = new docdb.DatabaseCluster(this, 'Database', {
cloudWatchLogsRetentionRole: myLogsPublishingRole, // Optional - a role will be created if not provided
});
```

## Enable Performance Insights

By enabling this feature it will be cascaded and enabled in all instances inside the cluster:

```ts
declare const vpc: ec2.Vpc;

const cluster = new docdb.DatabaseCluster(this, 'Database', {
masterUser: {
username: 'myuser',
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.MEMORY5, ec2.InstanceSize.LARGE),
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
vpc,
enablePerformanceInsights: true, // Enable Performance Insights in all instances under this cluster
});
```
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-docdb/lib/cluster.ts
Expand Up @@ -183,6 +183,13 @@ export interface DatabaseClusterProps {
* @default - a new role is created.
*/
readonly cloudWatchLogsRetentionRole?: IRole;

/**
* A value that indicates whether to enable Performance Insights for the instances in the DB Cluster.
*
* @default - false
*/
readonly enablePerformanceInsights?: boolean;
}

/**
Expand Down Expand Up @@ -509,6 +516,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
dbInstanceIdentifier: instanceIdentifier,
// Instance properties
dbInstanceClass: databaseInstanceType(props.instanceType),
enablePerformanceInsights: props.enablePerformanceInsights,
});

instance.applyRemovalPolicy(props.removalPolicy, {
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-docdb/lib/instance.ts
Expand Up @@ -165,6 +165,13 @@ export interface DatabaseInstanceProps {
* @default RemovalPolicy.Retain
*/
readonly removalPolicy?: cdk.RemovalPolicy

/**
* A value that indicates whether to enable Performance Insights for the DB Instance.
*
* @default - false
*/
readonly enablePerformanceInsights?: boolean;
}

/**
Expand Down Expand Up @@ -208,6 +215,7 @@ export class DatabaseInstance extends DatabaseInstanceBase implements IDatabaseI
availabilityZone: props.availabilityZone,
dbInstanceIdentifier: props.dbInstanceName,
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
enablePerformanceInsights: props.enablePerformanceInsights,
});

this.cluster = props.cluster;
Expand Down
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-docdb/test/cluster.test.ts
Expand Up @@ -706,6 +706,29 @@ describe('DatabaseCluster', () => {
});
});

test('can enable Performance Insights on instances', () => {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
masterUser: {
username: 'admin',
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
vpc,
enablePerformanceInsights: true,
});

// THEN
Template.fromStack(stack).hasResource('AWS::DocDB::DBInstance', {
Properties: {
EnablePerformanceInsights: true,
},
});
});

test('single user rotation', () => {
// GIVEN
const stack = testStack();
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-docdb/test/instance.test.ts
Expand Up @@ -172,6 +172,25 @@ describe('DatabaseInstance', () => {
Value: `${instanceEndpointAddress}:${port}`,
});
});

test('can enable performance insights on instances', () => {
// GIVEN
const stack = testStack();

// WHEN
new DatabaseInstance(stack, 'Instance', {
cluster: stack.cluster,
instanceType: SINGLE_INSTANCE_TYPE,
enablePerformanceInsights: true,
});

// THEN
Template.fromStack(stack).hasResource('AWS::DocDB::DBInstance', {
Properties: {
EnablePerformanceInsights: true,
},
});
});
});

class TestStack extends cdk.Stack {
Expand Down