fluent-plugin-formatter-protobuf 0.0.4 → 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: 3e212013e4ca4c6d50c19b1d2296e06626750039cb0b22f80ea255be37cd4d9f
4
- data.tar.gz: 30a007dba4d306d022d45cd5cc7230b7c3b9ba3edbb512b9e3924407588af03c
3
+ metadata.gz: ab1edaa0c55c3e7c3174c18c682aa96a6a07056d6017dc5180cea1c988a03189
4
+ data.tar.gz: 8a10cffebdd8e605465f61ba8e30dbcf6da7b332ecb44f8bd08b60cf2dbf4539
5
5
  SHA512:
6
- metadata.gz: e3c804a6a7cf38e50fb273e17437c7b14a57351f7e63483a24873b82c78adc7307de33f17c1f33504ac361a9b5b32488aabfcabb157b26c5214a9851f054d234
7
- data.tar.gz: 21adce1af4c987ddb7b3fbde52e3599cb98a925656550627ae625a8c962c88d67122db3ca55ba0c22a8875e86e7d8b9d6f49dc1d87acf311f6f380eec9c3aad0
6
+ metadata.gz: 6d0a30cb1342b7fdcbe7057d223dacd150dba565d11c29ff2b4395fb35347e76f21463d23af5bbbe6b27882cbbd700ee4b1e5a5eb82d153093c37be812428752
7
+ data.tar.gz: 9865e62b40999dcbfcb82d30ab2363f8f704d2f0b8f07612f42165b633da83b3f2adc6df1a948321d75e182fa16abbb0b610da9dbba81a9f5a089376488e0ac9
@@ -14,7 +14,7 @@ jobs:
14
14
 
15
15
  steps:
16
16
  - uses: actions/checkout@v2
17
- - name: Set up Ruby 2.7
17
+ - name: Set up Ruby 2.5
18
18
  uses: ruby/setup-ruby@v1
19
19
  with:
20
20
  bundler-cache: true
@@ -30,7 +30,7 @@ jobs:
30
30
 
31
31
  steps:
32
32
  - uses: actions/checkout@v2
33
- - name: Set up Ruby 2.7
33
+ - name: Set up Ruby 2.5
34
34
  uses: ruby/setup-ruby@v1
35
35
  with:
36
36
  bundler-cache: true
@@ -46,7 +46,7 @@ jobs:
46
46
 
47
47
  steps:
48
48
  - uses: actions/checkout@v2
49
- - name: Set up Ruby 2.7
49
+ - name: Set up Ruby 2.5
50
50
  uses: ruby/setup-ruby@v1
51
51
  with:
52
52
  bundler-cache: true
@@ -0,0 +1,49 @@
1
+ name: "CodeQL"
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+ schedule:
9
+ - cron: '18 11 * * 4'
10
+
11
+ jobs:
12
+ analyze:
13
+ name: Analyze
14
+ runs-on: ubuntu-latest
15
+ permissions:
16
+ actions: read
17
+ contents: read
18
+ security-events: write
19
+
20
+ strategy:
21
+ fail-fast: false
22
+ matrix:
23
+ language: [ 'ruby' ]
24
+
25
+ steps:
26
+ - name: Checkout repository
27
+ uses: actions/checkout@v2
28
+
29
+ - name: Initialize CodeQL
30
+ uses: github/codeql-action/init@v1
31
+ with:
32
+ languages: ${{ matrix.language }}
33
+
34
+ - name: Autobuild
35
+ uses: github/codeql-action/autobuild@v1
36
+
37
+ # ℹ️ Command-line programs to run using the OS shell.
38
+ # 📚 https://git.io/JvXDl
39
+
40
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
41
+ # and modify them (or add more) to build your code if your project
42
+ # uses a compiled language
43
+
44
+ #- run: |
45
+ # make bootstrap
46
+ # make release
47
+
48
+ - name: Perform CodeQL Analysis
49
+ uses: github/codeql-action/analyze@v1
@@ -15,7 +15,7 @@ jobs:
15
15
 
16
16
  steps:
17
17
  - uses: actions/checkout@v2
18
- - name: Set up Ruby 2.7
18
+ - name: Set up Ruby 2.5
19
19
  uses: ruby/setup-ruby@v1
20
20
  with:
21
21
  bundler-cache: true
@@ -31,7 +31,7 @@ jobs:
31
31
 
32
32
  steps:
33
33
  - uses: actions/checkout@v2
