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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca1a8fea393af2eed56eac08ac8fe4f8122d0c1e5b5d36099580ff9e0c962c67
4
- data.tar.gz: 9670c004adcabfe98e6ae98fe46a45ebe2a55e08df52d08e169fa149af2d032b
3
+ metadata.gz: ab1edaa0c55c3e7c3174c18c682aa96a6a07056d6017dc5180cea1c988a03189
4
+ data.tar.gz: 8a10cffebdd8e605465f61ba8e30dbcf6da7b332ecb44f8bd08b60cf2dbf4539
5
5
  SHA512:
6
- metadata.gz: 8e8f996d0940c53666eae2cea2b7d9b47a6d57a15d6c2038c7d83accf592d89018e8c864731e5b574449cc7c5d2a9b4ea6f4153cbb9dbdd4de84cc3e5c8a57ec
7
- data.tar.gz: 6b398f92c55ad9f8f6bc92b8da8947a887fa8bc3b3bd838c7973552e8aa12e353e04fcd76e13f9d314ace7429ced3c47b877b69f4d8b6270f7aefcfc0cb72758
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 | 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` |
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 :include_paths, :array, default: [], desc: 'Generated Ruby Protobuf class files path'
34
-
35
- config_param :class_name, :string, desc: 'Ruby Protobuf class name. Used to encode into Protobuf binary'
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
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
- if Pathname.new(filename).absolute?
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.inspect}"
83
+ raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.message}"
70
84
  end
71
85
  end
72
86
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fluent
4
4
  module Plugin
5
- VERSION = '0.1.1'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  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({ class_name: 'tutorial.AddressBook', include_paths: [VALID_INCLUDE_PATHS_RELATIVE] })
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.1.1
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-06 00:00:00.000000000 Z
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler