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

Merged
merged 12 commits into from
Feb 7, 2025

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 80.83%. Comparing base (3490d2e) to head (994fa23).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32851   +/-   ##
=======================================
  Coverage   80.83%   80.83%           
=======================================
  Files         236      236           
  Lines       14251    14251           
  Branches     2490     2490           
=======================================
  Hits        11520    11520           
  Misses       2446     2446           
  Partials      285      285           
Flag Coverage Δ
suite.unit 80.83% <ø> (ø)

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

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

}

// 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 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

&& 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly, we should avoid situations where there are unintended costs to the user.
28bab16

/**
* 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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
@sakurai-ryo
Copy link
Contributor Author

@lpizzinidev
Thank you for the review.
Could you please review this PR again?

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 👍

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 14, 2025
GavinZZ
GavinZZ previously approved these changes Feb 3, 2025
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Copy link
Contributor

mergify bot commented Feb 3, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@GavinZZ
Copy link
Contributor

GavinZZ commented Feb 5, 2025

@sakurai-ryo can you fix the merge conflicts when available? I've approved this PR.

@mergify mergify bot dismissed GavinZZ’s stale review February 6, 2025 09:58

Pull request has been modified.

@sakurai-ryo
Copy link
Contributor Author

@mergify update

Copy link
Contributor

mergify bot commented Feb 6, 2025

update

☑️ Nothing to do

  • #commits-behind > 0 [📌 update requirement]
  • -closed [📌 update requirement]
  • -conflict [📌 update requirement]
  • queue-position = -1 [📌 update requirement]

GavinZZ
GavinZZ previously approved these changes Feb 6, 2025
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 6, 2025
Copy link
Contributor

mergify bot commented Feb 6, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

mergify bot commented Feb 7, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@GavinZZ
Copy link
Contributor

GavinZZ commented Feb 7, 2025

@Mergifyio requeue

Copy link
Contributor

mergify bot commented Feb 7, 2025

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

Copy link
Contributor

mergify bot commented Feb 7, 2025

This pull request has been removed from the queue for the following reason: pull request branch update failed.

The pull request can't be updated

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@mergify mergify bot dismissed GavinZZ’s stale review February 7, 2025 19:38

Pull request has been modified.

Copy link
Contributor

mergify bot commented Feb 7, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit f6ed4be into aws:main Feb 7, 2025
20 checks passed
Copy link
Contributor

mergify bot commented Feb 7, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link

github-actions bot commented Feb 7, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
4 participants