fluent-plugin-formatter-protobuf 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9bcc9a5c80a25b6d30ebbabcbc6596db405738915dad875eb52570df1e793a0b
4
- data.tar.gz: c05073cdb7b669ca81aa29b21fc46d2c50846072b38d3cd749f09666babc62f8
3
+ metadata.gz: f49ca0a97713b1a0771cb9c73b38f49660b5fb4103a6d3f989140013fbd21bab
4
+ data.tar.gz: d547aaeef78fb13b4d5747dcf26fa27f1912e33ee6b4f699db401f335525fa94
5
5
  SHA512:
6
- metadata.gz: efd71e67d8f9388d487d2d6de036c012a29847960f8eab02c39d8c6d08e7b6a20fb4a1c7d622b8fbdb1a06d67666d9a2885edcef2bbb769fc7f3278400102d46
7
- data.tar.gz: 79a3e80a85c12df566a4e59b764487e9cb7e4d66962b0fcb0bbda6f8e840e8c64cc58a407ab948e256e19bf62aea46e0a9fe481b1c445966e9f3c6c2fed39ffe
6
+ metadata.gz: c17daaf911ea6a58cdbd8bd39b25bdf500630a506ab29f384d1abcf01e178578bea74ecf4e9ebff6c0496bf67304324f49b00744d49911bd1db32177d7fbcaed
7
+ data.tar.gz: bc2167f0f05d20594b453a7a40ba25c8e72ae085ed6c72a14714e2cdf617e9050f650b1c1aa1b82b5626f2c83666ef4015c19149deed227c4e0d39d79df910f2
@@ -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
data/README.md CHANGED
@@ -18,7 +18,7 @@ $ gem install fluent-plugin-formatter-protobuf
18
18
  $ gem install \
19
19
  fluent-plugin-formatter-protobuf \
20
20
  --version "<version>" \
21
- --source "https://rubygems.pkg.github.com/raytung"
21
+ --source "https://rubygems.pkg.github.com/fluent-plugins-nursery"
22
22
  ```
23
23
 
24
24
  ### Bundler (RubyGems)
@@ -32,7 +32,7 @@ gem "fluent-plugin-formatter-protobuf", "<version>"
32
32
  ### Bundler (GitHub RubyGems Registry),
33
33
 
34
34
  ```shell
35
- source "https://rubygems.pkg.github.com/raytung" do
35
+ source "https://rubygems.pkg.github.com/fluent-plugins-nursery" do
36
36
  gem "fluent-plugin-formatter-protobuf", "<version>"
37
37
  end
38
38
  ```
@@ -43,11 +43,12 @@ And then execute:
43
43
  $ bundle
44
44
  ```
45
45
 
46
- ## Not so quick start
46
+ ## Quick start
47
47
 
48
48
  1. Generate the protobuf ruby methods
49
49
  1. e.g `protoc --proto_path=. --ruby_out=. ./log.proto`
50
- 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
51
52
 
52
53
 
53
54
  ## Example
@@ -74,7 +75,7 @@ $ bundle
74
75
 
75
76
  <format>
76
77
  @type protobuf
77
- message_name "Log"
78
+ class_name "Log"
78
79
  include_paths ["/opt/fluent-plugin-formatter-protobuf/log_pb.rb"]
79
80
  </format>
80
81
  </match>
@@ -82,13 +83,10 @@ $ bundle
82
83
 
83
84
  ## Configuration
84
85
 
85
- You can generate configuration template:
86
-
87
- ```
88
- $ fluent-plugin-config-format formatter formatter-protobuf
89
- ```
90
-
91
- You can copy and paste generated documents here.
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||
92
90
 
93
91
  ## Copyright
94
92
 
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
@@ -28,11 +28,11 @@ Gem::Specification.new do |spec|
28
28
  spec.test_files = test_files
29
29
  spec.require_paths = ['lib']
30
30
 
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'
31
+ spec.add_development_dependency 'bundler', '~> 2.2'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
33
+ spec.add_development_dependency 'rubocop', '~> 1.22'
34
+ spec.add_development_dependency 'rubocop-rake', '~> 0.6'
35
+ spec.add_development_dependency 'test-unit', '~> 3.3'
36
36
  spec.add_runtime_dependency 'fluentd', ['>= 1.0', '< 2']
37
37
  spec.add_runtime_dependency 'google-protobuf', ['~> 3.18']
38
38
  end
@@ -29,11 +29,9 @@ module Fluent
29
29
  class ProtobufFormatter < Fluent::Plugin::Formatter
30
30
  Fluent::Plugin.register_formatter('protobuf', self)
31
31
 
