logstash-codec-protobuf 1.0.5 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +20 -1
  3. data/Gemfile +1 -1
  4. data/LICENSE +2 -3
  5. data/README.md +147 -40
  6. data/docs/index.asciidoc +173 -41
  7. data/lib/logstash/codecs/protobuf.rb +598 -238
  8. data/logstash-codec-protobuf.gemspec +3 -3
  9. data/spec/codecs/{protobuf_spec.rb → pb2_spec.rb} +81 -54
  10. data/spec/codecs/pb3_decode_spec.rb +445 -0
  11. data/spec/codecs/pb3_encode_spec.rb +243 -0
  12. data/spec/helpers/pb2/event.pb.rb +19 -0
  13. data/spec/helpers/pb2/event.proto +12 -0
  14. data/spec/helpers/pb2/header/header.pb.rb +16 -0
  15. data/spec/helpers/pb2/header/header.proto +8 -0
  16. data/spec/helpers/pb3/FantasyHorse_pb.rb +44 -0
  17. data/spec/helpers/pb3/ProbeResult_pb.rb +26 -0
  18. data/spec/helpers/pb3/dnsmessage_pb.rb +82 -0
  19. data/spec/helpers/pb3/events.proto3 +10 -0
  20. data/spec/helpers/pb3/events_pb.rb +17 -0
  21. data/spec/helpers/pb3/header/header.proto3 +7 -0
  22. data/spec/helpers/pb3/header/header_pb.rb +12 -0
  23. data/spec/helpers/pb3/integertest_pb.rb +20 -0
  24. data/spec/helpers/pb3/messageA.proto3 +12 -0
  25. data/spec/helpers/pb3/messageA_pb.rb +16 -0
  26. data/spec/helpers/pb3/messageB.proto3 +12 -0
  27. data/spec/helpers/pb3/messageB_pb.rb +16 -0
  28. data/spec/helpers/pb3/rum2_pb.rb +87 -0
  29. data/spec/helpers/pb3/rum3_pb.rb +87 -0
  30. data/spec/helpers/pb3/rum_pb.rb +87 -0
  31. metadata +62 -34
  32. data/lib/net/jpountz/lz4/lz4/1.3.0/lz4-1.3.0.jar +0 -0
  33. data/lib/org/apache/kafka/kafka-clients/0.11.0.0/kafka-clients-0.11.0.0.jar +0 -0
  34. data/lib/org/apache/logging/log4j/log4j-api/2.8.2/log4j-api-2.8.2.jar +0 -0
  35. data/lib/org/apache/logging/log4j/log4j-slf4j-impl/2.8.2/log4j-slf4j-impl-2.8.2.jar +0 -0
  36. data/lib/org/slf4j/slf4j-api/1.7.24/slf4j-api-1.7.24.jar +0 -0
  37. data/lib/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar +0 -0
  38. data/lib/org/xerial/snappy/snappy-java/1.1.2.6/snappy-java-1.1.2.6.jar +0 -0
  39. data/spec/codecs/protobuf3_spec.rb +0 -147
  40. data/vendor/jar-dependencies/runtime-jars/kafka-clients-0.11.0.0.jar +0 -0
  41. data/vendor/jar-dependencies/runtime-jars/log4j-api-2.8.2.jar +0 -0
  42. data/vendor/jar-dependencies/runtime-jars/log4j-slf4j-impl-2.8.2.jar +0 -0
  43. data/vendor/jar-dependencies/runtime-jars/lz4-1.3.0.jar +0 -0
  44. data/vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.24.jar +0 -0
  45. data/vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.25.jar +0 -0
  46. data/vendor/jar-dependencies/runtime-jars/snappy-java-1.1.2.6.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a623045ad79469eeefd501735a5fc3284c19eef3
4
- data.tar.gz: 1a4b69f9ae131f5abe2b55270073c975edcbeab3
2
+ SHA256:
3
+ metadata.gz: afe37c419ffac934a07356c24954ab9534d6438363a8cbc3a4a9a9f7b4214cd0
4
+ data.tar.gz: 775f81231ce4181e43900251e5fea9906027efc5cbff2d65cd82d122b28fd977
5
5
  SHA512:
