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(rds): support Database Insights for Aurora databases #32851

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sakurai-ryo
Copy link
Contributor

@sakurai-ryo sakurai-ryo commented Jan 11, 2025

Issue # (if applicable)

Closes #32680

Reason for this change

AWS announces Amazon CloudWatch Database Insights.
https://aws.amazon.com/about-aws/whats-new/2024/12/amazon-cloudwatch-database-insights

Description of changes

Database Insights has two modes: Standard and Advanced.
For Aurora databases, standard mode is enabled by default.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html#aws-resource-rds-dbcluster-return-values

When using advanced mode, you must enable Performance Insights and set its data retention period to 465 days.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Database-Insights.html

Describe any new or updated permissions being added

Nothing.

Description of how you validated changes

Unit tests and integ-tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the star-contributor [Pilot] contributed between 25-49 PRs to the CDK label Jan 11, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team January 11, 2025 11:11
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Jan 11, 2025
Copy link

codecov bot commented Jan 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.38%. Comparing base (9317203) to head (9ed3e5e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32851   +/-   ##
=======================================
  Coverage   81.38%   81.38%           
=======================================
  Files         222      222           
  Lines       13695    13695           
  Branches     2412     2412           
=======================================
  Hits        11145    11145           
  Misses       2271     2271           
  Partials      279      279           
Flag Coverage Δ
suite.unit 81.38% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 80.69% <ø> (ø)
packages/aws-cdk-lib/core 82.09% <ø> (ø)

}

