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

ISSUE-849: Use a map between topics and message-names when using ProtobufFile #854

Merged

Conversation

zarezadeh
Copy link
Contributor

@zarezadeh zarezadeh commented Sep 6, 2021

  • Breaking change?

What changes did you make? Added the ability to specify separate message types for each topic when using ProtobufFile for deserialization. The configuration protobufMessageName is now a map between the topic name and the message name. The key _default is used for specifying the message name for all other topics not defined explicitly.

Is there anything you'd like reviewers to focus on?

How Has This Been Tested? (put an "X" next to an item)

  • No need to
  • Manually(please, describe, when necessary)
  • Unit checks
  • Integration checks
  • Covered by existing automation

Checklist (put an "X" next to an item, otherwise PR will fail)

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. ENVIRONMENT VARIABLES)
  • My changes generate no new warnings(e.g. Sonar is happy)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged

Check out Contributing and Code of Conduct

@iliax
Copy link
Contributor

iliax commented Sep 7, 2021

@zarezadeh thank you for PR!
Here some improvements to consider:

  1. Lets keep configs backward-compatible: use protobufMessageName property value as default message and protobufTopicMessageName(or protobufMessageNameByTopic) map for explicit topic mapping
  2. please add mapping check in ProtobufFileRecordSerDe::serialize method:
    DynamicMessage.Builder builder = protobufSchema.newMessageBuilder();
  3. In tests please add manual messages creations rather than Base64. Here is a sample how you can do it:
DynamicMessage.Builder builder = protobufSchema.newMessageBuilder("messageNameHere");
JsonFormat.parser().merge("{ \"name\": \"My Name\", \"email\": \"test@test.com\" }", builder);
byte[] bytes =  builder.build().toByteArray();

@iliax iliax self-requested a review September 7, 2021 10:38
Copy link
Contributor

@iliax iliax left a comment

Choose a reason for hiding this comment

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

@zarezadeh zarezadeh requested a review from iliax September 7, 2021 13:03
@zarezadeh
Copy link
Contributor Author

@iliax thanks for your review, I applied your suggestions in the code.
But I think there's still one case that we should take into account: What if the provided messageName for a given topic does not exist in the protobuf definition? Should we handle it or is it the user's responsibility to provide proper configuration?

@iliax
Copy link
Contributor

iliax commented Sep 7, 2021

@iliax thanks for your review, I applied your suggestions in the code.
But I think there's still one case that we should take into account: What if the provided messageName for a given topic does not exist in the protobuf definition? Should we handle it or is it the user's responsibility to provide proper configuration?

@zarezadeh Yes, it is a good point. I think we definitely should not fall with NPE when provided name not found. We should either check names in constructor ( toDescriptor(..) != null) or in serialize/derialize. (requireNonNull(..))

Copy link
Contributor

@iliax iliax left a comment

Choose a reason for hiding this comment

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

see comment above

Copy link
Contributor

@germanosin germanosin left a comment

Choose a reason for hiding this comment

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

LGTM

@iliax iliax merged commit 64f9577 into provectus:master Sep 13, 2021
@iliax
Copy link
Contributor

iliax commented Sep 13, 2021

@zarezadeh thank you for PR!

javalover123 pushed a commit to javalover123/kafka-ui that referenced this pull request Dec 7, 2022
…obufFile (provectus#854)

* Use a map between topics and message-names when using ProtobufFile
* Validate the given message names for the topics in ProtobufFileRecordSerDe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to provide a separate Message name for each topic when using ProtobufFile
3 participants