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(msk-alpha): MSK Kafka versions 2.8.2.tiered and 3.5.1 and StorageMode property #27560

Merged
merged 36 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
efa6f01
setup the beginnings of tiered storage and storageMode
chrispidcock Oct 13, 2023
5bae714
added tests and kafka version 3.5.1
chrispidcock Oct 15, 2023
c5c0f58
added tests and kafka version 3.5.1
chrispidcock Oct 15, 2023
9525641
updated isTiered logic to use a string or class, to make it more adap…
chrispidcock Oct 15, 2023
6f0fae6
updated isTiered logic to use a string or class, to make it more adap…
chrispidcock Oct 15, 2023
8d9fc1e
remove accident change
chrispidcock Oct 15, 2023
4ecf14d
undefined storagemode by default, only because it reduces the snapsho…
chrispidcock Oct 15, 2023
d7e9bd0
changes to help me understand how to make everything pass
chrispidcock Oct 15, 2023
f6a2d30
cleaning up
chrispidcock Oct 16, 2023
64a971c
update tests, but unable to test cdk.depoy test yet, or update snapshots
chrispidcock Oct 16, 2023
e30c473
add StorageMode as a default setting
chrispidcock Oct 16, 2023
ffbad8c
tests: integration tests for storage mode
chrispidcock Oct 17, 2023
6e7972b
setting default applied value for storagemode to undefined
chrispidcock Oct 17, 2023
b2af07b
tests: updated zookeeper integration test kafka version
chrispidcock Oct 17, 2023
2428789
typo in storagemode integ
chrispidcock Oct 17, 2023
d7b7ea4
update add-cluster-user.js integration test
chrispidcock Oct 17, 2023
4a33b88
docs: add Storage Mode to the msk README
chrispidcock Oct 18, 2023
d984aea
complete integration tests
chrispidcock Oct 20, 2023
a6f2764
fix no-multiple-empty-lines
chrispidcock Oct 20, 2023
2562421
Merge branch 'main' into adding-new-msk-kafka-versions
chrispidcock Oct 20, 2023
7021063
Apply suggestions from code review
chrispidcock Oct 22, 2023
c04e415
updated code based on PR comments
chrispidcock Oct 22, 2023
bb173a0
comment update in prop
chrispidcock Oct 22, 2023
d666eab
Apply suggestions from code review
chrispidcock Oct 22, 2023
f167ba3
update tests to align with suggested changes
chrispidcock Oct 23, 2023
732ac38
fix: Strings must use singlequote quotes
chrispidcock Oct 23, 2023
4d7e28b
undo default instance size change
chrispidcock Oct 23, 2023
78c6b5b
fix: Strings must use singlequote quotes
chrispidcock Oct 23, 2023
2c4a0b5
Merge branch 'main' into adding-new-msk-kafka-versions
chrispidcock Oct 23, 2023
337ebf8
fix instanceType condition and tests
chrispidcock Oct 23, 2023
8aa7ba1
instanceType looks best place for mskInstanceType
chrispidcock Oct 23, 2023
2050f4e
Apply suggestions from code review
kaizencc Nov 17, 2023
e94f72c
Update packages/@aws-cdk/aws-msk-alpha/lib/cluster.ts
chrispidcock Nov 19, 2023
045280b
Merge branch 'main' into adding-new-msk-kafka-versions
chrispidcock Nov 29, 2023
01199ab
new lines to fix styling
kaizencc Dec 1, 2023
df26766
Merge branch 'main' into adding-new-msk-kafka-versions
kaizencc Dec 1, 2023
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
24 changes: 24 additions & 0 deletions packages/@aws-cdk/aws-msk-alpha/lib/cluster-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export class KafkaVersion {
*/
public static readonly V2_8_1 = KafkaVersion.of('2.8.1');

/**
* AWS MSK Kafka version 2.8.2.tiered
*/
public static readonly V2_8_2_TIERED = KafkaVersion.of('2.8.2.tiered');

/**
* Kafka version 3.1.1
*/
Expand All @@ -101,6 +106,11 @@ export class KafkaVersion {
*/
public static readonly V3_4_0 = KafkaVersion.of('3.4.0');

/**
* Kafka version 3.5.1
*/
public static readonly V3_5_1 = KafkaVersion.of('3.5.1');

/**
* Custom cluster version
* @param version custom version number
Expand All @@ -109,6 +119,20 @@ export class KafkaVersion {
return new KafkaVersion(version);
}

/**
* Does this Kafka version support tiered storage?
* @param version cluster kafka version
* MSK Kafka versions that support tiered storage.
* @see https://docs.aws.amazon.com/msk/latest/developerguide/msk-tiered-storage.html#msk-tiered-storage-requirements
*/
public static isTieredStorageCompatible(version: KafkaVersion | string) {
if (version instanceof KafkaVersion) {
version = version.version;
}
const suffix = 'tiered';
return version.indexOf(suffix, version.length - suffix.length) !== -1;
};
chrispidcock marked this conversation as resolved.
Show resolved Hide resolved

/**
*
* @param version cluster version number
Expand Down
38 changes: 38 additions & 0 deletions packages/@aws-cdk/aws-msk-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export interface ClusterProps {
* @default - 1000 GiB EBS volume
*/
readonly ebsStorageInfo?: EbsStorageInfo;
/**
kaizencc marked this conversation as resolved.
Show resolved Hide resolved
* Local or Tiered storage configuration for the brokers
*
* @default - StorageMode.LOCAL
*/
readonly storageMode?: StorageMode;
/**
* The Amazon MSK configuration to use for the cluster.
*
Expand Down Expand Up @@ -160,6 +166,22 @@ export interface EbsStorageInfo {
readonly encryptionKey?: kms.IKey;
}

/**
* This controls storage mode for supported storage tiers.
*
* @see https://docs.aws.amazon.com/msk/latest/developerguide/msk-tiered-storage.html
*/
chrispidcock marked this conversation as resolved.
Show resolved Hide resolved
export enum StorageMode {
/**
* Local storage mode utilizes network attached EBS storage.
*/
LOCAL = 'LOCAL',
/**
* Tiered storage mode utilizes EBS storage and S3.
*/
TIERED = 'TIERED',
}

/**
* The Amazon MSK configuration to use for the cluster.
* Note: There is currently no Cloudformation Resource to create a Configuration
Expand Down Expand Up @@ -500,6 +522,21 @@ export class Cluster extends ClusterBase {
inCluster: props.encryptionInTransit?.enableInCluster ?? true,
};

const storageMode =
props.storageMode ?? StorageMode.LOCAL;
if (storageMode === StorageMode.TIERED && KafkaVersion.isTieredStorageCompatible(props.kafkaVersion) === false) {
throw Error(
'To utilize Tiered storage mode, the MSK cluster Kafka version must be compatiable.',
);
}
if (storageMode === StorageMode.TIERED && instanceType === this.mskInstanceType(
ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL),
)) {
throw Error(
'The t3.small instance type does not support Tiered storage mode.',
);
}

const openMonitoring =
props.monitoring?.enablePrometheusJmxExporter ||
props.monitoring?.enablePrometheusNodeExporter
Expand Down Expand Up @@ -683,6 +720,7 @@ export class Cluster extends ClusterBase {
configurationInfo: props.configurationInfo,
enhancedMonitoring: props.monitoring?.clusterMonitoringLevel,
openMonitoring: openMonitoring,
storageMode: storageMode,
chrispidcock marked this conversation as resolved.
Show resolved Hide resolved
loggingInfo: loggingInfo,
clientAuthentication: clientAuthentication,
});
Expand Down
61 changes: 61 additions & 0 deletions packages/@aws-cdk/aws-msk-alpha/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ describe('MSK Cluster', () => {
[msk.KafkaVersion.V2_7_2, '2.7.2'],
[msk.KafkaVersion.V2_8_0, '2.8.0'],
[msk.KafkaVersion.V2_8_1, '2.8.1'],
[msk.KafkaVersion.V2_8_2_TIERED, '2.8.2.tiered'],
[msk.KafkaVersion.V3_1_1, '3.1.1'],
[msk.KafkaVersion.V3_2_0, '3.2.0'],
[msk.KafkaVersion.V3_3_1, '3.3.1'],
[msk.KafkaVersion.V3_3_2, '3.3.2'],
[msk.KafkaVersion.V3_4_0, '3.4.0'],
[msk.KafkaVersion.V3_5_1, '3.5.1'],
],
)('created with expected Kafka version %j', (parameter, result) => {
new msk.Cluster(stack, 'Cluster', {
Expand Down Expand Up @@ -242,6 +244,7 @@ describe('MSK Cluster', () => {
'arn:aws:kms:us-east-1:111122223333:key/1234abc',
),
},
storageMode: msk.StorageMode.LOCAL,
encryptionInTransit: {
clientBroker: msk.ClientBrokerEncryption.TLS,
},
Expand Down Expand Up @@ -694,6 +697,7 @@ describe('MSK Cluster', () => {
'arn:aws:kms:us-east-1:111122223333:key/1234abc',
),
},
storageMode: msk.StorageMode.LOCAL,
encryptionInTransit: {
clientBroker: msk.ClientBrokerEncryption.TLS,
},
Expand Down Expand Up @@ -785,5 +789,62 @@ describe('MSK Cluster', () => {
});
});
});

describe('created with storage mode', () => {
describe('with tiered storage mode', () => {
test('fails if incompatiable Kafka version', () => {
chrispidcock marked this conversation as resolved.
Show resolved Hide resolved
expect(
() =>
new msk.Cluster(stack, 'Cluster', {
clusterName: 'cluster',
kafkaVersion: msk.KafkaVersion.V2_6_1,
vpc,
storageMode: msk.StorageMode.TIERED,
}),
).toThrow(
'To utilize Tiered storage mode, the MSK cluster Kafka version must be compatiable.',
);
});
test('fails if instance type of t3.small', () => {
chrispidcock marked this conversation as resolved.
Show resolved Hide resolved
expect(
() =>
new msk.Cluster(stack, 'Cluster', {
clusterName: 'cluster',
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL),
kafkaVersion: msk.KafkaVersion.V2_8_2_TIERED,
vpc,
storageMode: msk.StorageMode.TIERED,
}),
).toThrow(
'The t3.small instance type does not support Tiered storage mode.',
);
});
test('create a cluster with tiered storage mode', () => {
chrispidcock marked this conversation as resolved.
Show resolved Hide resolved
chrispidcock marked this conversation as resolved.
Show resolved Hide resolved
new msk.Cluster(stack, 'Cluster', {
clusterName: 'cluster',
instanceType: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.LARGE),
kafkaVersion: msk.KafkaVersion.V2_8_2_TIERED,
vpc,
storageMode: msk.StorageMode.TIERED,
}),
Template.fromStack(stack).hasResourceProperties('AWS::MSK::Cluster', {
StorageMode: 'TIERED',
});
});
});
describe('with local storage mode', () => {
chrispidcock marked this conversation as resolved.
Show resolved Hide resolved
test('create a cluster with local storage mode', () => {
new msk.Cluster(stack, 'Cluster', {
clusterName: 'cluster',
kafkaVersion: msk.KafkaVersion.V2_6_1,
vpc,
storageMode: msk.StorageMode.LOCAL,
});
Template.fromStack(stack).hasResourceProperties('AWS::MSK::Cluster', {
StorageMode: 'LOCAL',
});
});
});
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: fal
const cluster = new Cluster(stack, 'Cluster', {
vpc,
clusterName: 'integ-test',
kafkaVersion: KafkaVersion.V3_4_0,
kafkaVersion: KafkaVersion.V3_5_1,
removalPolicy: RemovalPolicy.DESTROY,
clientAuthentication: ClientAuthentication.sasl({ scram: true }),
});
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-msk-alpha/test/integ.cluster-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ const versions: KafkaVersion[] = [
KafkaVersion.V2_7_2,
KafkaVersion.V2_8_0,
KafkaVersion.V2_8_1,
KafkaVersion.V2_8_2_TIERED,
KafkaVersion.V3_1_1,
KafkaVersion.V3_2_0,
KafkaVersion.V3_3_1,
KafkaVersion.V3_3_2,
KafkaVersion.V3_4_0,
KafkaVersion.V3_5_1,
];

class KafkaVersionTest extends Stack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class KafkaZookeeperTest extends Stack {

const cluster = new msk.Cluster(this, 'ClusterZookeeper', {
clusterName: 'cluster-zookeeper',
kafkaVersion: msk.KafkaVersion.V3_4_0,
kafkaVersion: msk.KafkaVersion.V3_5_1,
vpc,
removalPolicy: RemovalPolicy.DESTROY,
});
Expand Down
Loading