Skip to content

Commit 4d20cb6

Browse files
iliaxjoschiiliaxHaarolean
authored
[BE] ProtobufFilesSerde imports implementation & refactoring (#3357)
* Feature: Support more complex Protobuf files The changes in #2874 added initial support for using more than 1 Protobuf file in Kafka UI in absence of a proper schema registry. This change is building upon that functionality to support more complex scenarios in which there are multiple Protobuf files being used and not all of them are explicitly listed (for example imports). It's using the already present Wire library from Square to do the heavy lifting and create a comprehensive schema from all Protobuf files and directories listed in the Kafka UI configuration. * Refactor schema loading logic and reuse in tests * Add support for reading Protobufs from ZIP archives * Remove unused ProtobufFileSerde#toLocation(Path) * wip * wip * wip * wip * wip * wip * wip --------- Co-authored-by: Jochen Schalanda <[email protected]> Co-authored-by: iliax <[email protected]> Co-authored-by: Roman Zabaluev <[email protected]>
1 parent b3f74cb commit 4d20cb6

File tree

10 files changed

+596
-388
lines changed

10 files changed

+596
-388
lines changed

documentation/compose/kafka-ui-serdes.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ services:
2828
kafka.clusters.0.serde.0.name: ProtobufFile
2929
kafka.clusters.0.serde.0.topicKeysPattern: "topic1"
3030
kafka.clusters.0.serde.0.topicValuesPattern: "topic1"
31-
kafka.clusters.0.serde.0.properties.protobufFiles.0: /protofiles/key-types.proto
32-
kafka.clusters.0.serde.0.properties.protobufFiles.1: /protofiles/values.proto
31+
kafka.clusters.0.serde.0.properties.protobufFilesDir: /protofiles/
3332
kafka.clusters.0.serde.0.properties.protobufMessageNameForKey: test.MyKey # default type for keys
3433
kafka.clusters.0.serde.0.properties.protobufMessageName: test.MyValue # default type for values
3534
kafka.clusters.0.serde.0.properties.protobufMessageNameForKeyByTopic.topic1: test.MySpecificTopicKey # keys type for topic "topic1"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
syntax = "proto3";
22
package test;
33

4+
import "google/protobuf/wrappers.proto";
5+
46
message MyKey {
57
string myKeyF1 = 1;
8+
google.protobuf.UInt64Value uint_64_wrapper = 2;
69
}
710

811
message MySpecificTopicKey {
912
string special_field1 = 1;
1013
string special_field2 = 2;
14+
google.protobuf.FloatValue float_wrapper = 3;
1115
}

documentation/guides/Protobuf.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,26 @@ To configure Kafkaui to deserialize protobuf messages using a supplied protobuf
1212
```yaml
1313
kafka:
1414
clusters:
15-
- # Cluster configuration omitted.
16-
# protobufFile is the path to the protobuf schema. (deprecated: please use "protobufFiles")
15+
- # Cluster configuration omitted...
16+
# protobufFilesDir specifies root location for proto files (will be scanned recursively)
17+
# NOTE: if 'protobufFilesDir' specified, then 'protobufFile' and 'protobufFiles' settings will be ignored
18+
protobufFilesDir: "/path/to/my-protobufs"
19+
# (DEPRECATED) protobufFile is the path to the protobuf schema. (deprecated: please use "protobufFiles")
1720
protobufFile: path/to/my.proto
18-
# protobufFiles is the path to one or more protobuf schemas.
19-
protobufFiles:
20-
- /path/to/my.proto
21-
- /path/to/another.proto
22-
# protobufMessageName is the default protobuf type that is used to deserilize
23-
# the message's value if the topic is not found in protobufMessageNameByTopic.
21+
# (DEPRECATED) protobufFiles is the location of one or more protobuf schemas
22+
protobufFiles:
23+
- /path/to/my-protobufs/my.proto
24+
- /path/to/my-protobufs/another.proto
25+
- /path/to/my-protobufs:test/test.proto
26+
# protobufMessageName is the default protobuf type that is used to deserialize
27+
# the message's value if the topic is not found in protobufMessageNameByTopic.
2428
protobufMessageName: my.DefaultValType
2529
# protobufMessageNameByTopic is a mapping of topic names to protobuf types.
2630
# This mapping is required and is used to deserialize the Kafka message's value.
2731
protobufMessageNameByTopic:
2832
topic1: my.Type1
2933
topic2: my.Type2
30-
# protobufMessageNameForKey is the default protobuf type that is used to deserilize
34+
# protobufMessageNameForKey is the default protobuf type that is used to deserialize
3135
# the message's key if the topic is not found in protobufMessageNameForKeyByTopic.
3236
protobufMessageNameForKey: my.DefaultKeyType
3337
# protobufMessageNameForKeyByTopic is a mapping of topic names to protobuf types.

documentation/guides/Serialization.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ kafka:
4646
serde:
4747
- name: ProtobufFile
4848
properties:
49-
# path to the protobuf schema files
50-
protobufFiles:
51-
- path/to/my.proto
52-
- path/to/another.proto
49+
# path to the protobuf schema files directory
50+
protobufFilesDir: "path/to/protofiles"
5351
# default protobuf type that is used for KEY serialization/deserialization
5452
# optional
5553
protobufMessageNameForKey: my.Type1

kafka-ui-api/src/main/java/com/provectus/kafka/ui/serdes/builtin/ProtobufFileSerde.java

Lines changed: 285 additions & 112 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)