fluent-plugin-formatter-protobuf 0.2.0 → 0.3.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: ab1edaa0c55c3e7c3174c18c682aa96a6a07056d6017dc5180cea1c988a03189
4
- data.tar.gz: 8a10cffebdd8e605465f61ba8e30dbcf6da7b332ecb44f8bd08b60cf2dbf4539
3
+ metadata.gz: e6218edd36cd2e7186b2def09700237885d5851931a15ad3859b8eecdc8fd1ca
4
+ data.tar.gz: f609d96e5a3dd326ee0cc5d9a9638942ed9f9f063f34bca7ad696176ed58f589
5
5
  SHA512:
6
- metadata.gz: 6d0a30cb1342b7fdcbe7057d223dacd150dba565d11c29ff2b4395fb35347e76f21463d23af5bbbe6b27882cbbd700ee4b1e5a5eb82d153093c37be812428752
7
- data.tar.gz: 9865e62b40999dcbfcb82d30ab2363f8f704d2f0b8f07612f42165b633da83b3f2adc6df1a948321d75e182fa16abbb0b610da9dbba81a9f5a089376488e0ac9
6
+ metadata.gz: de97c9eed15e2ff1f86a4042412ad59efedad063a6957f052828b5efd5a3e6c888e9a1aa3f2f0c4cc1b1c33b3906a48d91dbd4d1b8dd855ece6c24db2be2742d
7
+ data.tar.gz: 45365b906912baf789221d565b039a44a4c97ac596518da587778ece2e92856b027a6ac5768cfae8fd64c9dd5b4032195ba2fc874c73cb1b804b9c93286c7682
@@ -0,0 +1,48 @@
1
+ on:
2
+ push:
3
+ branches:
4
+ - main
5
+ name: release-please
6
+ jobs:
7
+ release-please:
8
+ environment: main
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: google-github-actions/release-please-action@v2
12
+ id: release
13
+ with:
14
+ token: ${{ secrets.GITHUB_TOKEN }}
15
+ release-type: ruby
16
+ version-file: "lib/fluent/plugin/version.rb"
17
+
18
+ - uses: actions/checkout@v2
19
+
20
+ - name: Set up Ruby 2.5
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ bundler-cache: true
24
+
25
+ - name: Publish to GPR
26
+ run: |
27
+ mkdir -p $HOME/.gem
28
+ touch $HOME/.gem/credentials
29
+ chmod 0600 $HOME/.gem/credentials
30
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
31
+ gem build *.gemspec
32
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
33
+ env:
34
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
35
+ OWNER: ${{ github.repository_owner }}
36
+ if: ${{ steps.release.outputs.release_created }}
37
+
38
+ - name: Publish to RubyGems
39
+ run: |
40
+ mkdir -p $HOME/.gem
41
+ touch $HOME/.gem/credentials
42
+ chmod 0600 $HOME/.gem/credentials
43
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
44
+ gem build *.gemspec
45
+ gem push *.gem
46
+ env:
47
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
48
+ if: ${{ steps.release.outputs.release_created }}
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.2.0"
3
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [0.3.0](https://www.github.com/fluent-plugins-nursery/fluent-plugin-formatter-protobuf/compare/v0.2.0...v0.3.0) (2022-01-13)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add new configuration - `format_field` ([797789b](https://www.github.com/fluent-plugins-nursery/fluent-plugin-formatter-protobuf/commit/797789b38d5a599c2c107979beb7edf66e384bd5))
data/README.md CHANGED
@@ -88,12 +88,13 @@ This plugin only supports Protobuf v3.
88
88
 
89
89
  ## Configuration
90
90
 
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` |
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
+ |format_field| string (optional) | When defined, the plugin will only serialise the record in the given field rather than the whole record. This is potentially useful if you intend to use this formatter with the Kafka output plugin (https://github.com/fluent/fluent-plugin-kafka#output-plugin) for example, where your record contains a field to determine which Kafka topic to write to, or the Kafka headers to include, but you do not wish to include those data in the resulting proto3 binary. Defaults to serialising the entire record. | `''` |
96
+ |include_paths| array (required) | Generated Ruby Protobuf class files path | `[]` |
97
+ |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
 
98
99
  ## Tips
99
100
 
data/RELEASE.md CHANGED
@@ -1,9 +1,4 @@
1
1
  # Release
2
2
 
3
- ## Instructions
4
- To release the gem to Github package manager and Ruby Gems,
5
-
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
3
+ This repository follow conventional commit and semantic versioning, and the release to RubyGems.org and GitHub Ruby
4
+ Repository is managed by [release-please](https://github.com/google-github-actions/release-please-action).
@@ -41,6 +41,19 @@ module Fluent
41
41
  Serializes record from canonical proto3 JSON mapping (https://developers.google.com/protocol-buffers/docs/proto3#json) into binary'
42
42
  DESC
43
43
 
44
+ config_param :format_field,
45
+ :string,
46
+ default: '',
47
+ desc: <<~DESC
48
+ When defined, the plugin will only serialise the record in the given field rather than the whole record.
49
+ This is potentially useful if you intend to use this formatter with the Kafka output plugin
50
+ (https://github.com/fluent/fluent-plugin-kafka#output-plugin) for example, where your record contains
51
+ a field to determine which Kafka topic to write to, or the Kafka headers to include, but you do not
52
+ wish to include those data in the resulting proto3 binary.
53
+
54
+ Defaults to serialising the whole record.
55
+ DESC
56
+
44
57
  config_param :include_paths,
45
58
  :array,
46
59
  default: [],
@@ -73,7 +86,13 @@ module Fluent
73
86
  end
74
87
 
75
88
  def format(_tag, _time, record)
76
- protobuf_msg = @decode_json ? @protobuf_class.decode_json(Oj.dump(record)) : @protobuf_class.new(record)
89
+ format_record = @format_field == '' ? record : record[@format_field]
90
+
91
+ protobuf_msg = if @decode_json
92
+ @protobuf_class.decode_json(Oj.dump(format_record))
93
+ else
94
+ @protobuf_class.new(format_record)
95
+ end
77
96
  @protobuf_class.encode(protobuf_msg)
78
97
  end
79
98
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fluent
4
4
  module Plugin
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -0,0 +1,13 @@
1
+ {
2
+ "packages": {
3
+ ".": {
4
+ "releaseType": "ruby",
5
+ "draft": false,
6
+ "prerelease": false,
7
+ "bumpMinorPreMajor": true,
8
+ "bumpPatchForMinorPreMajor": true,
9
+ "changelogPath": "CHANGELOG.md",
10
+ "versioning": "default"
11
+ }
12
+ }
13
+ }
@@ -18,8 +18,8 @@ GEM
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.19.1)
22
- google-protobuf (3.19.1-x86_64-linux)
21
+ google-protobuf (3.19.2)
22
+ google-protobuf (3.19.2-x86_64-linux)
23
23
  http_parser.rb (0.7.0)
24
24
  msgpack (1.4.2)
25
25
  serverengine (2.2.4)
@@ -51,21 +51,34 @@ class ProtobufFormatterTest < Test::Unit::TestCase
51
51
  end
52
52
  # rubocop:enable Metrics/BlockLength
53
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
- } }] }
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
60
  # rubocop:disable Metrics/BlockLength
61
61
  sub_test_case 'format' do
62
62
  test 'encodes into Protobuf binary' do
63
63
  formatter = create_formatter({ class_name: 'tutorial.AddressBook',
64
64
  include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
65
65
 
66
+ formatted = formatter.format('some-tag', 1234, stub_ruby_hash)
67
+ address_book = Tutorial::AddressBook.new(stub_ruby_hash)
68
+ assert_equal(Tutorial::AddressBook.encode(address_book), formatted)
69
+ end
70
+
71
+ test 'encodes a particular field instead of the entire record if format_field is defined' do
72
+ formatter = create_formatter({ class_name: 'tutorial.AddressBook',
73
+ include_paths: VALID_INCLUDE_PATHS_ABSOLUTE,
74
+ format_field: 'data' })
75
+
66
76
  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 } }] })
77
+ {
78
+ 'topic' => 'some-kafka-topic',
79
+ 'headers' => {},
80
+ 'data' => stub_ruby_hash
81
+ })
69
82
  address_book = Tutorial::AddressBook.new(stub_ruby_hash)
70
83
  assert_equal(Tutorial::AddressBook.encode(address_book), formatted)
71
84
  end
@@ -76,8 +89,16 @@ class ProtobufFormatterTest < Test::Unit::TestCase
76
89
  include_paths: VALID_INCLUDE_PATHS_ABSOLUTE })
77
90
 
78
91
  formatted = formatter.format('some-tag', 1234,
79
- { people: [{ name: 'Masahiro', id: 1337, email: 'repeatedly _at_ gmail.com',
80
- last_updated: '2021-12-02T23:58:25.318Z' }] })
92
+ {
93
+ 'people' => [
94
+ {
95
+ 'name' => 'Masahiro',
96
+ 'id' => 1337,
97
+ 'email' => 'repeatedly _at_ gmail.com',
98
+ 'last_updated' => '2021-12-02T23:58:25.318Z'
99
+ }
100
+ ]
101
+ })
81
102
 
82
103
  address_book = Tutorial::AddressBook.new(stub_ruby_hash)
83
104
  assert_equal(Tutorial::AddressBook.encode(address_book), formatted)
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.2.0
4
+ version: 0.3.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-23 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,10 +138,12 @@ extra_rdoc_files: []
138
138
  files:
139
139
  - ".github/workflows/build-and-test.yml"
140
140
  - ".github/workflows/codeql-analysis.yml"
141
- - ".github/workflows/publish.yml"
141
+ - ".github/workflows/release-please.yml"
142
142
  - ".gitignore"
143
+ - ".release-please-manifest.json"
143
144
  - ".rubocop.yml"
144
145
  - ".ruby-version"
146
+ - CHANGELOG.md
145
147
  - Gemfile
146
148
  - LICENSE
147
149
  - README.md
@@ -152,6 +154,7 @@ files:
152
154
  - fluent-plugin-formatter-protobuf.gemspec
153
155
  - lib/fluent/plugin/formatter_protobuf.rb
154
156
  - lib/fluent/plugin/version.rb
157
+ - release-please-config.json
155
158
  - test/helper.rb
156
159
  - test/integration/Gemfile
157
160
  - test/integration/Gemfile.lock
@@ -1,96 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- push:
5
- tags:
6
- - v0.*
7
-
8
- jobs:
9
- lint:
10
- name: Lint
11
- runs-on: ubuntu-latest
12
- permissions:
13
- packages: write
14
- contents: read
15
-
16
- steps:
17
- - uses: actions/checkout@v2
18
- - name: Set up Ruby 2.5
19
- uses: ruby/setup-ruby@v1
20
- with:
21
- bundler-cache: true
22
- - name: "Unit test"
23
- run: "bundle exec rake lint:check"
24
-
25
- test:
26
- name: Unit test
27
- runs-on: ubuntu-latest
28
- permissions:
29
- packages: write
30
- contents: read
31
-
32
- steps:
33
- - uses: actions/checkout@v2
34
- - name: Set up Ruby 2.5
35
- uses: ruby/setup-ruby@v1
36
- with:
37
- bundler-cache: true
38
- - name: "Unit test"
39
- run: "bundle exec rake test:unit"
40
-
41
- publish-to-gpr:
42
- needs:
43
- - lint
44
- - test
45
- name: Build + Publish to GPR
46
- runs-on: ubuntu-latest
47
- permissions:
48
- packages: write
49
- contents: read
50
-
51
- steps:
52
- - uses: actions/checkout@v2
53
- - name: Set up Ruby 2.5
54
- uses: ruby/setup-ruby@v1
55
- with:
56
- bundler-cache: true
57
-
58
- - name: Publish to GPR
59
- run: |
60
- mkdir -p $HOME/.gem
61
- touch $HOME/.gem/credentials
62
- chmod 0600 $HOME/.gem/credentials
63
- printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
64
- gem build *.gemspec
65
- gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
66
- env:
67
- GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
68
- OWNER: ${{ github.repository_owner }}
69
-
70
- publish-to-ruby-gems:
71
- needs:
72
- - lint
73
- - test
74
- name: Build + Publish to RubyGems
75
- runs-on: ubuntu-latest
76
- permissions:
77
- packages: write
78
- contents: read
79
-
80
- steps:
81
- - uses: actions/checkout@v2
82
- - name: Set up Ruby 2.5
83
- uses: ruby/setup-ruby@v1
84
- with:
85
- bundler-cache: true
86
-
87
- - name: Publish to RubyGems
88
- run: |
89
- mkdir -p $HOME/.gem
90
- touch $HOME/.gem/credentials
91
- chmod 0600 $HOME/.gem/credentials
92
- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
93
- gem build *.gemspec
94
- gem push *.gem
95
- env:
96
- GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"