6
- metadata.gz: 0e152a7b9675dbd1c430da257a340364944f71b430bd093913705f376971650cc46933395a492f38732dc3665472ca56ebdc3e995d0c5023236b67466a7dc835
7
- data.tar.gz: a55114ffbc512e1ee31748093f864c1683e33536f590ded503cbae5ca2ec4f61754e7d518efc722593c9af4040270438f40fa05d3fa03ae27e334d1a61ff520c
6
+ metadata.gz: 02cff8a64b2bf3324d456b173b8b52761fb6ba8501f87e0011cc02328d75322552c794206fafa574919dc04e7bfe30fbb0f59e804a00f4550c57730913ff80fa
7
+ data.tar.gz: a431bd7300fa3dae4c16c82fd1dab79eefe8b1ea3552d5b9f9c8af175862867d029bd2ac398c1af445ec67e59cf12d010e61d5f75a3c159cfa64e294f7c1e178
data/CHANGELOG.md CHANGED
@@ -1,4 +1,23 @@
1
- ## 1.0.5
1
+ ## 1.2.5
2
+ - Encoder bugfix: avoid pipeline crash if encoding failed.
3
+
4
+ ## 1.2.4
5
+ - Encoder bugfix: avoid pipeline crash if encoding failed.
6
+
7
+ ## 1.2.3
8
+ - Add oneof information to @metadata (protobuf version 3 only).
9
+
10
+ ## 1.2.2
11
+ - Add type conversion feature to encoder
12
+
13
+ ## 1.2.1
14
+ - Keep original data in case of parsing errors
15
+
16
+ ## 1.2.0
17
+ - Autoload all referenced protobuf classes
18
+ - Fix concurrency issue when using multiple pipelines
19
+
20
+ ## 1.1.0
2
21
  - Add support for protobuf3
3
22
 
4
23
  ## 1.0.4
data/Gemfile CHANGED
@@ -8,4 +8,4 @@ use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "
8
8
  if Dir.exist?(logstash_path) && use_logstash_source
9
9
  gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
10
10
  gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
11
- end
11
+ end
data/LICENSE CHANGED
@@ -179,7 +179,7 @@
179
179
  APPENDIX: How to apply the Apache License to your work.
180
180
 
181
181
  To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "{}"
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
183
  replaced with your own identifying information. (Don't include
184
184
  the brackets!) The text should be enclosed in the appropriate
185
185
  comment syntax for the file format. We also recommend that a
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright (c) 2012-2018 Elasticsearch http://www.elastic.co
190
+ Copyright 2020 Elastic and contributors
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
@@ -200,4 +200,3 @@
200
200
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
201
  See the License for the specific language governing permissions and
202
202
  limitations under the License.