34
- - name: Set up Ruby 2.7
34
+ - name: Set up Ruby 2.5
35
35
  uses: ruby/setup-ruby@v1
36
36
  with:
37
37
  bundler-cache: true
@@ -42,7 +42,7 @@ jobs:
42
42
  needs:
43
43
  - lint
44
44
  - test
45
- name: Build + Publish
45
+ name: Build + Publish to GPR
46
46
  runs-on: ubuntu-latest
47
47
  permissions:
48
48
  packages: write
@@ -50,7 +50,7 @@ jobs:
50
50
 
51
51
  steps:
52
52
  - uses: actions/checkout@v2
53
- - name: Set up Ruby 2.7
53
+ - name: Set up Ruby 2.5
54
54
  uses: ruby/setup-ruby@v1
55
55
  with:
56
56
  bundler-cache: true
@@ -67,22 +67,11 @@ jobs:
67
67
  GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
68
68
  OWNER: ${{ github.repository_owner }}
69
69
 
70
- - name: Publish to RubyGems
71
- run: |
72
- mkdir -p $HOME/.gem
73
- touch $HOME/.gem/credentials
74
- chmod 0600 $HOME/.gem/credentials
75
- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
76
- gem build *.gemspec
77
- gem push *.gem
78
- env:
79
- GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
80
-
81
70
  publish-to-ruby-gems:
82
71
  needs:
83
72
  - lint
84
73
  - test
85
- name: Build + Publish
74
+ name: Build + Publish to RubyGems
86
75
  runs-on: ubuntu-latest
87
76
  permissions:
88
77
  packages: write
@@ -90,7 +79,7 @@ jobs:
90
79
 
91
80
  steps:
92
81
  - uses: actions/checkout@v2
93
- - name: Set up Ruby 2.7
82
+ - name: Set up Ruby 2.5
94
83
  uses: ruby/setup-ruby@v1
95
84
  with:
96
85
  bundler-cache: true
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- *.gem
1
+ *.gem
2
+ Gemfile.lock
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.1
1
+ 2.5.0
data/README.md CHANGED
@@ -8,16 +8,33 @@
8
8
 
9
9
  ### RubyGems
10
10
 
11
- ```
11
+ ```shell
12
12
  $ gem install fluent-plugin-formatter-protobuf
13
13
  ```
14
14
 
15
- ### Bundler
15
+ ### GitHub RubyGems Registry
16
+
17
+ ```shell
18
+ $ gem install \
19
+ fluent-plugin-formatter-protobuf \
20
+ --version "<version>" \
21
+ --source "https://rubygems.pkg.github.com/fluent-plugins-nursery"
22
+ ```
23
+
24
+ ### Bundler (RubyGems)
16
25
 
17
26
  Add following line to your Gemfile:
18
27
 
19
28
  ```ruby
20
- gem "fluent-plugin-formatter-protobuf"
29
+ gem "fluent-plugin-formatter-protobuf", "<version>"
30
+ ```
31
+
32
+ ### Bundler (GitHub RubyGems Registry),
33
+
34
+ ```shell
35
+ source "https://rubygems.pkg.github.com/fluent-plugins-nursery" do
36
+ gem "fluent-plugin-formatter-protobuf", "<version>"
37
+ end
21
38
  ```
22
39
 
23
40
  And then execute:
@@ -26,16 +43,20 @@ And then execute:
26
43
  $ bundle
27
44
  ```
28
45
 
29
- ## Not so quick start
46
+ ## Quick start
30
47
 
31
48
  1. Generate the protobuf ruby methods
32
49
  1. e.g `protoc --proto_path=. --ruby_out=. ./log.proto`
33
- 2. Modify the `<format>` section to include `message_name`, which is your Protobuf message name, and `include_paths`, the path where the generated Ruby types are stored
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
+ 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
+
53
+ ## Note
34
54
 
55
+ This plugin only supports Protobuf v3.
35
56
 
36
57
  ## Example
37
58
 
38
- ```fluentd
59
+ ```aconf
39
60
  <source>
40
61
  @type tcp
41
62
  tag tcp.events
@@ -47,17 +68,19 @@ $ bundle
47
68
  </source>
48
69
 
49
70
  <match tcp.events>
50
- @type file
51
-
52
- path /opt/fluent-plugin-formatter-protobuf/out
71
+ @type kafka2
72
+
73
+ brokers "#{BROKER_ENDPOINTS}"
74
+ compression_codec lz4
53
75
 
54
- <buffer>
76
+ <buffer topic>
55
77
  @type memory