32
- # Absolute paths to the generated Ruby protobuf files
33
- config_param :include_paths, :array, default: []
32
+ config_param :include_paths, :array, default: [], desc: 'Generated Ruby Protobuf class files path'
34
33
 
35
- # Protobuf message name
36
- config_param :message_name, :string
34
+ config_param :class_name, :string, desc: 'Ruby Protobuf class name. Used to encode into Protobuf binary'
37
35
 
38
36
  def configure(conf)
39
37
  super(conf)
@@ -42,10 +40,10 @@ module Fluent
42
40
 
43
41
  @include_paths.each { |path| require_proto!(path) } unless @include_paths.empty?
44
42
 
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?
43
+ class_lookup = Google::Protobuf::DescriptorPool.generated_pool.lookup(@class_name)
44
+ raise Fluent::ConfigError, "class name '#{@class_name}' not found" if class_lookup.nil?
47
45
 
48
- @protobuf_class = message_lookup.msgclass
46
+ @protobuf_class = class_lookup.msgclass
49
47
  end
50
48
 
51
49
  def formatter_type
@@ -57,22 +55,14 @@ module Fluent
57
55
  @protobuf_class.encode(protobuf_msg)
58
56
  end
59
57
 
60
- # @param [string] filename
61
- # @return [void]
62
58
  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
59
+ if Pathname.new(filename).absolute?
72
60
  require filename
73
- rescue LoadError => e
74
- raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.inspect}"
61
+ else
62
+ require_relative filename
75
63
  end
64
+ rescue LoadError => e
65
+ raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.inspect}"
76
66
  end
77
67
  end
78
68
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fluent
4
4
  module Plugin
5
- VERSION = '0.0.5'
5
+ VERSION = '0.1.0'
6
6
  end
7
7
  end
@@ -8,31 +8,47 @@ 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
+
13
+ # Relative to the plugin file
14
+ VALID_INCLUDE_PATHS_RELATIVE = '../../../test/proto/addressbook_pb.rb'
12
15
 
13
16
  sub_test_case 'configure' do
14
17
  test 'fail if include_paths is empty' do
15
18
  assert_raise(Fluent::ConfigError) do
16
- create_driver({ message_name: '', include_paths: [] })
19
+ create_driver({ class_name: '', include_paths: [] })
20
+ end
21
+ end
22
+
23
+ test 'fail if ruby files not found in the provided include paths' do
24
+ assert_raise(Fluent::ConfigError) do
25
+ create_driver({ class_name: 'tutorial.AddressBook', include_paths: ['some/random/path'] })
17
26
  end
18
27
  end
19
28
 
20
- test 'fail if no protobuf class can be found with message_name' do
29
+ test 'fail if no protobuf class can be found with class_name' do
21
30
  assert_raise(Fluent::ConfigError) do
22
- create_driver({ message_name: 'Some.Name', include_paths: VALID_INCLUDE_PATHS })
31
+ create_driver({ class_name: 'Some.Name', include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
32
+ end
33
+ end
34
+
35
+ test 'success if given valid relative paths in include paths' do
36
+ assert_nothing_raised do
37
+ create_driver({ class_name: 'tutorial.AddressBook', include_paths: [VALID_INCLUDE_PATHS_RELATIVE] })
23
38
  end
24
39
  end
25
40
 
26
41
  test 'passes on valid configuration' do
27
42
  assert_nothing_raised do
28
- create_driver({ message_name: 'tutorial.AddressBook', include_paths: VALID_INCLUDE_PATHS })
43
+ create_driver({ class_name: 'tutorial.AddressBook', include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
29
44
  end
30
45
  end
31
46
  end
32
47
 
33
48
  sub_test_case 'format' do
34
49
  test 'encodes into Protobuf binary' do
35
- formatter = create_formatter({ message_name: 'tutorial.AddressBook', include_paths: VALID_INCLUDE_PATHS })
50
+ formatter = create_formatter({ class_name: 'tutorial.AddressBook',
51
+ include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
36
52
 
37
53
  formatted = formatter.format('some-tag', 1234,
38
54
  { people: [{ name: 'Masahiro', id: 1337, email: 'repeatedly _at_ gmail.com' }] })
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.5
4
+ version: 0.1.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-24 00:00:00.000000000 Z
11
+ date: 2021-10-30 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
@@ -123,6 +123,7 @@ extensions: []
123
123
  extra_rdoc_files: []
124
124
  files:
125
125
  - ".github/workflows/build-and-test.yml"
126
+ - ".github/workflows/codeql-analysis.yml"
126
127
  - ".github/workflows/publish.yml"
127
128
  - ".gitignore"
128
129
  - ".rubocop.yml"