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(aws-kinesis): remove default shard count when stream mode is on-demand and set default mode to provisioned #18221

Merged
merged 20 commits into from
Jan 6, 2022
Merged

Conversation

igilham
Copy link
Contributor

@igilham igilham commented Dec 30, 2021

Change the default Kinesis Data Stream's stream mode to provisioned from undefined to make the active configuration more explicit in the resulting CloudFormation templates.

Fix an issue whereby the shard count is always set when the stream mode is set to on-demand, which is invalid. Shard count still defaults to 1 in provisioned mode, but is left undefined in on-demand mode.

Add validation for the above so that an error is thrown from CDK when specifying on-demand mode with a shard count.

Fixes #18139


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

aws-cdk-automation and others added 3 commits December 30, 2021 09:13
Co-authored-by: AWS CDK Team <aws-cdk@amazon.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Align the import prefix for this additional class.

Otherwise copying the code will not compile.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Explicitly declaring ShardCount with a default value can cause errors
when using the on-demand stream mode. Instead, we can rely on
CloudFormation's implicit defaults.

part of #18139
@gitpod-io
Copy link

gitpod-io bot commented Dec 30, 2021

@github-actions github-actions bot added the @aws-cdk/aws-kinesis Related to Amazon Kinesis label Dec 30, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 30, 2021

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@igilham igilham changed the title Fix-kinesis-on-demand fix(aws-kinesis): remove default shard count Dec 30, 2021
@igilham
Copy link
Contributor Author

igilham commented Dec 30, 2021

The changes so far should fix the basic problem and allow the stream mode to be used.

I haven't figured out how to do validation yet so any help would be appreciated.

@igilham
Copy link
Contributor Author

igilham commented Dec 30, 2021

It looks like the dynamodb module just adds various guard statements and to the L2 construct constructor to prevent misuse of conflicting configuration options. I'll do the same.

* Document that streamMode and shardCount conflict
* Add a guard to prevent specifying shard count when stream mode is on-demand
* Restore default shard count of 1 when stream mode is provisioned
* Establish default stream mode of provisioned

These changes make the stream configuration explicit in the generated
CloudFormation templates again, matching the design of DynamoDB.

Fixes #18139
@igilham igilham changed the title fix(aws-kinesis): remove default shard count fix(aws-kinesis): remove default shard count when stream mode is provisioned Dec 30, 2021
@igilham igilham marked this pull request as ready for review December 30, 2021 17:27
@igilham
Copy link
Contributor Author

igilham commented Dec 30, 2021

Okay, I think I'm ready for the first round of reviews.

shardCount: 2,
streamMode: StreamMode.ON_DEMAND,
});
}).toThrow('streamMode must be set to PROVISIONED (default) when specifying shardCount');

Choose a reason for hiding this comment

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

You can use streamMode must be set to ${StreamMode.PROVISIONED} (default) when specifying shardCount to keep the value of the enum even if it is changed in the future.

@@ -4,6 +4,9 @@
"Type": "AWS::Kinesis::Stream",
"Properties": {
"ShardCount": 1,
"StreamModeDetails": {
"StreamMode": "PROVISIONED"

Choose a reason for hiding this comment

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

Check for ${StreamMode.PROVISIONED} for the exact enum values and same for ON_DEMAND occurences

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made this change in the unit tests. It's not applicable to these JSON files.

packages/@aws-cdk/aws-kinesis/lib/stream.ts Show resolved Hide resolved
@@ -752,9 +755,15 @@ export class Stream extends StreamBase {
physicalName: props.streamName,
});

const shardCount = props.shardCount || 1;
let shardCount = props.shardCount;
let streamMode = props.streamMode ?? StreamMode.PROVISIONED;

Choose a reason for hiding this comment

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

Can be constant

Choose a reason for hiding this comment

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

In this commit, you are making two changes, ie. the fix and the default to PROVISIONED capacity. You can include that in the commit details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the description. Hopefully that's a bit clearer.

@igilham igilham changed the title fix(aws-kinesis): remove default shard count when stream mode is provisioned fix(aws-kinesis): remove default shard count when stream mode is on-demand and set default mode to provisioned Dec 31, 2021
@igilham
Copy link
Contributor Author

igilham commented Jan 4, 2022

I'm back from today if there's any more feedback on this.

Copy link
Contributor

@peterwoodworth peterwoodworth left a comment

Choose a reason for hiding this comment

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

This looks great to me, I wish I saw this before I submitted my own PR! Thank you for the contribution 🙂

Thank you also to @d4r3topk for the initial review!

@mergify
Copy link
Contributor

mergify bot commented Jan 6, 2022

Thank you for contributing! Your pull request will be updated from master 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: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: ccf2d61
  • 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 cac11bb into aws:master Jan 6, 2022
@mergify
Copy link
Contributor

mergify bot commented Jan 6, 2022

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

@igilham igilham deleted the fix-kinesis-on-demand branch January 6, 2022 09:23
akash1810 added a commit to guardian/cdk that referenced this pull request Jan 26, 2022
Since v1.139.0 the `StreamMode` of a Kinesis stream is `PROVISIONED` by default.

The stream mode can be one of two options:

- On-demand - data streams with an on-demand mode require no capacity planning and automatically scale to handle gigabytes of write and read throughput per minute. With the on-demand mode, Kinesis Data Streams automatically manages the shards in order to provide the necessary throughput.
- Provisioned - for the data streams with a provisioned mode, you must specify the number of shards for the data stream. The total capacity of a data stream is the sum of the capacities of its shards. You can increase or decrease the number of shards in a data stream as needed.

Provisioned matches our use of Kinesis today, so the default makes sense.

See:
  - aws/aws-cdk#18221
  - https://docs.aws.amazon.com/streams/latest/dev/how-do-i-size-a-stream.html
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…emand and set default mode to provisioned (aws#18221)

Change the default Kinesis Data Stream's stream mode to provisioned from undefined to make the active configuration more explicit in the resulting CloudFormation templates.

Fix an issue whereby the shard count is always set when the stream mode is set to on-demand, which is invalid. Shard count still defaults to `1` in provisioned mode, but is left undefined in on-demand mode.

Add validation for the above so that an error is thrown from CDK when specifying on-demand mode with a shard count.

Fixes aws#18139

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-kinesis Related to Amazon Kinesis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-kinesis): fails to deploy on-demand stream
6 participants