78
+ flush_interval 5s
56
79
  </buffer>
57
80
 
58
81
  <format>
59
82
  @type protobuf
60
- message_name "Log"
83
+ class_name "Log"
61
84
  include_paths ["/opt/fluent-plugin-formatter-protobuf/log_pb.rb"]
62
85
  </format>
63
86
  </match>
@@ -65,16 +88,54 @@ $ bundle
65
88
 
66
89
  ## Configuration
67
90
 
68
- You can generate configuration template:
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` |
97
+
98
+ ## Tips
99
+
100
+ #### 1. I have multiple `_pb.rb` files and they depend on one another. When I use this plugin, I'm getting a `LoadError`.
101
+
102
+ 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`.
103
+
104
+ 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`.
105
+
106
+ You can either order them in appropriate dependency order, such as
107
+
108
+ ```aconf
109
+ <format>
110
+ @type protobuf
111
+ class_name "SomePackage.A"
112
+ include_paths ["/some/path/b_pb.rb", "/some/path/a_pb.rb"]
113
+ </format>
69
114
 
70
115
  ```
71
- $ fluent-plugin-config-format formatter formatter-protobuf
116
+
117
+ 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.
118
+
119
+ e.g.
120
+
121
+ ```aconf
122
+ <format>
123
+ @type protobuf
124
+ class_name "SomePackage.A"
125
+ include_paths ["/some/path/a_pb.rb"]
126
+ </format>
127
+
72
128
  ```
73
129
 
74
- You can copy and paste generated documents here.
130
+ ```shell
131
+
132
+ export RUBYLIB="${RUBYLIB}:/some/path/"
133
+ fluentd \
134
+ --gemfile "/some/other/path/Gemfile" \
135
+ --config "/some/other/path/fluent.conf"
136
+
137
+ ```
75
138
 
76
- ## Copyright
139
+ ## License
77
140
 
78
- * Copyright(c) 2021 - Ray Tung
79
- * License
80
- * Apache License, Version 2.0
141
+ [Apache License, Version 2.0](./LICENSE)
data/RELEASE.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## Instructions
4
4
  To release the gem to Github package manager and Ruby Gems,
5
5
 
6
- 1. Update `lib/fluent/version.rb`
7
- 2. Update `Gemfile.lock`
8
- 3. Create a pull request and merge it into `main`
9
- 4. Manually creating a release on Github with a tag indicating the new version number e.g. `vMAJOR.MINOR.PATCH`
6
+ 1. Update `lib/fluent/plugin/version.rb`
7
+ 2. Create a pull request and merge it into `main`
8
+ 3. Manually creating a release on Github with a tag indicating the new version number e.g. `vMAJOR.MINOR.PATCH`
9
+ 4. GitHub Actions will automatically run and publish to RubyGems and GitHub repository
@@ -9,12 +9,13 @@ 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'
15
16
  spec.homepage = 'https://github.com/raytung/fluent-plugin-formatter-protobuf'
16
17
  spec.license = 'Apache-2.0'
17
- spec.required_ruby_version = Gem::Requirement.new('>=2.7.1')
18
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
18
19
 
19
20
  spec.metadata['homepage_uri'] = spec.homepage
20
21
  spec.metadata['source_code_uri'] = 'https://github.com/raytung/fluent-plugin-formatter-protobuf'
@@ -28,11 +29,12 @@ Gem::Specification.new do |spec|
28
29
  spec.test_files = test_files
29
30
  spec.require_paths = ['lib']
30
31
 
31
- spec.add_development_dependency 'bundler', '~> 2.2.22'
32
- spec.add_development_dependency 'rake', '~> 13.0.3'
33
- spec.add_development_dependency 'rubocop', '~> 1.22.1'
34
- spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
35
- spec.add_development_dependency 'test-unit', '~> 3.3.7'
32
+ spec.add_development_dependency 'bundler', '~> 2.2'
33
+ spec.add_development_dependency 'rake', '~> 13.0'
34
+ spec.add_development_dependency 'rubocop', '~> 1.22'
35
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6'
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
@@ -29,11 +30,30 @@ module Fluent
29
30
  class ProtobufFormatter < Fluent::Plugin::Formatter
30
31
  Fluent::Plugin.register_formatter('protobuf', self)
31
32
 
32
- # Absolute paths to the generated Ruby protobuf files
33
- config_param :include_paths, :array, default: []
34
-
35
- # Protobuf message name
36
- config_param :message_name, :string
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
37
57
 
38
58
  def configure(conf)
39
59
  super(conf)
@@ -42,10 +62,10 @@ module Fluent
42
62
 
43
63
  @include_paths.each { |path| require_proto!(path) } unless @include_paths.empty?
44
64
 
45
- message_lookup = Google::Protobuf::DescriptorPool.generated_pool.lookup(@message_name)
46
- raise Fluent::ConfigError, "message name '#{@message_name}' not found" if message_lookup.nil?
65
+ class_lookup = Google::Protobuf::DescriptorPool.generated_pool.lookup(@class_name)
66
+ raise Fluent::ConfigError, "class name '#{@class_name}' not found" if class_lookup.nil?
47
67
 
48
- @protobuf_class = message_lookup.msgclass
68
+ @protobuf_class = class_lookup.msgclass
49
69
  end
50
70
 
51
71
  def formatter_type
@@ -53,26 +73,14 @@ module Fluent
53
73
  end
54
74
 
55
75
  def format(_tag, _time, record)
56
- protobuf_msg = @protobuf_class.new(record)
76
+ protobuf_msg = @decode_json ? @protobuf_class.decode_json(Oj.dump(record)) : @protobuf_class.new(record)
57
77
  @protobuf_class.encode(protobuf_msg)
58
78
  end
59
79
 
60
- # @param [string] filename
61
- # @return [void]
62
80
  def require_proto!(filename)
63
- unless filename.end_with?('.rb')
64
- raise Fluent::ConfigError, "Unable to load file '#{filename}'. It is not a Ruby file"
65
- end
66
-
67
- unless Pathname.new(filename).absolute?
68
- raise Fluent::ConfigError, "Unable to load file '#{filename}'. Please provide absolute paths"
69
- end
70
-
71
- begin
72
- require filename
73
- rescue LoadError => e
74
- raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.inspect}"
75
- end
81
+ Kernel.method(@require_method.to_sym).call(filename)
82
+ rescue LoadError => e
83
+ raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.message}"
76
84
  end
77
85
  end
78
86
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fluent
4
4
  module Plugin
5
- VERSION = '0.0.4'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'fluentd', '1.14.1'
6
- gem 'fluent-plugin-formatter-protobuf', '0.0.3'
5
+ gem 'fluentd', '1.14.2'
6
+ gem 'fluent-plugin-formatter-protobuf', '0.1.0'
@@ -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.3)
6
+ fluent-plugin-formatter-protobuf (0.1.0)
7
7
  fluentd (>= 1.0, < 2)
8
8
  google-protobuf (~> 3.18)
9
- fluentd (1.14.1)
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.2, < 1.0.0)
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.18.1)
22
- google-protobuf (3.18.1-x86_64-linux)
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.3)
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.3)
42
- fluentd (= 1.14.1)
41
+ fluent-plugin-formatter-protobuf (= 0.1.0)
42
+ fluentd (= 1.14.2)
43
43
 
44
44
  BUNDLED WITH
45
45
  2.2.29
@@ -19,7 +19,7 @@
19
19
 
20
20
  <format>
21
21
  @type protobuf
22
- message_name "Log"
22
+ class_name "Log"
23
23
  include_paths ["/opt/fluent-plugin-formatter-protobuf/log_pb.rb"]
24
24
  </format>
25
25
  </match>
@@ -8,38 +8,94 @@ class ProtobufFormatterTest < Test::Unit::TestCase
8
8
  Fluent::Test.setup
9
9
  end
10
10
 
11
- VALID_INCLUDE_PATHS = [File.expand_path(File.join(__dir__, '..', 'proto', 'addressbook_pb.rb'))].freeze
11
+ VALID_INCLUDE_PATHS_ABSOLUTE = [File.expand_path(File.join(__dir__, '..', 'proto', 'addressbook_pb.rb'))].freeze
12
12
 
13
+ # Relative to the plugin file
14
+ VALID_INCLUDE_PATHS_RELATIVE = '../../../test/proto/addressbook_pb.rb'
15
+
16
+ # rubocop:disable Metrics/BlockLength
13
17
  sub_test_case 'configure' do
14
18
  test 'fail if include_paths is empty' do
15
19
  assert_raise(Fluent::ConfigError) do
16
- create_driver({ message_name: '', include_paths: [] })
20
+ create_driver({ class_name: '', include_paths: [] })
21
+ end
22
+ end
23
+
24
+ test 'fail if ruby files not found in the provided include paths' do
25
+ assert_raise(Fluent::ConfigError) do
26
+ create_driver({ class_name: 'tutorial.AddressBook', include_paths: ['some/random/path'] })
17
27
  end
18
28
  end
19
29
 
20
- test 'fail if no protobuf class can be found with message_name' do
30
+ test 'fail if no protobuf class can be found with class_name' do
21
31
  assert_raise(Fluent::ConfigError) do
22
- create_driver({ message_name: 'Some.Name', include_paths: VALID_INCLUDE_PATHS })
32
+ create_driver({ class_name: 'Some.Name', include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
33
+ end
34
+ end
35
+
36
+ test 'success if given valid relative paths in include paths' do
37
+ assert_nothing_raised do
38
+ create_driver({
39
+ class_name: 'tutorial.AddressBook',
40
+ include_paths: [VALID_INCLUDE_PATHS_RELATIVE],
41
+ require_method: 'require_relative'
42
+ })
23
43
  end
24
44
  end
25
45
 
26
46
  test 'passes on valid configuration' do
27
47
  assert_nothing_raised do
28
- create_driver({ message_name: 'tutorial.AddressBook', include_paths: VALID_INCLUDE_PATHS })
48
+ create_driver({ class_name: 'tutorial.AddressBook', include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
29
49
  end
30
50
  end
31
51
  end
52
+ # rubocop:enable Metrics/BlockLength
32
53
 
54
+ stub_ruby_hash = { people: [{ name: 'Masahiro', id: 1337,
55
+ email: 'repeatedly _at_ gmail.com',
56
+ last_updated: {
57
+ seconds: 1_638_489_505,
58
+ nanos: 318_000_000
59
+ } }] }
60
+ # rubocop:disable Metrics/BlockLength
33
61
  sub_test_case 'format' do
34
62
  test 'encodes into Protobuf binary' do
35
- formatter = create_formatter({ message_name: 'tutorial.AddressBook', include_paths: VALID_INCLUDE_PATHS })
63
+ formatter = create_formatter({ class_name: 'tutorial.AddressBook',
64
+ include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
65
+
66
+ formatted = formatter.format('some-tag', 1234,
67
+ { people: [{ name: 'Masahiro', id: 1337, email: 'repeatedly _at_ gmail.com',
68
+ last_updated: { seconds: 1_638_489_505, nanos: 318_000_000 } }] })
69
+ address_book = Tutorial::AddressBook.new(stub_ruby_hash)
70
+ assert_equal(Tutorial::AddressBook.encode(address_book), formatted)
71
+ end
72
+
73
+ test 'encodes Protobuf JSON format into Protobuf binary if config_param decode_json is true' do
74
+ formatter = create_formatter({ class_name: 'tutorial.AddressBook',
75
+ decode_json: true,
76
+ include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
36
77
 
37
78
  formatted = formatter.format('some-tag', 1234,
38
- { people: [{ name: 'Masahiro', id: 1337, email: 'repeatedly _at_ gmail.com' }] })
39
- golden_file = File.binread(File.expand_path(File.join(__dir__, '..', 'proto', 'addressbook.bin')))
40
- assert_equal(golden_file, formatted)
79
+ { people: [{ name: 'Masahiro', id: 1337, email: 'repeatedly _at_ gmail.com',
80
+ last_updated: '2021-12-02T23:58:25.318Z' }] })
81
+
82
+ address_book = Tutorial::AddressBook.new(stub_ruby_hash)
83
+ assert_equal(Tutorial::AddressBook.encode(address_book), formatted)
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)
41
96
  end
42
97
  end
98
+ # rubocop:enable Metrics/BlockLength
43
99
 
44
100
  private
45
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.0.4
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-10-16 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
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.22
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.2.22
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 13.0.3
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 13.0.3
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.22.1
47
+ version: '1.22'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.22.1
54
+ version: '1.22'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop-rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.6.0
61
+ version: '0.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.6.0
68
+ version: '0.6'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.3.7
75
+ version: '3.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.3.7
82
+ version: '3.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: fluentd
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -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:
@@ -123,12 +137,12 @@ extensions: []
123
137
  extra_rdoc_files: []
124
138
  files:
125
139
  - ".github/workflows/build-and-test.yml"
140
+ - ".github/workflows/codeql-analysis.yml"
126
141
  - ".github/workflows/publish.yml"
127
142
  - ".gitignore"
128
143
  - ".rubocop.yml"
129
144
  - ".ruby-version"
130
145
  - Gemfile
131
- - Gemfile.lock
132
146
  - LICENSE
133
147
  - README.md
134
148
  - RELEASE.md
@@ -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
@@ -167,14 +180,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
180
  requirements:
168
181
  - - ">="
169
182
  - !ruby/object:Gem::Version
170
- version: 2.7.1
183
+ version: 2.5.0
171
184
  required_rubygems_version: !ruby/object:Gem::Requirement
172
185
  requirements:
173
186
  - - ">="
174
187
  - !ruby/object:Gem::Version
175
188
  version: '0'
176
189
  requirements: []
177
- rubygems_version: 3.1.2
190
+ rubyforge_project:
191
+ rubygems_version: 2.7.3
178
192
  signing_key:
179
193
  specification_version: 4
180
194
  summary: Protobuf formatter for Fluentd
@@ -189,7 +203,5 @@ test_files:
189
203
  - test/integration/run.sh
190
204
  - test/plugin/test_formatter_protobuf.rb
191
205
  - test/proto/README.md
192
- - test/proto/addressbook
193
- - test/proto/addressbook.bin
194
206
  - test/proto/addressbook.proto
195
207
  - test/proto/addressbook_pb.rb
data/Gemfile.lock DELETED
@@ -1,77 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- fluent-plugin-formatter-protobuf (0.0.4)
5
- fluentd (>= 1.0, < 2)
6
- google-protobuf (~> 3.18)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- ast (2.4.2)
12
- concurrent-ruby (1.1.9)
13
- cool.io (1.7.1)
14
- fluentd (1.14.1)
15
- bundler
16
- cool.io (>= 1.4.5, < 2.0.0)
17
- http_parser.rb (>= 0.5.1, < 0.8.0)
18
- msgpack (>= 1.3.1, < 2.0.0)
19
- serverengine (>= 2.2.2, < 3.0.0)
20
- sigdump (~> 0.2.2)
21
- strptime (>= 0.2.2, < 1.0.0)
22
- tzinfo (>= 1.0, < 3.0)
23
- tzinfo-data (~> 1.0)
24
- webrick (>= 1.4.2, < 1.8.0)
25
- yajl-ruby (~> 1.0)
26
- google-protobuf (3.18.1-x86_64-linux)
27
- http_parser.rb (0.7.0)
28
- msgpack (1.4.2)
29
- parallel (1.21.0)
30
- parser (3.0.2.0)
31
- ast (~> 2.4.1)
32
- power_assert (2.0.1)
33
- rainbow (3.0.0)
34
- rake (13.0.6)
35
- regexp_parser (2.1.1)
36
- rexml (3.2.5)
37
- rubocop (1.22.1)
38
- parallel (~> 1.10)
39
- parser (>= 3.0.0.0)
40
- rainbow (>= 2.2.2, < 4.0)
41
- regexp_parser (>= 1.8, < 3.0)
42
- rexml
43
- rubocop-ast (>= 1.12.0, < 2.0)
44
- ruby-progressbar (~> 1.7)
45
- unicode-display_width (>= 1.4.0, < 3.0)
46
- rubocop-ast (1.12.0)
47
- parser (>= 3.0.1.1)
48
- rubocop-rake (0.6.0)
49
- rubocop (~> 1.0)
50
- ruby-progressbar (1.11.0)
51
- serverengine (2.2.4)
52
- sigdump (~> 0.2.2)
53
- sigdump (0.2.4)
54
- strptime (0.2.5)
55
- test-unit (3.3.9)
56
- power_assert
57
- tzinfo (2.0.4)
58
- concurrent-ruby (~> 1.0)
59
- tzinfo-data (1.2021.3)
60
- tzinfo (>= 1.0.0)
61
- unicode-display_width (2.1.0)
62
- webrick (1.7.0)
63
- yajl-ruby (1.4.1)
64
-
65
- PLATFORMS
66
- x86_64-linux
67
-
68
- DEPENDENCIES
69
- bundler (~> 2.2.22)
70
- fluent-plugin-formatter-protobuf!
71
- rake (~> 13.0.3)
72
- rubocop (~> 1.22.1)
73
- rubocop-rake (~> 0.6.0)
74
- test-unit (~> 3.3.7)
75
-
76
- BUNDLED WITH
77
- 2.2.29
@@ -1 +0,0 @@
1
- people: [{name:"Masahiro", id: 1337, email: "repeatedly _at_ gmail.com"}]
@@ -1,4 +0,0 @@
1
-
2
- (
3
- Masahiro�
4
- repeatedly _at_ gmail.com