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(lambda-event-sources): add kafka consumerGroupId support #21791

Merged
merged 14 commits into from
Sep 6, 2022

Conversation

RaphaelManke
Copy link
Contributor

@RaphaelManke RaphaelManke commented Aug 27, 2022

This PR adds the capability to specify the consumerGroupId in the event-source-mapping when connection to Kafka.
Adds the feature described in issue #21734

This features allows you to specify the consumerGroupId while connecting to a Kafka cluster. This feature was recently annouced https://aws.amazon.com/blogs/compute/using-custom-consumer-group-id-support-for-the-aws-lambda-event-sources-for-msk-and-self-managed-kafka/ and wasn't part of the cdk Kafka construct before.

Things done:

  • Added missing attributes to class EventSourceMapping
    • amazonManagedKafkaEventSourceConfig
    • selfManagedKafkaEventSourceConfig
  • Added validation for the consumerGroupId value based in CfnSpec
  • Added a common api consumerGroupId for adding the consumerGroupId independant if selfManaged or awsManaged
  • Updated existing integration test for SelfManagesKafkaConfig
    • The ManagedKafka Config is not integration tested because it requires a ManagedKafkaCluster which is not possible to deploy right now via cdk
  • Added Tests for consumerGroupId validation
  • Added Tests for template synth for SelfManagedKafka and AwsManagedKafka

All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link

gitpod-io bot commented Aug 27, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team August 27, 2022 11:12
@github-actions github-actions bot added the p2 label Aug 27, 2022
@RaphaelManke RaphaelManke marked this pull request as ready for review August 27, 2022 12:09
@RaphaelManke

This comment was marked as resolved.

@RaphaelManke

This comment was marked as resolved.

@RaphaelManke
Copy link
Contributor Author

@mrgrain You were reviewing a kafka related PR in the past, so maybe you are interested this time as well? 😃

@RaphaelManke RaphaelManke changed the title feat(lambda-event-sources) Add kafka consumerGroupId feat(lambda-event-sources): add kafka consumerGroupId Sep 2, 2022
@RaphaelManke RaphaelManke changed the title feat(lambda-event-sources): add kafka consumerGroupId feat(lambda-event-sources): add kafka consumerGroupId support Sep 2, 2022
*
* @default - none
*/
readonly consumerGroupId?: EventSourceMappingOptions['kafkaConsumerGroupId'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultimately this resolves to a string so I'm not sure what the benefit of assigning the type this 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.

Yes it is just a string, but my intention was to give someone that is looking at the code some guidance that the consumerGroupId is the same as the kafkaConsumerGroupId. And then it is easier to follow the path of the property to further documentation and usage. In this case the consumerGroupId is just a renaming of the property kafkaConsumerGroupId to have a shorter property name because we are aöready in the context of kafka properties.
But I get that this way of defining properties is a new style and therefore not optimal.
Please let me know if I should change it to or the property path reasoning has more value than just putting string here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate trying to give the extra context but I'm not sure that writing it this way will play nice with JSII when translating it into the other languages we use. That, and consistency in style is something I tend to think is pretty important for those who come after and try to understand the code to make changes again. I would use the docstring to provide this context if you don't think it's clear enough.

I do, however, like that you did shorten the name for the reason you listed.

packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts Outdated Show resolved Hide resolved
Comment on lines 345 to 346
let amazonManagedKafkaEventSourceConfig : CfnEventSourceMapping['amazonManagedKafkaEventSourceConfig'];
let selfManagedKafkaEventSourceConfig: CfnEventSourceMapping['selfManagedKafkaEventSourceConfig'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's figure out which one of these it should be mapped to and just set it there instead of providing both props.

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 split it into two if statements to have less branching. Additionally i moved the validation to private function to have a cleaner view on the logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this much better. Thanks!

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review September 3, 2022 10:48

Pull request has been modified.

@RaphaelManke RaphaelManke force-pushed the raphaelmanke/add-kafka-group-id branch 2 times, most recently from 0e1a308 to 01b4f41 Compare September 3, 2022 15:38
Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Please see my comments inline. This is almost perfect. Thanks for bearing with me on all the stylistic changes requested and my constant request of MOAR TESTS.

*
* @default - none
*/
readonly consumerGroupId?: EventSourceMappingOptions['kafkaConsumerGroupId'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate trying to give the extra context but I'm not sure that writing it this way will play nice with JSII when translating it into the other languages we use. That, and consistency in style is something I tend to think is pretty important for those who come after and try to understand the code to make changes again. I would use the docstring to provide this context if you don't think it's clear enough.

I do, however, like that you did shorten the name for the reason you listed.

Comment on lines 345 to 346
let amazonManagedKafkaEventSourceConfig : CfnEventSourceMapping['amazonManagedKafkaEventSourceConfig'];
let selfManagedKafkaEventSourceConfig: CfnEventSourceMapping['selfManagedKafkaEventSourceConfig'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this much better. Thanks!

@RaphaelManke RaphaelManke force-pushed the raphaelmanke/add-kafka-group-id branch from 3393880 to a6b01a1 Compare September 6, 2022 06:42
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review September 6, 2022 06:42

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Sep 6, 2022

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: 5ad6658
  • 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 b36bc11 into aws:main Sep 6, 2022
@mergify
Copy link
Contributor

mergify bot commented Sep 6, 2022

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants