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): Add InstanceParameterGroup #2075

Closed
wants to merge 8 commits into from

Conversation

aereal
Copy link

@aereal aereal commented Mar 22, 2019

refs. #1693


Pull Request Checklist

  • Testing
    • Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
    • CLI change?: coordinate update of integration tests with team
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
  • Title and Description
    • Change type: title prefixed with fix, feat will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

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

/**
* A instance parameter group
*/
export abstract class InstanceParameterGroupRef extends Construct {
Copy link
Contributor

Copy link
Author

Choose a reason for hiding this comment

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

These are imported but not used yet, so just removed them. fixed db1c8f3

*/
protected validate(): string[] {
if (Object.keys(this.parameters).length === 0) {
return ['At least one parameter required, call setParameter().'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Add unit tests for this case.

Copy link
Author

Choose a reason for hiding this comment

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

fixed 9c77fbf

/**
* The parameters in this parameter group
*/
parameters?: Parameters;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why optional?

Is there a @default?

Copy link
Author

Choose a reason for hiding this comment

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

No reason, just followed ClusterParameterGroup. I have no own opinion of this and change this to be required.

Copy link
Author

Choose a reason for hiding this comment

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

fixed ad3d753

*/
export interface InstanceParameterGroupProps {
/**
* Database family of this parameter group
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there more detail? Perhaps a link to some documentation describing what a family is?

Copy link
Author

Choose a reason for hiding this comment

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

fixed 8435164

this.setParameter(key, value);
}

this.parameterGroupName = resource.ref;
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a safe ref on the Resource, e.g. resource.parameterGroupName.

Copy link
Author

Choose a reason for hiding this comment

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

fixed 8a22d7c

@aereal
Copy link
Author

aereal commented Mar 24, 2019

@sam-goodwin

Thank you for review. I pushed some changes, so could you review them?

@sam-goodwin sam-goodwin added the @aws-cdk/aws-rds Related to Amazon Relational Database label Mar 25, 2019
});

for (const [key, value] of Object.entries(parameters || {})) {
this.setParameter(key, value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you worried about using the passed in parameters object? Because you could do the following instead:

this.parameters = props.parameters || {};

*/
public setParameter(key: string, value: string | undefined) {
if (value === undefined && key in this.parameters) {
delete this.parameters[key];
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't overload the setParameter function with delete behavior. We don't support union types in public APIs because they don't translate well to other languages like Java, and it is also a confusing API to call set to delete something.

setParameter is for setting parameters and removeParameter is for removing them, keep it simple.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sam-goodwin I think this PR is based on the existing implementation of the cluster parameter group (https://github.com/awslabs/aws-cdk/blob/master/packages/%40aws-cdk/aws-rds/lib/cluster-parameter-group.ts implemented here #729) which proposes the same approach.

Does you comment mean that the cluster parameter group should also be refactored?

I'm currently working on a PR to support db instances and would like to have your opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

On a second pass, I realize my comment about this union type was incorrect - string | undefined will work fine because it means optional. My mistake.

That said, it does seem confusing to me that we use setParameter to delete a parameter. I wouldn't expect to (for example) use map.put(key, null) to delete a key from a Map in Java. I was unaware of the precedent set in cluster parameter groups. What is the use case for this overloaded behavior?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know, it seems to come from this discussion #729 (comment).

For me it doesn't make sense to have setParameter and removeParameter methods, parameters should be defined directly in the construction props.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. @rix0rrr can you chime in?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might make sense to build the RDS parameters object incrementally, since it can be frking huge (there are many parameters to set!), so I think I might want some function to do:

lessDurabilityMorePerformance(paramGroup);

Or something. But I don't feel super strongly about this, I'm okay with removing the mutators as well.

* Remove a previously-set parameter from this parameter group
*/
public removeParameter(key: string) {
this.setParameter(key, undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

... do the delete work here.

});

// THEN
expect(stack).to(haveResource('AWS::RDS::DBInstance', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you also verify the value of the parameter instance group?


// THEN
test.deepEqual(stack.node.resolve(exported), { parameterGroupName: { 'Fn::ImportValue': 'Stack:ParamsParameterGroupNameA6B808D7' } });
test.deepEqual(stack.node.resolve(imported.parameterGroupName), { 'Fn::ImportValue': 'Stack:ParamsParameterGroupNameA6B808D7' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Validate the stacks. expect(stack).to(haveResource(..)).

new InstanceParameterGroup(stack, 'Params', {
family: 'hello',
description: 'desc',
parameters: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should allow you to create an invalid instance in the first place.

@jogold
Copy link
Contributor

jogold commented Apr 8, 2019

See #2187 where parameter groups are refactored and the changes from this PR could be integrated?

rix0rrr pushed a commit that referenced this pull request May 31, 2019
Specific classes are exposed for a source database instance (`DatabaseInstance`), an instance created from a snapshot (`DatabaseInstanceFromSnapshot`) and a read replica instance (`DatabaseInstanceReadReplica`).

Add construct for option groups and refactor parameter groups.

Add basic support for instance event rules.

Integration with Secrets Manager and secret rotation.

Closes #2075 
Closes #1693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants