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 performance insights configuration at cluster level #31385

Merged
merged 18 commits into from
Oct 15, 2024

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Sep 10, 2024

Issue # (if applicable)

Closes #31375 .

Reason for this change

Properties for Performance Insights at cluster level are supported in L1, but not in L2.

Description of changes

Added the properties in props for Database Cluster.

Description of how you validated changes

Both 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 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Sep 10, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team September 10, 2024 09:26
@github-actions github-actions bot added the distinguished-contributor [Pilot] contributed 50+ PRs to the CDK label Sep 10, 2024
@go-to-k go-to-k changed the title feat(rds): support performance insights for cluster feat(rds): support performance insights configuration for cluster Sep 10, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@go-to-k go-to-k changed the title feat(rds): support performance insights configuration for cluster feat(rds): support performance insights configuration at cluster level Sep 10, 2024
@go-to-k go-to-k marked this pull request as ready for review September 10, 2024 11:52
@go-to-k go-to-k marked this pull request as draft September 10, 2024 11:54
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 10, 2024 13:00

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@go-to-k go-to-k marked this pull request as ready for review September 10, 2024 14:15
@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 Sep 10, 2024
@go-to-k go-to-k marked this pull request as draft September 11, 2024 05:37
@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 Sep 11, 2024
@go-to-k go-to-k marked this pull request as ready for review September 11, 2024 14:20
@@ -476,14 +476,14 @@ to use for the instance:
declare const vpc: ec2.Vpc;

