-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Kafka codec #4950
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
Kafka codec #4950
Changes from 10 commits
4ec6b33
aa51c6b
074f868
f341df7
12ece4f
431a64c
ac5f851
8cb67ee
7e3f54c
d0534c3
db7763e
00aac5b
255f120
bbf0e08
76cc44f
6f86d76
23c1b9d
f369bfa
28641b4
3b9e324
89c1a59
acdbcb3
f5f5f32
20c7bf1
81c97c8
130d2ac
d47c2c2
145f28d
11d9288
ebe2134
7f1abca
36f76c7
98c7752
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| # Kafka network filter. | ||
| # Public docs: docs/root/configuration/network_filters/kafka_filter.rst | ||
|
|
||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_library", | ||
| "envoy_package", | ||
| ) | ||
|
|
||
| envoy_package() | ||
|
|
||
| envoy_cc_library( | ||
| name = "kafka_request_codec_lib", | ||
| srcs = ["request_codec.cc"], | ||
| hdrs = [ | ||
| "codec.h", | ||
| "request_codec.h", | ||
| ], | ||
| deps = [ | ||
| ":kafka_request_lib", | ||
| "//source/common/buffer:buffer_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "kafka_request_lib", | ||
| srcs = [ | ||
| "generated/kafka_request_resolver.cc", | ||
| "kafka_request.cc", | ||
| ], | ||
| hdrs = [ | ||
| "generated/requests.h", | ||
| "kafka_request.h", | ||
| ], | ||
| deps = [ | ||
| ":parser_lib", | ||
| ":serialization_lib", | ||
| "//source/common/common:assert_lib", | ||
| "//source/common/common:minimal_logger_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "parser_lib", | ||
| hdrs = ["parser.h"], | ||
| deps = [ | ||
| ":kafka_protocol_lib", | ||
| ":message_lib", | ||
| "//source/common/common:minimal_logger_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "message_lib", | ||
| hdrs = [ | ||
| "message.h", | ||
| ], | ||
| deps = [ | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "serialization_lib", | ||
| hdrs = [ | ||
| "generated/serialization_composite.h", | ||
| "serialization.h", | ||
| ], | ||
| deps = [ | ||
| ":kafka_protocol_lib", | ||
| "//include/envoy/buffer:buffer_interface", | ||
| "//source/common/common:byte_order_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_library( | ||
| name = "kafka_protocol_lib", | ||
| hdrs = [ | ||
| "kafka_types.h", | ||
| ], | ||
| external_deps = ["abseil_optional"], | ||
| deps = [ | ||
| "//source/common/common:macros", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/buffer/buffer.h" | ||
| #include "envoy/common/pure.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace NetworkFilters { | ||
| namespace Kafka { | ||
|
|
||
| /** | ||
| * Kafka message decoder | ||
| * @tparam MessageType message type (Kafka request or Kafka response) | ||
| */ | ||
| template <typename MessageType> class MessageDecoder { | ||
| public: | ||
| virtual ~MessageDecoder() = default; | ||
|
|
||
| /** | ||
| * Processes given buffer attempting to decode messages of type MessageType container within | ||
| * @param data buffer instance | ||
| */ | ||
| virtual void onData(Buffer::Instance& data) PURE; | ||
| }; | ||
|
|
||
| /** | ||
| * Kafka message decoder | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments out of date |
||
| * @tparam MessageType message type (Kafka request or Kafka response) | ||
| */ | ||
| template <typename MessageType> class MessageEncoder { | ||
| public: | ||
| virtual ~MessageEncoder() = default; | ||
|
|
||
| /** | ||
| * Encodes given message | ||
| * @param message message to be encoded | ||
| */ | ||
| virtual void encode(const MessageType& message) PURE; | ||
| }; | ||
|
|
||
| } // namespace Kafka | ||
| } // namespace NetworkFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // DO NOT EDIT - THIS FILE WAS GENERATED | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimally we would not check in the generated code. Can we run the generator during the build so that everything is hermetic and reproducible? I think I would like to get that setup and then I will commit to a full and expedient review? WDYT @adamkotwasinski? /wait
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattklein123 Actual decision is yours, as then you are requiring to have jvm & gradle installed (as you need to get Kafka's Java library to get the protocol data, so you need Java - there is no BNF with Kafka spec, the BNF was created from Java code). Erlang https://github.com/klarna/kafka_protocol#code-generation chose the other way - the generated files are committed. It's up to you if you want to pull java&related tooling into your build ecosystem - I'm fine either way.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use Bazel. It's there. Yes I would prefer to make it hermetic. I think this can likely be done as an external genrule Bazel target. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may be interested in apache/kafka#5893
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so with request/resp spec in json, we can remove java from ecosystem
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gwenshap FYI - if this gets merged in, we will depend on the fact that spec files present at https://github.com/apache/kafka/tree/2.2/clients/src/main/resources/common/message are named |
||
| // clang-format off | ||
| #include "extensions/filters/network/kafka/generated/requests.h" | ||
| #include "extensions/filters/network/kafka/kafka_request.h" | ||
| #include "extensions/filters/network/kafka/parser.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace NetworkFilters { | ||
| namespace Kafka { | ||
|
|
||
| const RequestParserResolver RequestParserResolver::INSTANCE; | ||
|
|
||
| ParserSharedPtr RequestParserResolver::createParser(int16_t api_key, int16_t api_version, | ||
| RequestContextSharedPtr context) const { | ||
|
|
||
| if (8 == api_key && 0 == api_version) { | ||
| return std::make_shared<OffsetCommitRequestV0Parser>(context); | ||
| } | ||
| if (8 == api_key && 1 == api_version) { | ||
| return std::make_shared<OffsetCommitRequestV1Parser>(context); | ||
| } | ||
| if (8 == api_key && 2 == api_version) { | ||
| return std::make_shared<OffsetCommitRequestV2Parser>(context); | ||
| } | ||
| if (8 == api_key && 3 == api_version) { | ||
| return std::make_shared<OffsetCommitRequestV3Parser>(context); | ||
| } | ||
| return std::make_shared<SentinelParser>(context); | ||
| } | ||
|
|
||
| } // namespace Kafka | ||
| } // namespace NetworkFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| // clang-format on | ||
Uh oh!
There was an error while loading. Please reload this page.