203
-
data/README.md CHANGED
@@ -3,73 +3,180 @@
3
3
  This is a codec plugin for [Logstash](https://github.com/elastic/logstash) to parse protobuf messages.
4
4
 
5
5
  # Prerequisites and Installation
6
-
7
- * prepare your ruby versions of the protobuf definitions, for example using the ruby-protoc compiler from https://github.com/codekitchen/ruby-protocol-buffers
6
+
7
+ * prepare your Ruby versions of the Protobuf definitions:
8
+ * For protobuf 2 use the [ruby-protoc compiler](https://github.com/codekitchen/ruby-protocol-buffers).
9
+ * For protobuf 3 use the [official google protobuf compiler](https://developers.google.com/protocol-buffers/docs/reference/ruby-generated).
8
10
  * install the codec: `bin/logstash-plugin install logstash-codec-protobuf`
9
- * use the codec in your logstash config file. See details below.
11
+ * use the codec in your Logstash config file. See details below.
10
12
 
11
13
  ## Configuration
12
14
 
13
- include_path (required): an array of strings with filenames or directory names where logstash can find your protobuf definitions. Please provide absolute paths. For directories it will only try to import files ending on .rb
15
+ There are two ways to specify the locations of the ruby protobuf definitions:
16
+ * specify each class and their loading order using the configurations `include_path`. This option will soon be deprecated in favour of the autoloader.
17
+ * specify the path to the main protobuf class, and a folder from which to load its dependencies, using `class_file` and `protobuf_root_directory`. The codec will detect the dependencies of each file and load them automatically.
14
18
 
15
- class_name (required): the name of the protobuf class that is to be decoded or encoded.
19
+ `include_path` (optional): an array of strings with filenames where logstash can find your protobuf definitions. Requires absolute paths. Please note that protobuf v2 files have the ending `.pb.rb` whereas files compiled for protobuf v3 end in `_pb.rb`. Cannot be used together with `protobuf_root_directory` or `class_file`.
16
20
 
17
- ## Usage example: decoder
21
+ `protobuf_root_directory` (optional): Only to be used in combination with `class_file`. Absolute path to the directory that contains all compiled protobuf files. Cannot be used together with `include_path`.
18
22
 
19
- Use this as a codec in any logstash input. Just provide the name of the class that your incoming objects will be encoded in, and specify the path to the compiled definition.
20
- Here's an example for a kafka input:
23
+ `class_file` (optional): Relative path to the ruby file that contains class_name. Only to be used in combination with `protobuf_root_directory`. Cannot be used together with `include_path`.
21
24
 
22
- kafka
23
- {
24
- zk_connect => "127.0.0.1"
25
- topic_id => "unicorns_protobuffed"
26
- codec => protobuf
27
- {
28
- class_name => "Unicorn"
29
- include_path => ['/my/path/to/compiled/protobuf/definitions/UnicornProtobuf.pb.rb']
30
- }
31
- }
25
+ `class_name` (required): the name of the protobuf class that is to be decoded or encoded. For protobuf 2 separate the modules with ::. For protobuf 3 use single dots.
32
26
 
33
- ### Example with referenced definitions
27
+ `protobuf_version` (optional): set this to 3 if you want to use protobuf 3 definitions. Defaults to 2.
34
28
 
35
- Imagine you have the following protobuf relationship: class Cheese lives in namespace Foods::Dairy and uses another class Milk.
29
+ `stop_on_error` (optional): Decoder only: will stop the entire pipeline upon discovery of a non decodable message. Deactivated by default.
36
30
 
37
- module Foods
38
- module Dairy
39
- class Cheese
40
- set_fully_qualified_name "Foods.Dairy.Cheese"
41
- optional ::Foods::Cheese::Milk, :milk, 1
42
- optional :int64, :unique_id, 2
43
- # here be more field definitions
31
+ `pb3_encoder_autoconvert_types` (optional): Encoder only: will try to fix type mismatches between the protobuf definition and the actual data. Available for protobuf 3 only. Activated by default.
44
32
 
45
- Make sure to put the referenced Milk class first in the include_path:
33
+ ## Usage example: decoder
46
34
 
47
- include_path => ['/path/to/protobuf/definitions/Milk.pb.rb','/path/to/protobuf/definitions/Cheese.pb.rb']
35
+ Use this as a codec in any logstash input. Just provide the name of the class that your incoming objects will be encoded in, and specify the path to the compiled definition.
36
+ Here's an example for a kafka input with protobuf 2:
37
+
38
+ ```ruby
39
+ kafka
40
+ {
41
+ topic_id => "..."
42
+ key_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
43
+ value_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
44
+
45
+ codec => protobuf
46
+ {
47
+ class_name => "Animals::Mammals::Unicorn"
48
+ include_path => ['/path/to/pb_definitions/Animal.pb.rb', '/path/to/pb_definitions/Unicorn.pb.rb']
49
+ }
50
+ }
51
+ ```
52
+
53
+ Example for protobuf 3, manual class loading specification (deprecated):
54
+
55
+ ```ruby
56
+ kafka
57
+ {
58
+ topic_id => "..."
59
+ key_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
60
+ value_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
61
+ codec => protobuf
62
+ {
63
+ class_name => "Animals.Mammals.Unicorn"
64
+ include_path => ['/path/to/pb_definitions/Animal_pb.rb', '/path/to/pb_definitions/Unicorn_pb.rb']
65
+ protobuf_version => 3
66
+ }
67
+ }
68
+ ```
69
+
70
+ Example for protobuf 3, automatic class loading specification:
71
+
72
+ ```ruby
73
+ kafka
74
+ {
75
+ topic_id => "..."
76
+ key_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
77
+ value_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
78
+ codec => protobuf
79
+ {
80
+ class_name => "Animals.Mammals.Unicorn"
81
+ class_file => '/path/to/pb_definitions/some_folder/Unicorn_pb.rb'
82
+ protobuf_root_directory => "/path/to/pb_definitions/"
83
+ protobuf_version => 3
84
+ }
85
+ }
86
+ ```
87
+ In this example, all protobuf files must live in a subfolder of `/path/to/pb_definitions/`.
88
+
89
+ For version 3 class names check the bottom of the generated protobuf ruby file. It contains lines like this:
90
+
91
+ ```ruby
92
+ Animals.Unicorn = Google::Protobuf::DescriptorPool.generated_pool.lookup("Animals.Unicorn").msgclass
93
+ ```
94
+
95
+ Use the parameter for the lookup call as the class_name for the codec config.
96
+
97
+ If you're using a kafka input please also set the deserializer classes as shown above.
98
+
99
+ ### Class loading order
100
+
101
+ Imagine you have the following protobuf version 2 relationship: class Unicorn lives in namespace Animal::Horse and uses another class Wings.
102
+
103
+ ```ruby
104
+ module Animal
105
+ module Mammal
106
+ class Unicorn
107
+ set_fully_qualified_name "Animal.Mammal.Unicorn"
108
+ optional ::Bodypart::Wings, :wings, 1
109
+ optional :string, :name, 2
110
+ ...
111
+ ```
112
+
113
+ Make sure to put the referenced wings class first in the include_path:
114
+
115
+ ```ruby
116
+ include_path => ['/path/to/pb_definitions/wings.pb.rb','/path/to/pb_definitions/unicorn.pb.rb']
117
+ ```
48
118
 
49
119
  Set the class name to the parent class:
50
-
51
- class_name => "Foods::Dairy::Cheese"
120
+
121
+ ```ruby
122
+ class_name => "Animal::Mammal::Unicorn"
123
+ ```
124
+
125
+ for protobuf 2. For protobuf 3 use
126
+
127
+ ```ruby
128
+ class_name => "Animal.Mammal.Unicorn"
129
+ ```
52
130
 
53
131
  ## Usage example: encoder
54
132
 
55
- The configuration of the codec for encoding logstash events for a protobuf output is pretty much the same as for the decoder input usage as demonstrated above. There are some constraints though that you need to be aware of:
56
- * the protobuf definition needs to contain all the fields that logstash typically adds to an event, in the corrent data type. Examples for this are @timestamp (string), @version (string), host, path, all of which depend on your input sources and filters aswell. If you do not want to add those fields to your protobuf definition then please use a [modify filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) to [remove](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-remove_field) the undesired fields.
57
- * object members starting with @ are somewhat problematic in protobuf definitions. Therefore those fields will automatically be renamed to remove the at character. This also effects the important @timestamp field. Please name it just "timestamp" in your definition.
133
+ The configuration of the codec for encoding logstash events for a protobuf output is pretty much the same as for the decoder input usage as demonstrated above, with the following exception: when writing to the Kafka output,
134
+ * do not set the `value_deserializer_class` or the `key_deserializer_class`.
135
+ * do set the serializer class like so: `value_serializer => "org.apache.kafka.common.serialization.ByteArraySerializer"`.
58
136
 
137
+ Please be aware of the following:
138
+ * the protobuf definition needs to contain all the fields that logstash typically adds to an event, in the corrent data type. Examples for this are `@timestamp` (string), `@version` (string), `host`, `path`, all of which depend on your input sources and filters aswell. If you do not want to add those fields to your protobuf definition then please use a [modify filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) to [remove](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-remove_field) the undesired fields.
139
+ * object members starting with `@` are somewhat problematic in protobuf definitions. Therefore those fields will automatically be renamed to remove the at character. This also effects the important `@timestamp` field. Please name it just "timestamp" in your definition.
140
+ * fields with a nil value will automatically be removed from the event. Empty fields will not be removed.
141
+ * it is recommended to set the config option `pb3_encoder_autoconvert_types` to true. Otherwise any type mismatch between your data and the protobuf definition will cause an event to be lost. The auto typeconversion does not alter your data. It just tries to convert obviously identical data into the expected datatype, such as converting integers to floats where floats are expected, or "true" / "false" strings into booleans where booleans are expected.
142
+
143
+ ```ruby
144
+ kafka
145
+ {
146
+ codec => protobuf
147
+ {
148
+ class_name => "Animals.Mammals.Unicorn"
149
+ class_file => '/path/to/pb_definitions/some_folder/Unicorn_pb.rb'
150
+ protobuf_root_directory => "/path/to/pb_definitions/"
151
+ protobuf_version => 3
152
+ }
153
+ ...
154
+ value_serializer => "org.apache.kafka.common.serialization.ByteArraySerializer"
155
+ }
156
+ }
157
+ ```
59
158
 
60
159
  ## Troubleshooting
61
160
 
62
- ### "uninitialized constant SOME_CLASS_NAME"
161
+ ### Decoder: Protobuf 2
162
+ #### "uninitialized constant SOME_CLASS_NAME"
163
+
164
+ If you include more than one definition class, consider the order of inclusion. This is especially relevant if you include whole directories. A definition might refer to another definition that is not loaded yet. In this case, please specify the files in the `include_path` variable in reverse order of reference. See 'Example with referenced definitions' above.
165
+
166
+ #### no protobuf output
167
+
168
+ Maybe your protobuf definition does not fullfill the requirements and needs additional fields. Run logstash with the `--debug` flag and search for error messages.
63
169
 
64
- If you include more than one definition class, consider the order of inclusion. This is especially relevant if you include whole directories. A definition might refer to another definition that is not loaded yet. In this case, please specify the files in the include_path variable in reverse order of reference. See 'Example with referenced definitions' above.
170
+ ### Decoder: Protobuf 3
65
171
 
66
- ### no protobuf output
172
+ #### NullPointerException
67
173
 
68
- Maybe your protobuf definition does not fullfill the requirements and needs additional fields. Run logstash with the --debug flag and grep for "error 2".
174
+ Check for missing imports. There's a high probability that one of the imported classes has dependencies of its own and those are not being fully satisfied. To avoid this, consider using the autoloader feature by setting the configurations for `protobuf_root_directory` and `class_file`.
69
175
 
176
+ ### Encoder: Protobuf 3
70
177
 
71
- ## Limitations and roadmap
178
+ #### NullPointerException
72
179
 
73
- * maybe add support for setting undefined fields from default values in the decoder
180
+ Check for missing imports. There's a high probability that one of the imported classes has dependencies of its own and those are not being fully satisfied. To avoid this, consider using the autoloader feature by setting the configurations for `protobuf_root_directory` and `class_file`.
74
181
 
75
182
 
data/docs/index.asciidoc CHANGED
@@ -20,21 +20,70 @@ include::{include_path}/plugin_header.asciidoc[]
20
20
 
21
21
  ==== Description
22
22
 
23
- This codec converts protobuf encoded messages into logstash events and vice versa.
23
+ This codec converts protobuf encoded messages into logstash events and vice versa. It supports the protobuf versions 2 and 3.
24
24
 
25
- Requires the protobuf definitions as ruby files. You can create those using the [ruby-protoc compiler](https://github.com/codekitchen/ruby-protocol-buffers).
25
+ The plugin requires the protobuf definitions to be compiled to ruby files. +
26
+ For protobuf 2 use the https://github.com/codekitchen/ruby-protocol-buffers[ruby-protoc compiler]. +
27
+ For protobuf 3 use the https://developers.google.com/protocol-buffers/docs/reference/ruby-generated[official google protobuf compiler].
26
28
 
27
- The following shows a usage example for decoding events from a kafka stream:
29
+ The following shows a usage example (protobuf v2) for decoding events from a kafka stream:
28
30
  [source,ruby]
29
- kafka
31
+ kafka
30
32
  {
31
- zk_connect => "127.0.0.1"
32
- topic_id => "your_topic_goes_here"
33
- codec => protobuf
34
- {
35
- class_name => "Animal::Unicorn"
36
- include_path => ['/path/to/protobuf/definitions/UnicornProtobuf.pb.rb']
37
- }
33
+ topic_id => "..."
34
+ key_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
35
+ value_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
36
+ codec => protobuf
37
+ {
38
+ class_name => "Animals::Mammals::Unicorn"
39
+ class_file => '/path/to/pb_definitions/some_folder/Unicorn.pb.rb'
40
+ protobuf_root_directory => "/path/to/pb_definitions/"
41
+ }
42
+ }
43
+
44
+ Decoder usage example for protobuf v3:
45
+ [source,ruby]
46
+ kafka
47
+ {
48
+ topic_id => "..."
49
+ key_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
50
+ value_deserializer_class => "org.apache.kafka.common.serialization.ByteArrayDeserializer"
51
+ codec => protobuf
52
+ {
53
+ class_name => "Animals.Mammals.Unicorn"
54
+ class_file => '/path/to/pb_definitions/some_folder/Unicorn_pb.rb'
55
+ protobuf_root_directory => "/path/to/pb_definitions/"
56
+ protobuf_version => 3
57
+ }
58
+ }
59
+
60
+
61
+ The codec can be used in input and output plugins. +
62
+ When using the codec in the kafka input plugin please set the deserializer classes as shown above. +
63
+ When using the codec in an output plugin:
64
+
65
+ * make sure to include all the desired fields in the protobuf definition, including timestamp.
66
+ Remove fields that are not part of the protobuf definition from the event by using the mutate filter. Encoding will fail if the event has fields which are not in the protobuf definition.
67
+ * the `@` symbol is currently not supported in field names when loading the protobuf definitions for encoding. Make sure to call the timestamp field `timestamp`
68
+ instead of `@timestamp` in the protobuf file. Logstash event fields will be stripped of the leading `@` before conversion.
69
+ * fields with a nil value will automatically be removed from the event. Empty fields will not be removed.
70
+ * it is recommended to set the config option `pb3_encoder_autoconvert_types` to true. Otherwise any type mismatch between your data and the protobuf definition will cause an event to be lost. The auto typeconversion does not alter your data. It just tries to convert obviously identical data into the expected datatype, such as converting integers to floats where floats are expected, or "true" / "false" strings into booleans where booleans are expected.
71
+ * When writing to Kafka: set the serializer class: `value_serializer => "org.apache.kafka.common.serialization.ByteArraySerializer"`
72
+
73
+ Encoder usage example (protobufg v3):
74
+
75
+ [source,ruby]
76
+ kafka
77
+ {
78
+ codec => protobuf
79
+ {
80
+ class_name => "Animals.Mammals.Unicorn"
81
+ class_file => '/path/to/pb_definitions/some_folder/Unicorn_pb.rb'
82
+ protobuf_root_directory => "/path/to/pb_definitions/"
83
+ protobuf_version => 3
84
+ }
85
+ value_serializer => "org.apache.kafka.common.serialization.ByteArraySerializer"
86
+ }
38
87
  }
39
88
 
40
89
 
@@ -45,62 +94,145 @@ kafka
45
94
  |=======================================================================
46
95
  |Setting |Input type|Required
47
96
  | <<plugins-{type}s-{plugin}-class_name>> |<<string,string>>|Yes
48
- | <<plugins-{type}s-{plugin}-include_path>> |<<array,array>>|Yes
97
+ | <<plugins-{type}s-{plugin}-class_file>> |<<string,string>>|No
98
+ | <<plugins-{type}s-{plugin}-protobuf_root_directory>> |<<string,string>>|No
99
+ | <<plugins-{type}s-{plugin}-include_path>> |<<array,array>>|No
100
+ | <<plugins-{type}s-{plugin}-protobuf_version>> |<<number,number>>|Yes
101
+ | <<plugins-{type}s-{plugin}-stop_on_error>> |<<boolean,boolean>>|No
102
+ | <<plugins-{type}s-{plugin}-pb3_encoder_autoconvert_types>> |<<boolean,boolean>>|No
49
103
  |=======================================================================
50
104
 
51
105
  &nbsp;
52
106
 
53
107
  [id="plugins-{type}s-{plugin}-class_name"]
54
- ===== `class_name`
108
+ ===== `class_name`
55
109
 
56
110
  * This is a required setting.
57
111
  * Value type is <<string,string>>
58
112
  * There is no default value for this setting.
59
113
 
60
- Name of the class to decode.
61
- If your protobuf definition contains modules, prepend them to the class name with double colons like so:
114
+ Fully qualified name of the class to decode.
115
+ Please note that the module delimiter is different depending on the protobuf version. For protobuf v2, use double colons:
116
+ [source,ruby]
117
+ class_name => "Animals::Mammals::Unicorn"
118
+
119
+ For protobuf v3, use single dots:
62
120
  [source,ruby]
63
- class_name => "Foods::Dairy::Cheese"
121
+ class_name => "Animals.Mammals.Unicorn"
64
122
 
65
- This corresponds to a protobuf definition starting as follows:
123
+ For protobuf v3, you can copy the class name from the Descriptorpool registrations at the bottom of the generated protobuf ruby file. It contains lines like this:
66
124
  [source,ruby]
67
- module Foods
68
- module Dairy
69
- class Cheese
70
- # here are your field definitions.
125
+ Animals.Mammals.Unicorn = Google::Protobuf::DescriptorPool.generated_pool.lookup("Animals.Mammals.Unicorn").msgclass
126
+
127
+ If your class references other definitions: you only have to add the name of the main class here.
128
+
129
+ [id="plugins-{type}s-{plugin}-class_file"]
130
+ ===== `class_file`
131
+
132
+ * Value type is <<string,string>>
133
+ * There is no default value for this setting.
134
+
135
+ Absolute path to the directory that contains all compiled protobuf files. If the protobuf definitions are spread across multiple folders, this needs to point to the folder containing all those folders.
136
+
137
+ [id="plugins-{type}s-{plugin}-protobuf_root_directory"]
138
+ ===== `protobuf_root_directory`
139
+
140
+ * Value type is <<string,string>>
141
+ * There is no default value for this setting.
142
+
143
+ Absolute path to the root directory that contains all referenced/used dependencies of the main class (`class_name`) or any of its dependencies. Must be used in combination with the `class_file` setting, and can not be used in combination with the legacy loading mechanism `include_path`.
144
+
145
+ Example:
146
+
147
+ [source]
148
+ pb3
149
+ ├── header
150
+ │ └── header_pb.rb
151
+ ├── messageA_pb.rb
152
+
153
+ In this case `messageA_pb.rb` has an embedded message from `header/header_pb.rb`.
154
+ If `class_file` is set to `messageA_pb.rb`, and `class_name` to `MessageA`, `protobuf_root_directory` must be set to `/path/to/pb3`, which includes both definitions.
71
155
 
72
- If your class references other definitions: you only have to add the main class here.
73
156
 
74
157
  [id="plugins-{type}s-{plugin}-include_path"]
75
- ===== `include_path`
158
+ ===== `include_path`
76
159
 
77
- * This is a required setting.
78
160
  * Value type is <<array,array>>
79
161
  * There is no default value for this setting.
80
162
 
81
- List of absolute pathes to files with protobuf definitions.
82
- When using more than one file, make sure to arrange the files in reverse order of dependency so that each class is loaded before it is
163
+ Legacy protobuf definition loading mechanism for backwards compatibility:
164
+ List of absolute pathes to files with protobuf definitions.
165
+ When using more than one file, make sure to arrange the files in reverse order of dependency so that each class is loaded before it is
83
166
  refered to by another.
84
167
 
85
- Example: a class _Cheese_ referencing another protobuf class _Milk_
168
+ Example: a class _Unicorn_ referencing another protobuf class _Wings_
86
169
  [source,ruby]
87
- module Foods
88
- module Dairy
89
- class Cheese
90
- set_fully_qualified_name "Foods.Dairy.Cheese"
91
- optional ::Foods::Cheese::Milk, :milk, 1
92
- optional :int64, :unique_id, 2
93
- # here be more field definitions
170
+ module Animal
171
+ module Mammal
172
+ class Unicorn
173
+ set_fully_qualified_name "Animal.Mammal.Unicorn"
174
+ optional ::Bodypart::Wings, :wings, 1
175
+ optional :string, :name, 2
176
+ ...
94
177
 
95
178
  would be configured as
96
179
  [source,ruby]
97
- include_path => ['/path/to/protobuf/definitions/Milk.pb.rb','/path/to/protobuf/definitions/Cheese.pb.rb']
180
+ include_path => ['/path/to/pb_definitions/wings.pb.rb','/path/to/pb_definitions/unicorn.pb.rb']
181
+
182
+ Please note that protobuf v2 files have the ending `.pb.rb` whereas files compiled for protobuf v3 end in `_pb.rb`.
183
+
184
+ Cannot be used together with `protobuf_root_directory` or `class_file`.
185
+
186
+ [id="plugins-{type}s-{plugin}-protobuf_version"]
187
+ ===== `protobuf_version`
188
+
189
+ * Value type is <<number,number>>
190
+ * Default value is 2
191
+
192
+ Protocol buffers version. Valid settings are 2, 3.
193
+
194
+ [id="plugins-{type}s-{plugin}-stop_on_error"]
195
+ ===== `stop_on_error`
196
+
197
+ * Value type is <<boolean,boolean>>
198
+ * Default value is false
199
+
200
+ Stop entire pipeline when encountering a non decodable message.
98
201
 
99
- When using the codec in an output plugin:
100
- * make sure to include all the desired fields in the protobuf definition, including timestamp.
101
- Remove fields that are not part of the protobuf definition from the event by using the mutate filter.
102
- * the @ symbol is currently not supported in field names when loading the protobuf definitions for encoding. Make sure to call the timestamp field "timestamp"
103
- instead of "@timestamp" in the protobuf file. Logstash event fields will be stripped of the leading @ before conversion.
104
-
202
+ [id="plugins-{type}s-{plugin}-pb3_encoder_autoconvert_types"]
203
+ ===== `pb3_encoder_autoconvert_types`
204
+
205
+ * Value type is <<boolean,boolean>>
206
+ * Default value is true
207
+
208
+ Convert data types to match the protobuf definition (if possible).
209
+ The protobuf encoder library is very strict with regards to data types. Example: an event has an integer field but the protobuf definition expects a float. This would lead to an exception and the event would be lost.
210
+
211
+ This feature tries to convert the datatypes to the expectations of the protobuf definitions, without modifying the data whatsoever. Examples of conversions it might attempt:
212
+
213
+ `"true" :: string => true :: boolean`
214
+
215
+ `17 :: int => 17.0 :: float`
216
+
217
+ `12345 :: number => "12345" :: string`
218
+
219
+ Available only for protobuf version 3.
220
+
221
+ [id="plugins-{type}s-{plugin}-pb3_set_oneof_metainfo"]
222
+ ===== `pb3_set_oneof_metainfo`
223
+
224
+ * Value type is <<boolean,boolean>>
225
+ * Default value is false
226
+
227
+ Add meta information to `[@metadata][pb_oneof]` about which classes were chosen for [oneof](https://developers.google.com/protocol-buffers/docs/proto3#oneof) fields. A new field of name `[@metadata][pb_oneof][FOO]` will be added, where `FOO` is the name of the `oneof` field.
228
+
229
+ Example values: for the protobuf definition
230
+ [source,ruby]
231
+ oneof :horse_type do
232
+ optional :unicorn, :message, 2, "UnicornType"
233
+ optional :pegasus, :message, 3, "PegasusType"
234
+ end
105
235
 
236
+ the field `[@metadata][pb_oneof][horse_type]` will be set to either `pegasus` or `unicorn`.
237
+ Available only for protobuf version 3.
106
238