const iopsInstance = new rds.DatabaseInstance(this, 'IopsInstance', {
engine: rds.DatabaseInstanceEngine.mysql({ version: rds.MysqlEngineVersion.VER_8_0_30 }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

VER_8_0_30 is deprecated.

Comment on lines 1278 to 1279
However, if Performance Insights is enabled at the cluster level, it is not possible to specify a different value for the instance
level than the cluster level.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If Performance Insights was enabled at cluster and instance level, and the values of the performanceInsightRetention or performanceInsightEncryptionKey were different for the cluster and the instance, CFn failed.

If performanceInsightRetentions are different, CFn occurred:

Resource handler returned message: "PerformanceInsightsRetentionPeriod conflicts with cluster level parameter. ...“

If performanceInsightEncryptionKeys are different, CFn occurred:

Resource handler returned message: "PerformanceInsightsKMSKeyId conflicts with cluster level parameter. …”

However, if Performance Insights was enabled at cluster and instance level and the values were the same for the cluster and the instance, CFn did not fail.

If the value of enablePerformanceInsights was different for the cluster and the instance, it did not result in an error. If it was true in the cluster and false in the instance, it did not result in an error but was also enabled in the instance.

===

I wanted to implement validation of this behaviour. However, the instance does not have Performance Insights settings publicly, so it is not accessible from the cluster. Therefore, to implement validation, the structure of the instances had to be changed significantly, so I decided not to do it in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

the structure of the instances had to be changed significantly,

Isn't exposing the props in AuroraClusterInstance and adding validation in validateClusterInstances enough? 🤔

Copy link
Contributor Author

@go-to-k go-to-k Sep 17, 2024

Choose a reason for hiding this comment

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

I added the validation, what do you think?

The cluster has a writer and readers as IAuroraClusterInstance not AuroraClusterInstance, so I added the variable performanceInsightsEnabled in IAuroraClusterInstance interface.

And the legacyCreateInstances function for the database cluster is not a method, I also added a public variable performanceInsightsEnabled in DatabaseClusterNew.

@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 Sep 11, 2024
packages/aws-cdk-lib/aws-rds/lib/cluster.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-rds/test/cluster.test.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-rds/README.md Outdated Show resolved Hide resolved
Comment on lines 1278 to 1279
However, if Performance Insights is enabled at the cluster level, it is not possible to specify a different value for the instance
level than the cluster level.
Copy link
Contributor

Choose a reason for hiding this comment

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

the structure of the instances had to be changed significantly,

Isn't exposing the props in AuroraClusterInstance and adding validation in validateClusterInstances enough? 🤔

@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 Sep 15, 2024
@go-to-k
Copy link
Contributor Author

go-to-k commented Sep 17, 2024

@lpizzinidev

Thanks for your review.
I have made the changes, so could you please take a look at them?

packages/aws-cdk-lib/aws-rds/lib/cluster.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-rds/lib/cluster.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-rds/README.md Outdated Show resolved Hide resolved
throw new Error(`\`performanceInsightEncryptionKey\` for each instance must be the same as the one at cluster level, got instance '${instance.node.id}': '${instance.performanceInsightEncryptionKey.keyArn}', cluster: '${this.performanceInsightEncryptionKey.keyArn}'`);
}
// Even if both of cluster and instance keys are unresolved, check if they are the same token.
if (compared === TokenComparison.BOTH_UNRESOLVED && clusterKeyArn !== instanceKeyArn) {
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 the validity of this condition 🤔
Given that we're already ignoring the ONE_UNRESOLVED case, we could maybe skip the check for BOTH_UNRESOLVED as well

Copy link
Contributor Author

@go-to-k go-to-k Sep 18, 2024

Choose a reason for hiding this comment

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

I was certainly wondering about this myself because I had never seen such an implementation. However, I thought that if only one of the values is a token, it is impossible to compare them in any way, but if both are tokens, they can be compared by check whether both are the same token.

I thought that excluding this case would diminish the validation as it would mean skipping the most common cases, such as the following. What do you think?

new DatabaseCluster(stack, 'Database', {
  engine: DatabaseClusterEngine.AURORA,
  vpc,
  performanceInsightEncryptionKey: new kms.Key(stack, 'Key1'),
  writer: ClusterInstance.provisioned('writer', {
    performanceInsightEncryptionKey: new kms.Key(stack, 'Key2'),
  }),
});

packages/aws-cdk-lib/aws-rds/lib/cluster.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-rds/test/cluster.test.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-rds/test/cluster.test.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-rds/test/cluster.test.ts Outdated Show resolved Hide resolved
@go-to-k
Copy link
Contributor Author

go-to-k commented Sep 19, 2024

@lpizzinidev

I have reflected on your points and replied to them, could you take another look at them?

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 Sep 24, 2024
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.

Thanks for contributing! Left some minor feedbacks

Comment on lines +442 to +456

/**
* Whether Performance Insights is enabled
*/
readonly performanceInsightsEnabled?: boolean;

/**
* The amount of time, in days, to retain Performance Insights data.
*/
readonly performanceInsightRetention?: PerformanceInsightRetention;

/**
* The AWS KMS key for encryption of Performance Insights data.
*/
readonly performanceInsightEncryptionKey?: kms.IKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do they need to be introduced in the interface?

Copy link
Contributor Author

@go-to-k go-to-k Oct 11, 2024

Choose a reason for hiding this comment

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

The reason for this is that in order to validate instance's settings in the DatabaseClusterNew class, the properties need to be added to the interface. Otherwise, the class cannot access the properties.

see: #31385 (comment)

The writer and reader variables are not class type but the interface type (IAuroraClusterInstance), so added to the interface.

  /**
   * Perform validations on the cluster instances
   */
  private validateClusterInstances(writer: IAuroraClusterInstance, readers: IAuroraClusterInstance[]): void {
    if (writer.type === InstanceType.SERVERLESS_V2) {
      this.hasServerlessInstance = true;
    }
    validatePerformanceInsightsSettings(this, {
      nodeId: writer.node.id,
      performanceInsightsEnabled: writer.performanceInsightsEnabled,
      performanceInsightRetention: writer.performanceInsightRetention,
      performanceInsightEncryptionKey: writer.performanceInsightEncryptionKey,
    });

Comment on lines +505 to +509
this.performanceInsightsEnabled = enablePerformanceInsights;
this.performanceInsightRetention = enablePerformanceInsights
? (props.performanceInsightRetention || PerformanceInsightRetention.DEFAULT)
: undefined;
this.performanceInsightEncryptionKey = props.performanceInsightEncryptionKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed instead of the old way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just to set it to new variables added to the AuroraClusterInstance instance variables.

L467-469

  public readonly performanceInsightsEnabled: boolean;
  public readonly performanceInsightRetention?: PerformanceInsightRetention;
  public readonly performanceInsightEncryptionKey?: kms.IKey;

Comment on lines +1571 to +1574
Annotations.of(cluster).addWarningV2(
'@aws-cdk/aws-rds:instancePerformanceInsightsOverridden',
`Performance Insights is enabled on cluster '${cluster.node.id}' at cluster level, but disabled for ${target}. `+
'However, Performance Insights for this instance will also be automatically enabled if enabled at cluster level.',
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just throw an error here to match the bebhaviour with the bottom checks?

Copy link
Contributor Author

@go-to-k go-to-k Oct 11, 2024

Choose a reason for hiding this comment

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

CFn can deploy with this configuration. It just means that the instance configuration is overridden by the Aurora service layer not CFn.

If it can be deployed as the correct behaviour in CFn but not in CDK, it will block valid deployments. This is why I have made it a warning here.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's good to know. I agree with your approach instead if it's deployable.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 10, 2024
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

Copy link
Contributor

mergify bot commented Oct 15, 2024

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: 3b39874
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 7d6bf77 into aws:main Oct 15, 2024
9 checks passed
Copy link
Contributor

mergify bot commented Oct 15, 2024

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

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 Oct 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(rds): add performanceInisghts configuration at cluster level
4 participants