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

fix(deadline): lock down DocDC engine to version 3.6.0 #230

Merged
merged 4 commits into from
Nov 20, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def __init__(self, scope: Construct, stack_id: str, *, props: StorageTierDocDBPr
# It is recommended that when creating your render farm you use at least 2 instances for redundancy.
instances=1,
master_user=Login(username='adminuser'),
engine_version='3.6.0',
backup=BackupProps(
# We recommend setting the retention of your backups to 15 days
# for security reasons. The default retention is just one day.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class StorageTierDocDB extends StorageTier {
masterUser: {
username: 'adminuser',
},
engineVersion: '3.6.0',
backup: {
// We recommend setting the retention of your backups to 15 days
// for security reasons. The default retention is just one day.
Expand Down
1 change: 1 addition & 0 deletions integ/lib/storage-struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class StorageStruct extends Construct {
masterUser: {
username: 'DocDBUser',
},
engineVersion: '3.6.0',
backup: {
retention: Duration.days(15),
},
Expand Down
25 changes: 25 additions & 0 deletions packages/aws-rfdk/lib/deadline/lib/database-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as path from 'path';
import {
CfnDBCluster,
CfnDBInstance,
IDatabaseCluster,
} from '@aws-cdk/aws-docdb';
Expand All @@ -22,6 +23,7 @@ import {
ISecret,
} from '@aws-cdk/aws-secretsmanager';
import {
Annotations,
IConstruct,
Stack,
} from '@aws-cdk/core';
Expand Down Expand Up @@ -163,6 +165,10 @@ class DocDBDatabaseConnection extends DatabaseConnection {
constructor(private readonly props: DocDBConnectionOptions) {
super();

if (!this.isCompatibleDocDBVersion()) {
Annotations.of(props.database).addError('engineVersion must be 3.6.0 to be compatible with Deadline');
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as below. Should we relax this message to 3.6.x

Copy link
Contributor

Choose a reason for hiding this comment

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

This still says 3.6.0 but our other messaging and the version check all use 3.6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I discussed this with Josh offline. DocumentDB doesn't do patch-level versions. It will always be 3.6.0

}

this.containerEnvironment = {
// The container must fetch the credentials from Secrets Manager
DB_CREDENTIALS_URI: this.props.login.secretArn,
Expand Down Expand Up @@ -256,6 +262,25 @@ class DocDBDatabaseConnection extends DatabaseConnection {
throw new Error('The internal implementation of the AWS CDK\'s DocumentDB cluster construct may have changed. Please update to a newer RFDK for an updated implementation, or file a ticket if this is the latest release.');
}
}

/**
* Deadline is only compatible with MongoDB 3.6. This function attempts to determine whether
* the given DocDB version is compatible.
*/
protected isCompatibleDocDBVersion(): boolean {
// The defaultChild of a DocDB DatabaseCluster is a CfnDBCluster, but we only have this
// child if the customer didn't import from attributes. We can check the DB version by
// checking the value of the engineVersion property of that object.
if (this.props.database.node.defaultChild) {
const cluster = this.props.database.node.defaultChild! as CfnDBCluster;
if (cluster.engineVersion === '3.6.0') {
return true;
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. I'm just thinking in the event that DocDB issues a patch version for 3.6. Just in case, should we relax the final version component here? So:

return cluster.engineVersion.startsWith('3.6.');

It looks like RDS has patch engine versions for other DB types:

$ aws docdb describe-db-engine-versions --engine mariadb --engine-version 10.0.17
{
    "DBEngineVersions": [
        {
            "Engine": "mariadb",
            "EngineVersion": "10.0.17",
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No harm in doing that, though the DocDB service team will never have any 3.6 value other than 3.6.0 and similarly, no 4.0 other than 4.0.0. They specifically don't do patch versions.

}

return true; // No information, assume it's compatible.
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-rfdk/lib/deadline/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export interface RepositoryProps {

/**
* Specify the database where the deadline schema needs to be initialized.
* Note that Deadline supports only databases that are compatible with MongoDB 3.6.
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks great. I had also suggested adding something to the TSDoc string of DatabaseConnection.forDocDB too. Perhaps even DocDBConnectionOptions.database. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, right. Sure. I can add something there...

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment for DocDBConnectionOptions.database wasn't updated, do we need that too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added those too in latest rev.

*
* @default A Document DB Cluster will be created with a single db.r5.large instance.
*/
Expand Down Expand Up @@ -490,6 +491,7 @@ export class Repository extends Construct implements IRepository {
const instances = props.documentDbInstanceCount ?? Repository.DEFAULT_NUM_DOCDB_INSTANCES;
const dbCluster = new DatabaseCluster(this, 'DocumentDatabase', {
masterUser: {username: 'DocDBUser'},
engineVersion: '3.6.0',
Copy link
Contributor

Choose a reason for hiding this comment

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

Two things:

  1. This is good for the case where props.database is not supplied, but is it possible to add validation that the engine is correct for the code path where a caller specifies their own cluster and fail-fast?
  2. Can we add a test for this new behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a good idea. I'll see what I can cobble together.

instanceProps: {
instanceType: InstanceType.of(InstanceClass.R5, InstanceSize.LARGE),
vpc: props.vpc,
Expand Down
137 changes: 137 additions & 0 deletions packages/aws-rfdk/lib/deadline/test/database-connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import {
PrivateHostedZone,
} from '@aws-cdk/aws-route53';
import { Secret } from '@aws-cdk/aws-secretsmanager';
import {
Duration,
Stack,
Expand Down Expand Up @@ -77,6 +78,7 @@ describe('DocumentDB', () => {
backup: {
retention: Duration.days(15),
},
engineVersion: '3.6.0',
});

if (!database.secret) {
Expand Down Expand Up @@ -264,6 +266,141 @@ describe('DocumentDB', () => {

});

describe('DocumentDB Version Checks', () => {
let stack: Stack;
let vpc: Vpc;
beforeEach(() => {
stack = new Stack();
vpc = new Vpc(stack, 'VPC');
});

test('Compatible version', () => {
// GIVEN
const database = new DatabaseCluster(stack, 'DbCluster', {
masterUser: {
username: 'master',
},
instanceProps: {
instanceType: InstanceType.of(
InstanceClass.R5,
InstanceSize.XLARGE,
),
vpc,
vpcSubnets: {
onePerAz: true,
subnetType: SubnetType.PRIVATE,
},
},
backup: {
retention: Duration.days(15),
},
engineVersion: '3.6.0',
});

// WHEN
DatabaseConnection.forDocDB({database, login: database.secret!});

// THEN
expect(database.node.metadata.length).toBe(0);
});

test('When from attributes', () => {
// GIVEN
const sg = new SecurityGroup(stack, 'SG', {
vpc,
});
const secret = new Secret(stack, 'Secret');
const database = DatabaseCluster.fromDatabaseClusterAttributes(stack, 'DbCluster', {
clusterEndpointAddress: '1.2.3.4',
clusterIdentifier: 'foo',
instanceEndpointAddresses: [ '1.2.3.5' ],
instanceIdentifiers: [ 'i0' ],
port: 27001,
readerEndpointAddress: '1.2.3.6',
securityGroup: sg,
});

// WHEN
DatabaseConnection.forDocDB({database, login: secret});

// THEN
expect(database.node.metadata.length).toBe(0);
});

test('No engineVersion given', () => {
// GIVEN
const database = new DatabaseCluster(stack, 'DbCluster', {
masterUser: {
username: 'master',
},
instanceProps: {
instanceType: InstanceType.of(
InstanceClass.R5,
InstanceSize.XLARGE,
),
vpc,
vpcSubnets: {
onePerAz: true,
subnetType: SubnetType.PRIVATE,
},
},
backup: {
retention: Duration.days(15),
},
});

// WHEN
DatabaseConnection.forDocDB({database, login: database.secret!});

// THEN
expect(database.node.metadata).toEqual(
expect.arrayContaining([
expect.objectContaining({
type: 'aws:cdk:error',
data: 'engineVersion must be 3.6.0 to be compatible with Deadline',
}),
]),
);
});

test('engineVersion not 3.6.0', () => {
// GIVEN
const database = new DatabaseCluster(stack, 'DbCluster', {
masterUser: {
username: 'master',
},
instanceProps: {
instanceType: InstanceType.of(
InstanceClass.R5,
InstanceSize.XLARGE,
),
vpc,
vpcSubnets: {
onePerAz: true,
subnetType: SubnetType.PRIVATE,
},
},
backup: {
retention: Duration.days(15),
},
engineVersion: '4.0.0',
});

// WHEN
DatabaseConnection.forDocDB({database, login: database.secret!});

// THEN
expect(database.node.metadata).toEqual(
expect.arrayContaining([
expect.objectContaining({
type: 'aws:cdk:error',
data: 'engineVersion must be 3.6.0 to be compatible with Deadline',
}),
]),
);
});
});

describe('MongoDB', () => {
let stack: Stack;
let vpc: Vpc;
Expand Down