fluent-plugin-formatter-protobuf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -13
- data/fluent-plugin-formatter-protobuf.gemspec +2 -0
- data/lib/fluent/plugin/formatter_protobuf.rb +5 -1
- data/lib/fluent/plugin/version.rb +1 -1
- data/test/integration/Gemfile +2 -2
- data/test/integration/Gemfile.lock +8 -8
- data/test/integration/fluent.conf +1 -1
- data/test/plugin/test_formatter_protobuf.rb +23 -3
- metadata +17 -6
- data/test/proto/addressbook +0 -1
- data/test/proto/addressbook.bin +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca1a8fea393af2eed56eac08ac8fe4f8122d0c1e5b5d36099580ff9e0c962c67
|
4
|
+
data.tar.gz: 9670c004adcabfe98e6ae98fe46a45ebe2a55e08df52d08e169fa149af2d032b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e8f996d0940c53666eae2cea2b7d9b47a6d57a15d6c2038c7d83accf592d89018e8c864731e5b574449cc7c5d2a9b4ea6f4153cbb9dbdd4de84cc3e5c8a57ec
|
7
|
+
data.tar.gz: 6b398f92c55ad9f8f6bc92b8da8947a887fa8bc3b3bd838c7973552e8aa12e353e04fcd76e13f9d314ace7429ced3c47b877b69f4d8b6270f7aefcfc0cb72758
|
data/README.md
CHANGED
@@ -50,10 +50,13 @@ $ bundle
|
|
50
50
|
2. Modify the `<format>` section to include `class_name`, which is your Protobuf message name, and `include_paths`, the path where the generated Ruby types are stored
|
51
51
|
1. Given protobuf class `Your::Protobuf::Class::Name` class should be given as `Your.Protobuf.Class.Name` in `class_name`. The exact name can be found in the generated Ruby files
|
52
52
|
|
53
|
+
## Note
|
54
|
+
|
55
|
+
This plugin only supports Protobuf v3.
|
53
56
|
|
54
57
|
## Example
|
55
58
|
|
56
|
-
```
|
59
|
+
```aconf
|
57
60
|
<source>
|
58
61
|
@type tcp
|
59
62
|
tag tcp.events
|
@@ -65,12 +68,14 @@ $ bundle
|
|
65
68
|
</source>
|
66
69
|
|
67
70
|
<match tcp.events>
|
68
|
-
@type
|
69
|
-
|
70
|
-
|
71
|
+
@type kafka2
|
72
|
+
|
73
|
+
brokers "#{BROKER_ENDPOINTS}"
|
74
|
+
compression_codec lz4
|
71
75
|
|
72
|
-
<buffer>
|
76
|
+
<buffer topic>
|
73
77
|
@type memory
|
78
|
+
flush_interval 5s
|
74
79
|
</buffer>
|
75
80
|
|
76
81
|
<format>
|
@@ -83,13 +88,53 @@ $ bundle
|
|
83
88
|
|
84
89
|
## Configuration
|
85
90
|
|
86
|
-
|parameter|type|description|default|
|
87
|
-
|
88
|
-
|include_paths|array (optional)| Generated Ruby Protobuf class files path
|
89
|
-
|class_name|string (required)| Ruby Protobuf class name. Used to encode into Protobuf binary||
|
91
|
+
|parameter| type | description | default |
|
92
|
+
|---|--------------------|---------------------------------------------------------------|---------|
|
93
|
+
|include_paths| array (optional) | Generated Ruby Protobuf class files path | `[]` |
|
94
|
+
|class_name| string (required) | Ruby Protobuf class name. Used to encode into Protobuf binary ||
|
95
|
+
|decode_json| boolean (optional) | Serializes record from canonical proto3 JSON mapping (https://developers.google.com/protocol-buffers/docs/proto3#json) into binary | `false` |
|
96
|
+
|
97
|
+
## Tips
|
98
|
+
|
99
|
+
#### 1. I have multiple `_pb.rb` files and they depend on one another. When I use this plugin, I'm getting a `LoadError`.
|
100
|
+
|
101
|
+
This happens because the plugin currently loads paths in `include_paths` sequentially. You can either sort the files in correct dependency order (which is cumbersome), or add to Ruby's `$LOAD_PATH`.
|
102
|
+
|
103
|
+
For example, you have 2 generated ruby files, `a_pb.rb` and `b_pb.rb`, and both `a_pb.rb` depends on `b_pb.rb`.
|
104
|
+
|
105
|
+
You can either order them in appropriate dependency order, such as
|
106
|
+
|
107
|
+
```aconf
|
108
|
+
<format>
|
109
|
+
@type protobuf
|
110
|
+
class_name "SomePackage.A"
|
111
|
+
include_paths ["/some/path/b_pb.rb", "/some/path/a_pb.rb"]
|
112
|
+
</format>
|
113
|
+
|
114
|
+
```
|
115
|
+
|
116
|
+
or you can put the generated files in a directory say `/some/path/`, and add to Ruby's `$LOAD_PATH` via the `RUBYLIB` environment variable.
|
117
|
+
|
118
|
+
e.g.
|
119
|
+
|
120
|
+
```aconf
|
121
|
+
<format>
|
122
|
+
@type protobuf
|
123
|
+
class_name "SomePackage.A"
|
124
|
+
include_paths ["/some/path/a_pb.rb"]
|
125
|
+
</format>
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
```shell
|
130
|
+
|
131
|
+
export RUBYLIB="${RUBYLIB}:/some/path/"
|
132
|
+
fluentd \
|
133
|
+
--gemfile "/some/other/path/Gemfile" \
|
134
|
+
--config "/some/other/path/fluent.conf"
|
135
|
+
|
136
|
+
```
|
90
137
|
|
91
|
-
##
|
138
|
+
## License
|
92
139
|
|
93
|
-
|
94
|
-
* License
|
95
|
-
* Apache License, Version 2.0
|
140
|
+
[Apache License, Version 2.0](./LICENSE)
|
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Fluent::Plugin::VERSION
|
10
10
|
spec.authors = ['Ray Tung']
|
11
11
|
spec.email = ['code@raytung.net']
|
12
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
12
13
|
|
13
14
|
spec.summary = 'Protobuf formatter for Fluentd'
|
14
15
|
spec.description = 'This is a Fluentd formatter plugin designed to convert Protobuf JSON into Protobuf binary'
|
@@ -35,4 +36,5 @@ Gem::Specification.new do |spec|
|
|
35
36
|
spec.add_development_dependency 'test-unit', '~> 3.3'
|
36
37
|
spec.add_runtime_dependency 'fluentd', ['>= 1.0', '< 2']
|
37
38
|
spec.add_runtime_dependency 'google-protobuf', ['~> 3.18']
|
39
|
+
spec.add_runtime_dependency 'oj', '~> 3.13'
|
38
40
|
end
|
@@ -22,6 +22,7 @@ require 'google/protobuf'
|
|
22
22
|
|
23
23
|
require 'fluent/env'
|
24
24
|
require 'fluent/time'
|
25
|
+
require 'oj'
|
25
26
|
|
26
27
|
module Fluent
|
27
28
|
module Plugin
|
@@ -33,6 +34,9 @@ module Fluent
|
|
33
34
|
|
34
35
|
config_param :class_name, :string, desc: 'Ruby Protobuf class name. Used to encode into Protobuf binary'
|
35
36
|
|
37
|
+
config_param :decode_json, :bool, default: false,
|
38
|
+
desc: 'Serializes record from canonical proto3 JSON mapping (https://developers.google.com/protocol-buffers/docs/proto3#json) into binary' # rubocop:disable Layout/LineLength
|
39
|
+
|
36
40
|
def configure(conf)
|
37
41
|
super(conf)
|
38
42
|
|
@@ -51,7 +55,7 @@ module Fluent
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def format(_tag, _time, record)
|
54
|
-
protobuf_msg = @protobuf_class.new(record)
|
58
|
+
protobuf_msg = @decode_json ? @protobuf_class.decode_json(Oj.dump(record)) : @protobuf_class.new(record)
|
55
59
|
@protobuf_class.encode(protobuf_msg)
|
56
60
|
end
|
57
61
|
|
data/test/integration/Gemfile
CHANGED
@@ -3,23 +3,23 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
concurrent-ruby (1.1.9)
|
5
5
|
cool.io (1.7.1)
|
6
|
-
fluent-plugin-formatter-protobuf (0.0
|
6
|
+
fluent-plugin-formatter-protobuf (0.1.0)
|
7
7
|
fluentd (>= 1.0, < 2)
|
8
8
|
google-protobuf (~> 3.18)
|
9
|
-
fluentd (1.14.
|
9
|
+
fluentd (1.14.2)
|
10
10
|
bundler
|
11
11
|
cool.io (>= 1.4.5, < 2.0.0)
|
12
12
|
http_parser.rb (>= 0.5.1, < 0.8.0)
|
13
13
|
msgpack (>= 1.3.1, < 2.0.0)
|
14
14
|
serverengine (>= 2.2.2, < 3.0.0)
|
15
15
|
sigdump (~> 0.2.2)
|
16
|
-
strptime (>= 0.2.
|
16
|
+
strptime (>= 0.2.4, < 1.0.0)
|
17
17
|
tzinfo (>= 1.0, < 3.0)
|
18
18
|
tzinfo-data (~> 1.0)
|
19
19
|
webrick (>= 1.4.2, < 1.8.0)
|
20
20
|
yajl-ruby (~> 1.0)
|
21
|
-
google-protobuf (3.
|
22
|
-
google-protobuf (3.
|
21
|
+
google-protobuf (3.19.1)
|
22
|
+
google-protobuf (3.19.1-x86_64-linux)
|
23
23
|
http_parser.rb (0.7.0)
|
24
24
|
msgpack (1.4.2)
|
25
25
|
serverengine (2.2.4)
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
strptime (0.2.5)
|
29
29
|
tzinfo (2.0.4)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
|
-
tzinfo-data (1.2021.
|
31
|
+
tzinfo-data (1.2021.5)
|
32
32
|
tzinfo (>= 1.0.0)
|
33
33
|
webrick (1.7.0)
|
34
34
|
yajl-ruby (1.4.1)
|
@@ -38,8 +38,8 @@ PLATFORMS
|
|
38
38
|
x86_64-linux
|
39
39
|
|
40
40
|
DEPENDENCIES
|
41
|
-
fluent-plugin-formatter-protobuf (= 0.0
|
42
|
-
fluentd (= 1.14.
|
41
|
+
fluent-plugin-formatter-protobuf (= 0.1.0)
|
42
|
+
fluentd (= 1.14.2)
|
43
43
|
|
44
44
|
BUNDLED WITH
|
45
45
|
2.2.29
|
@@ -45,15 +45,35 @@ class ProtobufFormatterTest < Test::Unit::TestCase
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
stub_ruby_hash = { people: [{ name: 'Masahiro', id: 1337,
|
49
|
+
email: 'repeatedly _at_ gmail.com',
|
50
|
+
last_updated: {
|
51
|
+
seconds: 1_638_489_505,
|
52
|
+
nanos: 318_000_000
|
53
|
+
} }] }
|
48
54
|
sub_test_case 'format' do
|
49
55
|
test 'encodes into Protobuf binary' do
|
50
56
|
formatter = create_formatter({ class_name: 'tutorial.AddressBook',
|
51
57
|
include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
|
52
58
|
|
53
59
|
formatted = formatter.format('some-tag', 1234,
|
54
|
-
{ people: [{ name: 'Masahiro', id: 1337, email: 'repeatedly _at_ gmail.com'
|
55
|
-
|
56
|
-
|
60
|
+
{ people: [{ name: 'Masahiro', id: 1337, email: 'repeatedly _at_ gmail.com',
|
61
|
+
last_updated: { seconds: 1_638_489_505, nanos: 318_000_000 } }] })
|
62
|
+
address_book = Tutorial::AddressBook.new(stub_ruby_hash)
|
63
|
+
assert_equal(Tutorial::AddressBook.encode(address_book), formatted)
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'encodes Protobuf JSON format into Protobuf binary if config_param decode_json is true' do
|
67
|
+
formatter = create_formatter({ class_name: 'tutorial.AddressBook',
|
68
|
+
decode_json: true,
|
69
|
+
include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
|
70
|
+
|
71
|
+
formatted = formatter.format('some-tag', 1234,
|
72
|
+
{ people: [{ name: 'Masahiro', id: 1337, email: 'repeatedly _at_ gmail.com',
|
73
|
+
last_updated: '2021-12-02T23:58:25.318Z' }] })
|
74
|
+
|
75
|
+
address_book = Tutorial::AddressBook.new(stub_ruby_hash)
|
76
|
+
assert_equal(Tutorial::AddressBook.encode(address_book), formatted)
|
57
77
|
end
|
58
78
|
end
|
59
79
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-formatter-protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Tung
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,20 @@ dependencies:
|
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '3.18'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: oj
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '3.13'
|
124
|
+
type: :runtime
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '3.13'
|
117
131
|
description: This is a Fluentd formatter plugin designed to convert Protobuf JSON
|
118
132
|
into Protobuf binary
|
119
133
|
email:
|
@@ -148,14 +162,13 @@ files:
|
|
148
162
|
- test/integration/run.sh
|
149
163
|
- test/plugin/test_formatter_protobuf.rb
|
150
164
|
- test/proto/README.md
|
151
|
-
- test/proto/addressbook
|
152
|
-
- test/proto/addressbook.bin
|
153
165
|
- test/proto/addressbook.proto
|
154
166
|
- test/proto/addressbook_pb.rb
|
155
167
|
homepage: https://github.com/raytung/fluent-plugin-formatter-protobuf
|
156
168
|
licenses:
|
157
169
|
- Apache-2.0
|
158
170
|
metadata:
|
171
|
+
rubygems_mfa_required: 'true'
|
159
172
|
homepage_uri: https://github.com/raytung/fluent-plugin-formatter-protobuf
|
160
173
|
source_code_uri: https://github.com/raytung/fluent-plugin-formatter-protobuf
|
161
174
|
changelog_uri: https://github.com/raytung/fluent-plugin-formatter-protobuf/blob/main/CHANGELOG.md
|
@@ -190,7 +203,5 @@ test_files:
|
|
190
203
|
- test/integration/run.sh
|
191
204
|
- test/plugin/test_formatter_protobuf.rb
|
192
205
|
- test/proto/README.md
|
193
|
-
- test/proto/addressbook
|
194
|
-
- test/proto/addressbook.bin
|
195
206
|
- test/proto/addressbook.proto
|
196
207
|
- test/proto/addressbook_pb.rb
|
data/test/proto/addressbook
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
people: [{name:"Masahiro", id: 1337, email: "repeatedly _at_ gmail.com"}]
|
data/test/proto/addressbook.bin
DELETED