// Database Insights is not supported for non-Aurora engines
if (props.databaseInsightsMode && !props.engine.engineType.startsWith('aurora')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, DatabaseClusterEngine only supports Aurora engines, but AWS::RDS::DBCluster supports standard MySQL and PostgreSQL engines.
Database Insights only supports Aurora engines, so I added validation here, just in case.

#25547

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 9ed3e5e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 11, 2025
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍 Left comments for minor adjustments

if (enablePerformanceInsights && props.enablePerformanceInsights === false) {
throw new Error('`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set');
throw new Error('`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set, or `databaseInsightsMode` was set to `DatabaseInsightsMode.ADVANCED`');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error('`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set, or `databaseInsightsMode` was set to `DatabaseInsightsMode.ADVANCED`');
throw new Error('`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set, or `databaseInsightsMode` was set to \'${DatabaseInsightsMode.ADVANCED}\'`');

Let's use the variable value for clarity.

&& props.performanceInsightRetention
&& props.performanceInsightRetention !== PerformanceInsightRetention.MONTHS_15
) {
throw new Error('`performanceInsightRetention` must be set to PerformanceInsightRetention.MONTHS_15 when `databaseInsightsMode` is set to DatabaseInsightsMode.ADVANCED');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error('`performanceInsightRetention` must be set to PerformanceInsightRetention.MONTHS_15 when `databaseInsightsMode` is set to DatabaseInsightsMode.ADVANCED');
throw new Error('`performanceInsightRetention` must be set to \'${PerformanceInsightRetention.MONTHS_15}\' when `databaseInsightsMode` is set to \'${DatabaseInsightsMode.ADVANCED}\'');

Same as above.

Comment on lines +559 to +560
*
* In advanced mode, Performance Insights must be enabled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*
* In advanced mode, Performance Insights must be enabled.

The current implementation is enabling insights automatically when DatabaseInsightsMode.ADVANCED

Comment on lines +431 to +432
* @default - 7(PerformanceInsightRetention.DEFAULT) if `enablePerformanceInsights` is set,
* 465(PerformanceInsightRetention.MONTHS_15) if DatabaseInsightsMode.ADVANCED is set for `databaseInsightsMode`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @default - 7(PerformanceInsightRetention.DEFAULT) if `enablePerformanceInsights` is set,
* 465(PerformanceInsightRetention.MONTHS_15) if DatabaseInsightsMode.ADVANCED is set for `databaseInsightsMode`.
* @default - 7 days if `enablePerformanceInsights` is set. 465 days (15 months) if `databaseInsightsMode` is set to DatabaseInsightsMode.ADVANCED.

throw new Error('`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set, or `databaseInsightsMode` was set to `DatabaseInsightsMode.ADVANCED`');
}
if (props.databaseInsightsMode === DatabaseInsightsMode.ADVANCED
&& props.performanceInsightRetention
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. Could automatically setting retention to 15 months cause unexpected billing to customers unaware of the longer period? If so, it may be better to enforce performanceInsightRetention being set manually to PerformanceInsightRetention.MONTHS_15.

/**
* The database insights mode.
*
* @default - DatabaseInsightsMode.STANDARD if Amazon Aurora engine is used, otherwise not set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @default - DatabaseInsightsMode.STANDARD if Amazon Aurora engine is used, otherwise not set.
* @default - DatabaseInsightsMode.STANDARD when performance insights are enabled and Amazon Aurora engine is used, otherwise not set.

Comment on lines +1382 to +1408
The standard mode of Database Insights is enabled by default for Aurora databases.

You can enhance the monitoring of your Aurora databases by enabling the advanced mode of Database Insights.

See [AWS docs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Database-Insights.html) for more information about Database Insights.

The following example shows enabling the advanced mode of Database Insights for a clustered database.

```ts
declare const vpc: ec2.Vpc;
new rds.DatabaseCluster(this, 'Database', {
engine: rds.DatabaseClusterEngine.AURORA,
vpc: vpc,
// If you enable the advanced mode of Database Insights,
// Performance Insights is enabled and the retention period of Performance Insights data is set to 465(15 months).
databaseInsightsMode: rds.DatabaseInsightsMode.ADVANCED,
writer: rds.ClusterInstance.provisioned('Writer', {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R7G, ec2.InstanceSize.LARGE),
}),
});
```

Note that settings regarding Database Insights are only possible at the cluster level.

### Supported Engines

Database Insights supports Amazon Aurora MySQL and Amazon Aurora PostgreSQL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The standard mode of Database Insights is enabled by default for Aurora databases.
You can enhance the monitoring of your Aurora databases by enabling the advanced mode of Database Insights.
See [AWS docs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Database-Insights.html) for more information about Database Insights.
The following example shows enabling the advanced mode of Database Insights for a clustered database.
```ts
declare const vpc: ec2.Vpc;
new rds.DatabaseCluster(this, 'Database', {
engine: rds.DatabaseClusterEngine.AURORA,
vpc: vpc,
// If you enable the advanced mode of Database Insights,
// Performance Insights is enabled and the retention period of Performance Insights data is set to 465(15 months).
databaseInsightsMode: rds.DatabaseInsightsMode.ADVANCED,
writer: rds.ClusterInstance.provisioned('Writer', {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R7G, ec2.InstanceSize.LARGE),
}),
});
```
Note that settings regarding Database Insights are only possible at the cluster level.
### Supported Engines
Database Insights supports Amazon Aurora MySQL and Amazon Aurora PostgreSQL.
The standard mode of Database Insights is enabled by default for Aurora databases.
You can enhance the monitoring of your Aurora databases by enabling the advanced mode of Database Insights.
To control Database Insights mode, use the `databaseInsightsMode` property:
```ts
declare const vpc: ec2.Vpc;
new rds.DatabaseCluster(this, 'Database', {
engine: rds.DatabaseClusterEngine.AURORA,
vpc: vpc,
// If you enable the advanced mode of Database Insights,
// Performance Insights is enabled and the retention period of Performance Insights data is set to 465(15 months).
databaseInsightsMode: rds.DatabaseInsightsMode.ADVANCED,
writer: rds.ClusterInstance.provisioned('Writer', {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R7G, ec2.InstanceSize.LARGE),
}),
});

Note: Database Insights are only supported for Amazon Aurora MySQL and Amazon Aurora PostgreSQL clusters.

Visit CloudWatch Database Insights for more details.

Feel free to improve further 👍

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(rds): add support for database insights
3 participants