fluent-plugin-formatter-protobuf 0.0.3 → 0.1.1
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/.github/workflows/build-and-test.yml +54 -0
- data/.github/workflows/codeql-analysis.yml +49 -0
- data/.github/workflows/publish.yml +96 -0
- data/.gitignore +2 -2
- data/.rubocop.yml +7 -4
- data/.ruby-version +1 -1
- data/README.md +109 -10
- data/RELEASE.md +9 -0
- data/Rakefile +5 -0
- data/fluent-plugin-formatter-protobuf.gemspec +9 -5
- data/lib/fluent/plugin/formatter_protobuf.rb +15 -21
- data/lib/fluent/plugin/version.rb +1 -3
- data/test/integration/Gemfile +6 -0
- data/{Gemfile.lock → test/integration/Gemfile.lock} +11 -19
- data/test/integration/README.md +12 -0
- data/test/integration/fluent.conf +25 -0
- data/test/integration/log.proto +6 -0
- data/test/integration/log_pb.rb +15 -0
- data/test/integration/run.sh +12 -0
- data/test/plugin/test_formatter_protobuf.rb +45 -9
- metadata +72 -18
- data/.github/workflows/gem-push.yml +0 -19
- data/package.json +0 -58
- data/test/proto/addressbook +0 -1
- data/test/proto/addressbook.bin +0 -4
- data/yarn.lock +0 -3725
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca1a8fea393af2eed56eac08ac8fe4f8122d0c1e5b5d36099580ff9e0c962c67
|
4
|
+
data.tar.gz: 9670c004adcabfe98e6ae98fe46a45ebe2a55e08df52d08e169fa149af2d032b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e8f996d0940c53666eae2cea2b7d9b47a6d57a15d6c2038c7d83accf592d89018e8c864731e5b574449cc7c5d2a9b4ea6f4153cbb9dbdd4de84cc3e5c8a57ec
|
7
|
+
data.tar.gz: 6b398f92c55ad9f8f6bc92b8da8947a887fa8bc3b3bd838c7973552e8aa12e353e04fcd76e13f9d314ace7429ced3c47b877b69f4d8b6270f7aefcfc0cb72758
|
@@ -0,0 +1,54 @@
|
|
1
|
+
name: Build and test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
lint:
|
9
|
+
name: Lint
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
packages: write
|
13
|
+
contents: read
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby 2.5
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
bundler-cache: true
|
21
|
+
- name: "Unit test"
|
22
|
+
run: "bundle exec rake lint:check"
|
23
|
+
|
24
|
+
test:
|
25
|
+
name: Unit test
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
packages: write
|
29
|
+
contents: read
|
30
|
+
|
31
|
+
steps:
|
32
|
+
- uses: actions/checkout@v2
|
33
|
+
- name: Set up Ruby 2.5
|
34
|
+
uses: ruby/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
bundler-cache: true
|
37
|
+
- name: "Unit test"
|
38
|
+
run: "bundle exec rake test:unit"
|
39
|
+
|
40
|
+
build:
|
41
|
+
name: Build
|
42
|
+
runs-on: ubuntu-latest
|
43
|
+
permissions:
|
44
|
+
packages: write
|
45
|
+
contents: read
|
46
|
+
|
47
|
+
steps:
|
48
|
+
- uses: actions/checkout@v2
|
49
|
+
- name: Set up Ruby 2.5
|
50
|
+
uses: ruby/setup-ruby@v1
|
51
|
+
with:
|
52
|
+
bundler-cache: true
|
53
|
+
- name: "Unit test"
|
54
|
+
run: "bundle exec rake build"
|
@@ -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
|
@@ -0,0 +1,96 @@
|
|
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}}"
|
data/.gitignore
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
*.gem
|
2
|
+
Gemfile.lock
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
require: rubocop-rake
|
1
2
|
AllCops:
|
2
3
|
NewCops: enable
|
3
4
|
Style/StringLiterals:
|
4
5
|
Exclude:
|
5
|
-
- '
|
6
|
+
- '**/*_pb.rb'
|
6
7
|
Style/HashSyntax:
|
7
8
|
Exclude:
|
8
|
-
- '
|
9
|
+
- '**/*_pb.rb'
|
9
10
|
Style/FrozenStringLiteralComment:
|
10
11
|
Exclude:
|
11
|
-
- '
|
12
|
+
- '**/*_pb.rb'
|
12
13
|
Metrics/MethodLength:
|
13
|
-
Max: 100
|
14
|
+
Max: 100
|
15
|
+
Exclude:
|
16
|
+
- '**/*_pb.rb'
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0
|
data/README.md
CHANGED
@@ -1,21 +1,40 @@
|
|
1
1
|
# fluent-plugin-formatter-protobuf
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/fluent-plugin-formatter-protobuf)
|
4
|
+
|
3
5
|
[Fluentd](https://fluentd.org/) formatter plugin to format messages into Protobuf v3 encoded binary.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
### RubyGems
|
8
10
|
|
9
|
-
```
|
11
|
+
```shell
|
10
12
|
$ gem install fluent-plugin-formatter-protobuf
|
11
13
|
```
|
12
14
|
|
13
|
-
###
|
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)
|
14
25
|
|
15
26
|
Add following line to your Gemfile:
|
16
27
|
|
17
28
|
```ruby
|
18
|
-
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
|
19
38
|
```
|
20
39
|
|
21
40
|
And then execute:
|
@@ -24,18 +43,98 @@ And then execute:
|
|
24
43
|
$ bundle
|
25
44
|
```
|
26
45
|
|
46
|
+
## Quick start
|
47
|
+
|
48
|
+
1. Generate the protobuf ruby methods
|
49
|
+
1. e.g `protoc --proto_path=. --ruby_out=. ./log.proto`
|
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
|
54
|
+
|
55
|
+
This plugin only supports Protobuf v3.
|
56
|
+
|
57
|
+
## Example
|
58
|
+
|
59
|
+
```aconf
|
60
|
+
<source>
|
61
|
+
@type tcp
|
62
|
+
tag tcp.events
|
63
|
+
port 5170
|
64
|
+
delimiter "\n"
|
65
|
+
<parse>
|
66
|
+
@type json
|
67
|
+
</parse>
|
68
|
+
</source>
|
69
|
+
|
70
|
+
<match tcp.events>
|
71
|
+
@type kafka2
|
72
|
+
|
73
|
+
brokers "#{BROKER_ENDPOINTS}"
|
74
|
+
compression_codec lz4
|
75
|
+
|
76
|
+
<buffer topic>
|
77
|
+
@type memory
|
78
|
+
flush_interval 5s
|
79
|
+
</buffer>
|
80
|
+
|
81
|
+
<format>
|
82
|
+
@type protobuf
|
83
|
+
class_name "Log"
|
84
|
+
include_paths ["/opt/fluent-plugin-formatter-protobuf/log_pb.rb"]
|
85
|
+
</format>
|
86
|
+
</match>
|
87
|
+
```
|
88
|
+
|
27
89
|
## Configuration
|
28
90
|
|
29
|
-
|
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` |
|
96
|
+
|
97
|
+
## Tips
|
98
|
+
|
99
|
+
#### 1. I have multiple `_pb.rb` files and they depend on one another. When I use this plugin, I'm getting a `LoadError`.
|
100
|
+
|
101
|
+
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`.
|
102
|
+
|
103
|
+
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`.
|
104
|
+
|
105
|
+
You can either order them in appropriate dependency order, such as
|
106
|
+
|
107
|
+
```aconf
|
108
|
+
<format>
|
109
|
+
@type protobuf
|
110
|
+
class_name "SomePackage.A"
|
111
|
+
include_paths ["/some/path/b_pb.rb", "/some/path/a_pb.rb"]
|
112
|
+
</format>
|
30
113
|
|
31
114
|
```
|
32
|
-
|
115
|
+
|
116
|
+
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.
|
117
|
+
|
118
|
+
e.g.
|
119
|
+
|
120
|
+
```aconf
|
121
|
+
<format>
|
122
|
+
@type protobuf
|
123
|
+
class_name "SomePackage.A"
|
124
|
+
include_paths ["/some/path/a_pb.rb"]
|
125
|
+
</format>
|
126
|
+
|
33
127
|
```
|
34
128
|
|
35
|
-
|
129
|
+
```shell
|
130
|
+
|
131
|
+
export RUBYLIB="${RUBYLIB}:/some/path/"
|
132
|
+
fluentd \
|
133
|
+
--gemfile "/some/other/path/Gemfile" \
|
134
|
+
--config "/some/other/path/fluent.conf"
|
135
|
+
|
136
|
+
```
|
36
137
|
|
37
|
-
##
|
138
|
+
## License
|
38
139
|
|
39
|
-
|
40
|
-
* License
|
41
|
-
* Apache License, Version 2.0
|
140
|
+
[Apache License, Version 2.0](./LICENSE)
|
data/RELEASE.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Release
|
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
|
data/Rakefile
CHANGED
@@ -6,15 +6,16 @@ require 'fluent/plugin/version'
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'fluent-plugin-formatter-protobuf'
|
9
|
-
spec.version = Fluent::Plugin::
|
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.
|
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,9 +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
|
32
|
-
spec.add_development_dependency 'rake', '~> 13.0
|
33
|
-
spec.add_development_dependency '
|
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'
|
34
37
|
spec.add_runtime_dependency 'fluentd', ['>= 1.0', '< 2']
|
35
38
|
spec.add_runtime_dependency 'google-protobuf', ['~> 3.18']
|
39
|
+
spec.add_runtime_dependency 'oj', '~> 3.13'
|
36
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,12 @@ module Fluent
|
|
29
30
|
class ProtobufFormatter < Fluent::Plugin::Formatter
|
30
31
|
Fluent::Plugin.register_formatter('protobuf', self)
|
31
32
|
|
32
|
-
|
33
|
-
config_param :include_paths, :array, default: []
|
33
|
+
config_param :include_paths, :array, default: [], desc: 'Generated Ruby Protobuf class files path'
|
34
34
|
|
35
|
-
|
36
|
-
|
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
|
37
39
|
|
38
40
|
def configure(conf)
|
39
41
|
super(conf)
|
@@ -42,10 +44,10 @@ module Fluent
|
|
42
44
|
|
43
45
|
@include_paths.each { |path| require_proto!(path) } unless @include_paths.empty?
|
44
46
|
|
45
|
-
|
46
|
-
raise Fluent::ConfigError, "
|
47
|
+
class_lookup = Google::Protobuf::DescriptorPool.generated_pool.lookup(@class_name)
|
48
|
+
raise Fluent::ConfigError, "class name '#{@class_name}' not found" if class_lookup.nil?
|
47
49
|
|
48
|
-
@protobuf_class =
|
50
|
+
@protobuf_class = class_lookup.msgclass
|
49
51
|
end
|
50
52
|
|
51
53
|
def formatter_type
|
@@ -53,26 +55,18 @@ module Fluent
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def format(_tag, _time, record)
|
56
|
-
protobuf_msg = @protobuf_class.new(record)
|
58
|
+
protobuf_msg = @decode_json ? @protobuf_class.decode_json(Oj.dump(record)) : @protobuf_class.new(record)
|
57
59
|
@protobuf_class.encode(protobuf_msg)
|
58
60
|
end
|
59
61
|
|
60
|
-
# @param [string] filename
|
61
|
-
# @return [void]
|
62
62
|
def require_proto!(filename)
|
63
|
-
|
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
|
63
|
+
if Pathname.new(filename).absolute?
|
72
64
|
require filename
|
73
|
-
|
74
|
-
|
65
|
+
else
|
66
|
+
require_relative filename
|
75
67
|
end
|
68
|
+
rescue LoadError => e
|
69
|
+
raise Fluent::ConfigError, "Unable to load file '#{filename}'. Reason: #{e.inspect}"
|
76
70
|
end
|
77
71
|
end
|
78
72
|
end
|
@@ -1,53 +1,45 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
fluent-plugin-formatter-protobuf (0.0.3)
|
5
|
-
fluentd (>= 1.0, < 2)
|
6
|
-
google-protobuf (~> 3.18)
|
7
|
-
|
8
1
|
GEM
|
9
2
|
remote: https://rubygems.org/
|
10
3
|
specs:
|
11
4
|
concurrent-ruby (1.1.9)
|
12
5
|
cool.io (1.7.1)
|
13
|
-
|
6
|
+
fluent-plugin-formatter-protobuf (0.1.0)
|
7
|
+
fluentd (>= 1.0, < 2)
|
8
|
+
google-protobuf (~> 3.18)
|
9
|
+
fluentd (1.14.2)
|
14
10
|
bundler
|
15
11
|
cool.io (>= 1.4.5, < 2.0.0)
|
16
12
|
http_parser.rb (>= 0.5.1, < 0.8.0)
|
17
13
|
msgpack (>= 1.3.1, < 2.0.0)
|
18
14
|
serverengine (>= 2.2.2, < 3.0.0)
|
19
15
|
sigdump (~> 0.2.2)
|
20
|
-
strptime (>= 0.2.
|
16
|
+
strptime (>= 0.2.4, < 1.0.0)
|
21
17
|
tzinfo (>= 1.0, < 3.0)
|
22
18
|
tzinfo-data (~> 1.0)
|
23
19
|
webrick (>= 1.4.2, < 1.8.0)
|
24
20
|
yajl-ruby (~> 1.0)
|
25
|
-
google-protobuf (3.
|
21
|
+
google-protobuf (3.19.1)
|
22
|
+
google-protobuf (3.19.1-x86_64-linux)
|
26
23
|
http_parser.rb (0.7.0)
|
27
24
|
msgpack (1.4.2)
|
28
|
-
power_assert (2.0.1)
|
29
|
-
rake (13.0.6)
|
30
25
|
serverengine (2.2.4)
|
31
26
|
sigdump (~> 0.2.2)
|
32
27
|
sigdump (0.2.4)
|
33
28
|
strptime (0.2.5)
|
34
|
-
test-unit (3.3.9)
|
35
|
-
power_assert
|
36
29
|
tzinfo (2.0.4)
|
37
30
|
concurrent-ruby (~> 1.0)
|
38
|
-
tzinfo-data (1.2021.
|
31
|
+
tzinfo-data (1.2021.5)
|
39
32
|
tzinfo (>= 1.0.0)
|
40
33
|
webrick (1.7.0)
|
41
34
|
yajl-ruby (1.4.1)
|
42
35
|
|
43
36
|
PLATFORMS
|
37
|
+
ruby
|
44
38
|
x86_64-linux
|
45
39
|
|
46
40
|
DEPENDENCIES
|
47
|
-
|
48
|
-
|
49
|
-
rake (~> 13.0.3)
|
50
|
-
test-unit (~> 3.3.7)
|
41
|
+
fluent-plugin-formatter-protobuf (= 0.1.0)
|
42
|
+
fluentd (= 1.14.2)
|
51
43
|
|
52
44
|
BUNDLED WITH
|
53
45
|
2.2.29
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Integration test
|
2
|
+
|
3
|
+
A _manual_ integration test.
|
4
|
+
|
5
|
+
### Instructions
|
6
|
+
|
7
|
+
1. Open a new terminal and run`$ ./run.sh`
|
8
|
+
2. Open a separate terminal and run `echo '{"timestamp": 1634386250, "message":"hello!"}\n' | netcat 127.0.0.1 5170`
|
9
|
+
3. Somehow flush data (I simply stop the docker container)
|
10
|
+
4. Verify out data (It should look like `out.YYYYMMDD_N.log`) with `protoc`
|
11
|
+
1. `protoc --decode_raw < out.YYYYMMDD_N.log`
|
12
|
+
2. `cat out.YYYYMMDD_N.log | protoc --decode=Log --proto_path=. log.proto`
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<source>
|
2
|
+
@type tcp
|
3
|
+
tag tcp.events
|
4
|
+
port 5170
|
5
|
+
delimiter "\n"
|
6
|
+
<parse>
|
7
|
+
@type json
|
8
|
+
</parse>
|
9
|
+
</source>
|
10
|
+
|
11
|
+
<match tcp.events>
|
12
|
+
@type file
|
13
|
+
|
14
|
+
path /opt/fluent-plugin-formatter-protobuf/out
|
15
|
+
|
16
|
+
<buffer>
|
17
|
+
@type memory
|
18
|
+
</buffer>
|
19
|
+
|
20
|
+
<format>
|
21
|
+
@type protobuf
|
22
|
+
class_name "Log"
|
23
|
+
include_paths ["/opt/fluent-plugin-formatter-protobuf/log_pb.rb"]
|
24
|
+
</format>
|
25
|
+
</match>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: log.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
|
+
add_file("log.proto", :syntax => :proto3) do
|
8
|
+
add_message "Log" do
|
9
|
+
optional :timestamp, :int64, 1
|
10
|
+
optional :message, :string, 2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Log = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Log").msgclass
|