fluent-plugin-formatter-protobuf 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/lib/fluent/plugin/formatter_protobuf.rb +26 -12
- data/lib/fluent/plugin/version.rb +1 -1
- data/test/plugin/test_formatter_protobuf.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab1edaa0c55c3e7c3174c18c682aa96a6a07056d6017dc5180cea1c988a03189
|
4
|
+
data.tar.gz: 8a10cffebdd8e605465f61ba8e30dbcf6da7b332ecb44f8bd08b60cf2dbf4539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d0a30cb1342b7fdcbe7057d223dacd150dba565d11c29ff2b4395fb35347e76f21463d23af5bbbe6b27882cbbd700ee4b1e5a5eb82d153093c37be812428752
|
7
|
+
data.tar.gz: 9865e62b40999dcbfcb82d30ab2363f8f704d2f0b8f07612f42165b633da83b3f2adc6df1a948321d75e182fa16abbb0b610da9dbba81a9f5a089376488e0ac9
|
data/README.md
CHANGED
@@ -88,11 +88,12 @@ This plugin only supports Protobuf v3.
|
|
88
88
|
|
89
89
|
## Configuration
|
90
90
|
|
91
|
-
|parameter| type | description
|
92
|
-
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
|parameter| type | description | default |
|
92
|
+
|---|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
|
93
|
+
|class_name| string (required) | Ruby Protobuf class name. Used to encode into Protobuf binary ||
|
94
|
+
|decode_json| boolean (optional) | Serializes record from canonical proto3 JSON mapping (https://developers.google.com/protocol-buffers/docs/proto3#json) into binary | `false` |
|
95
|
+
|include_paths| array (required) | Generated Ruby Protobuf class files path | `[]` |
|
96
|
+
|require_method| string (optional) | Determine how to bring the generated Ruby Protobuf class files into scope. If your generated Ruby Protobuf class files are provided by a Ruby Gem, you may want to use 'require'. If you are providing the generated files as files, you may want to use 'require_relative' | `require` |
|
96
97
|
|
97
98
|
## Tips
|
98
99
|
|
@@ -30,12 +30,30 @@ module Fluent
|
|
30
30
|
class ProtobufFormatter < Fluent::Plugin::Formatter
|
31
31
|
Fluent::Plugin.register_formatter('protobuf', self)
|
32
32
|
|
33
|
-
config_param :
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
config_param :decode_json,
|
38
|
-
|
33
|
+
config_param :class_name,
|
34
|
+
:string,
|
35
|
+
desc: 'Ruby Protobuf class name. Used to encode into Protobuf binary'
|
36
|
+
|
37
|
+
config_param :decode_json,
|
38
|
+
:bool,
|
39
|
+
default: false,
|
40
|
+
desc: <<~DESC
|
41
|
+
Serializes record from canonical proto3 JSON mapping (https://developers.google.com/protocol-buffers/docs/proto3#json) into binary'
|
42
|
+
DESC
|
43
|
+
|
44
|
+
config_param :include_paths,
|
45
|
+
:array,
|
46
|
+
default: [],
|
47
|
+
desc: 'Generated Ruby Protobuf class files path'
|
48
|
+
|
49
|
+
config_param :require_method,
|
50
|
+
:string,
|
51
|
+
default: 'require',
|
52
|
+
desc: <<~DESC
|
53
|
+
Determine how to bring the generated Ruby Protobuf class files into scope. If your generated Ruby Protobuf class files
|
54
|
+
are provided by a Ruby Gem, you would want to use \'require\'. If you are providing the generated files as files, you
|
55
|
+
may want to use \'require_relative\''
|
56
|
+
DESC
|
39
57
|
|
40
58
|
def configure(conf)
|
41
59
|
super(conf)
|
@@ -60,13 +78,9 @@ module Fluent
|
|
60
78
|
end
|
61
79
|
|
62
80
|
def require_proto!(filename)
|
63
|
-
|
64
|
-
require filename
|
65
|
-
else
|
66
|
-
require_relative filename
|
67
|
-
end
|
81
|
+
Kernel.method(@require_method.to_sym).call(filename)
|
68
82
|
rescue LoadError => e
|
69
|
-
raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.
|
83
|
+
raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.message}"
|
70
84
|
end
|
71
85
|
end
|
72
86
|
end
|
@@ -13,6 +13,7 @@ class ProtobufFormatterTest < Test::Unit::TestCase
|
|
13
13
|
# Relative to the plugin file
|
14
14
|
VALID_INCLUDE_PATHS_RELATIVE = '../../../test/proto/addressbook_pb.rb'
|
15
15
|
|
16
|
+
# rubocop:disable Metrics/BlockLength
|
16
17
|
sub_test_case 'configure' do
|
17
18
|
test 'fail if include_paths is empty' do
|
18
19
|
assert_raise(Fluent::ConfigError) do
|
@@ -34,7 +35,11 @@ class ProtobufFormatterTest < Test::Unit::TestCase
|
|
34
35
|
|
35
36
|
test 'success if given valid relative paths in include paths' do
|
36
37
|
assert_nothing_raised do
|
37
|
-
create_driver({
|
38
|
+
create_driver({
|
39
|
+
class_name: 'tutorial.AddressBook',
|
40
|
+
include_paths: [VALID_INCLUDE_PATHS_RELATIVE],
|
41
|
+
require_method: 'require_relative'
|
42
|
+
})
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
@@ -44,6 +49,7 @@ class ProtobufFormatterTest < Test::Unit::TestCase
|
|
44
49
|
end
|
45
50
|
end
|
46
51
|
end
|
52
|
+
# rubocop:enable Metrics/BlockLength
|
47
53
|
|
48
54
|
stub_ruby_hash = { people: [{ name: 'Masahiro', id: 1337,
|
49
55
|
email: 'repeatedly _at_ gmail.com',
|
@@ -51,6 +57,7 @@ class ProtobufFormatterTest < Test::Unit::TestCase
|
|
51
57
|
seconds: 1_638_489_505,
|
52
58
|
nanos: 318_000_000
|
53
59
|
} }] }
|
60
|
+
# rubocop:disable Metrics/BlockLength
|
54
61
|
sub_test_case 'format' do
|
55
62
|
test 'encodes into Protobuf binary' do
|
56
63
|
formatter = create_formatter({ class_name: 'tutorial.AddressBook',
|
@@ -75,7 +82,20 @@ class ProtobufFormatterTest < Test::Unit::TestCase
|
|
75
82
|
address_book = Tutorial::AddressBook.new(stub_ruby_hash)
|
76
83
|
assert_equal(Tutorial::AddressBook.encode(address_book), formatted)
|
77
84
|
end
|
85
|
+
|
86
|
+
test 'encodes Ruby hash into Protobuf binary if generated files are provided by a Gem' do
|
87
|
+
formatter = create_formatter({
|
88
|
+
class_name: 'google.protobuf.Duration',
|
89
|
+
# Provided by the google-protobuf gem
|
90
|
+
include_paths: ['google/protobuf/duration_pb'],
|
91
|
+
require_method: 'require'
|
92
|
+
})
|
93
|
+
formatted = formatter.format('some-tag', 1234, { seconds: 1, nanos: 340_012 })
|
94
|
+
duration = Google::Protobuf::Duration.new({ seconds: 1, nanos: 340_012 })
|
95
|
+
assert_equal(Google::Protobuf::Duration.encode(duration), formatted)
|
96
|
+
end
|
78
97
|
end
|
98
|
+
# rubocop:enable Metrics/BlockLength
|
79
99
|
|
80
100
|
private
|
81
101
|
|
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.
|
4
|
+
version: 0.2.0
|
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-12-
|
11
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|