fluent-plugin-json 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +38 -0
- data/.rubocop.yml +10 -0
- data/README.md +43 -26
- data/fluent-plugin-json.gemspec +5 -4
- data/test/helper.rb +3 -0
- data/test/plugin/test_filter_json.rb +96 -6
- metadata +34 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cffdd05fc081766a31eff1b72f9f7175967fa7bf3835b258a542e8aae29fdf0c
|
4
|
+
data.tar.gz: b1025d1e3f2886957b2fbc02ed3a4a6f0427b9bae42e6238227d6b309a086878
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6214f18f40adb9bb2d6ddf0e658484096bd032454b1bdd8f6375e254359f09d976da5f56eb23c0713192227784e7108ece9e0c148c6d6fac932318d866ad6523
|
7
|
+
data.tar.gz: 6596c550da1aa829e9441a268dd60ae143f809f77ee724fdac28fc6beb147ca9c673d9d99b93dcb0845bc1fc83e3becc3cbdfa3cafd0c7444babf5af32e54d6b
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: ci
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
paths-ignore:
|
6
|
+
- '**.md'
|
7
|
+
- '.rubocop.yml'
|
8
|
+
pull_request:
|
9
|
+
paths-ignore:
|
10
|
+
- '**.md'
|
11
|
+
- '.rubocop.yml'
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
run-tests:
|
15
|
+
name: Run tests
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
os: [ubuntu-18.04]
|
19
|
+
ruby-version: ['2.5', '2.6', '2.7']
|
20
|
+
|
21
|
+
runs-on: ${{ matrix.os }}
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby-version }}
|
30
|
+
bundler-cache: true
|
31
|
+
|
32
|
+
- name: Bundle install
|
33
|
+
run: |
|
34
|
+
gem install bundler && \
|
35
|
+
bundle install --jobs 4 --retry 3
|
36
|
+
|
37
|
+
- name: Tests
|
38
|
+
run: bundle exec rake test
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# fluent-plugin-json
|
2
2
|
|
3
|
+
[![ci](https://github.com/iamazeem/fluent-plugin-json/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/iamazeem/fluent-plugin-json/actions/workflows/ci.yml)
|
4
|
+
[![License: Apache](https://img.shields.io/badge/license-Apache-blue.svg?style=flat-square)](https://github.com/iamAzeem/fluent-plugin-json/blob/master/LICENSE)
|
5
|
+
![GitHub release (latest by date)](https://img.shields.io/github/v/release/iamAzeem/fluent-plugin-json?style=flat-square)
|
6
|
+
[![RubyGems Downloads](https://img.shields.io/gem/dt/fluent-plugin-json?color=blue&style=flat-square)](https://rubygems.org/gems/fluent-plugin-json)
|
7
|
+
|
8
|
+
![Lines of code](https://img.shields.io/tokei/lines/github/iamAzeem/fluent-plugin-json?label=LOC&style=flat-square)
|
9
|
+
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/iamAzeem/fluent-plugin-json?style=flat-square)
|
10
|
+
![GitHub repo size](https://img.shields.io/github/repo-size/iamAzeem/fluent-plugin-json?style=flat-square)
|
11
|
+
|
3
12
|
[Fluentd](https://fluentd.org/) filter plugin for JSON with JSON pointer support
|
4
13
|
([RFC-6901](https://tools.ietf.org/html/rfc6901)).
|
5
14
|
|
@@ -8,7 +17,7 @@
|
|
8
17
|
### RubyGems
|
9
18
|
|
10
19
|
```bash
|
11
|
-
|
20
|
+
gem install fluent-plugin-json
|
12
21
|
```
|
13
22
|
|
14
23
|
### Bundler
|
@@ -16,13 +25,13 @@ $ gem install fluent-plugin-json
|
|
16
25
|
Add the following line to your Gemfile:
|
17
26
|
|
18
27
|
```ruby
|
19
|
-
gem
|
28
|
+
gem 'fluent-plugin-json'
|
20
29
|
```
|
21
30
|
|
22
31
|
And then execute:
|
23
32
|
|
24
33
|
```bash
|
25
|
-
|
34
|
+
bundle
|
26
35
|
```
|
27
36
|
|
28
37
|
## Configuration
|
@@ -32,26 +41,27 @@ $ bundle
|
|
32
41
|
* `pointer` (string) (required): The JSON pointer to an element.
|
33
42
|
* `pattern` (regexp) (required): The regular expression to match the element.
|
34
43
|
|
35
|
-
The configuration
|
36
|
-
`pointer` to a JSON element and
|
44
|
+
The configuration may consist of one or more checks. Each check contains a
|
45
|
+
`pointer` to a JSON element and its corresponding `pattern` (regex) to test it.
|
37
46
|
|
38
47
|
The checks are evaluated sequentially. The failure of a single check results in
|
39
|
-
rejection of the event. A rejected event is not routed for further
|
48
|
+
the rejection of the event. A rejected event is not routed for further
|
49
|
+
processing.
|
40
50
|
|
41
|
-
NOTE
|
42
|
-
for testing with the `pattern` (
|
51
|
+
**NOTE**: The JSON element pointed to by the `pointer` is always converted to a
|
52
|
+
string for testing with the `pattern` (regex).
|
43
53
|
|
44
|
-
For
|
54
|
+
For the detailed syntax of:
|
45
55
|
|
46
|
-
- JSON Pointer, see [RFC-6901](https://tools.ietf.org/html/rfc6901#section-5)
|
56
|
+
- JSON Pointer, see [RFC-6901](https://tools.ietf.org/html/rfc6901#section-5); and,
|
47
57
|
- Ruby's Regular Expression, see [Regexp](https://ruby-doc.org/core-2.4.1/Regexp.html).
|
48
58
|
|
49
59
|
### Example
|
50
60
|
|
51
|
-
Here is a configuration with
|
52
|
-
[`forward`](https://docs.fluentd.org/v/1.0/input/forward), `json`
|
53
|
-
with multiple checks and routing to
|
54
|
-
[`stdout`](https://docs.fluentd.org/v/1.0/output/stdout):
|
61
|
+
Here is a sample configuration with
|
62
|
+
[`forward`](https://docs.fluentd.org/v/1.0/input/forward) input plugin, `json`
|
63
|
+
filter plugin with multiple checks and the routing to
|
64
|
+
[`stdout`](https://docs.fluentd.org/v/1.0/output/stdout) output plugin:
|
55
65
|
|
56
66
|
```text
|
57
67
|
<source>
|
@@ -65,23 +75,22 @@ with multiple checks and routing to the output plugin
|
|
65
75
|
|
66
76
|
<check>
|
67
77
|
pointer /log/user # point to { "log": { "user": "test", ... } }
|
68
|
-
pattern /test/i # check it against username `test` (ignore case)
|
78
|
+
pattern /test/i # check it against the value of username `test` (ignore case)
|
69
79
|
</check>
|
70
80
|
|
71
81
|
<check>
|
72
82
|
pointer /log/codes/0 # point to { "log": { "codes": [123, ...] } }
|
73
|
-
pattern /123/ # check it against 0th index of codes array
|
83
|
+
pattern /123/ # check it against the value at 0th index of the codes array i.e. `123`
|
74
84
|
</check>
|
75
85
|
|
76
86
|
<check>
|
77
|
-
pointer /log/level # point to { "log": { "level": ... } }
|
78
|
-
pattern /.*/ # check it against all log levels
|
87
|
+
pointer /log/level # point to { "log": { "level": "info", ... } }
|
88
|
+
pattern /.*/ # check it against all the log levels
|
79
89
|
</check>
|
80
90
|
</filter>
|
81
91
|
|
82
92
|
<match debug.test>
|
83
93
|
@type stdout
|
84
|
-
@id stdout_output
|
85
94
|
</match>
|
86
95
|
```
|
87
96
|
|
@@ -94,7 +103,7 @@ For a JSON message:
|
|
94
103
|
Sent using `fluent-cat` with tag `debug.test`:
|
95
104
|
|
96
105
|
```bash
|
97
|
-
|
106
|
+
echo '{ "log": {"user": "test", "codes": [123, 456], "level": "info"} }' | fluent-cat "debug.test"
|
98
107
|
```
|
99
108
|
|
100
109
|
After passing all the checks, the routed event to `stdout` would be:
|
@@ -103,17 +112,25 @@ After passing all the checks, the routed event to `stdout` would be:
|
|
103
112
|
2020-07-23 22:36:06.093187459 +0500 debug.test: {"log":{"user":"test","codes":[123,456],"level":"info"}}
|
104
113
|
```
|
105
114
|
|
106
|
-
By default, the
|
115
|
+
By default, the checks are logged in `debug` mode only:
|
107
116
|
|
108
|
-
```
|
117
|
+
```text
|
109
118
|
2020-07-23 22:47:33 +0500 [debug]: #0 [json_filter] check: pass [/log/user -> 'test'] (/test/)
|
110
119
|
2020-07-23 22:47:33 +0500 [debug]: #0 [json_filter] check: pass [/log/codes/0 -> '123'] (/123/)
|
111
120
|
2020-07-23 22:47:33 +0500 [debug]: #0 [json_filter] check: pass [/log/level -> 'info'] (/.*/)
|
112
121
|
2020-07-23 22:47:33.577900915 +0500 debug.test: {"log":{"user":"test","codes":[123,456],"level":"info"}}
|
113
122
|
```
|
114
123
|
|
115
|
-
##
|
124
|
+
## Contribute
|
125
|
+
|
126
|
+
- Fork the project.
|
127
|
+
- Check out the latest `main` branch.
|
128
|
+
- Create a feature or bugfix branch from `main`.
|
129
|
+
- Commit and push your changes.
|
130
|
+
- Make sure to add and run tests locally: `bundle exec rake test`.
|
131
|
+
- Run `rubocop` locally and fix all the lint warnings.
|
132
|
+
- Submit the PR.
|
133
|
+
|
134
|
+
## License
|
116
135
|
|
117
|
-
|
118
|
-
* License
|
119
|
-
* Apache License, Version 2.0
|
136
|
+
[Apache 2.0](LICENSE)
|
data/fluent-plugin-json.gemspec
CHANGED
@@ -5,12 +5,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'fluent-plugin-json'
|
8
|
-
spec.version = '0.
|
8
|
+
spec.version = '0.2.0'
|
9
9
|
spec.authors = ['Azeem Sajid']
|
10
10
|
spec.email = ['azeem.sajid@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = 'Fluentd filter plugin
|
13
|
-
spec.description = 'Fluentd filter plugin
|
12
|
+
spec.summary = 'Fluentd JSON filter plugin with JSON Pointer Support (RFC-6901)'
|
13
|
+
spec.description = 'Fluentd JSON filter plugin with JSON Pointer Support (RFC-6901) to pinpoint elements.'
|
14
14
|
spec.homepage = 'https://github.com/iamAzeem/fluent-plugin-json'
|
15
15
|
spec.license = 'Apache-2.0'
|
16
16
|
|
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.test_files = test_files
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.0'
|
26
26
|
spec.add_development_dependency 'hana', '~> 1.3', '>= 1.3.6'
|
27
27
|
spec.add_development_dependency 'rake', '~> 12.0'
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.12', '<= 0.12.2'
|
28
29
|
spec.add_development_dependency 'test-unit', '~> 3.0'
|
29
30
|
spec.add_runtime_dependency 'fluentd', ['>= 0.14.10', '< 2']
|
30
31
|
spec.add_runtime_dependency 'hana', '~> 1.3', '>= 1.3.6'
|
data/test/helper.rb
CHANGED
@@ -1,20 +1,110 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'helper'
|
4
|
-
require 'fluent/plugin/filter_json
|
4
|
+
require 'fluent/plugin/filter_json'
|
5
5
|
|
6
6
|
class JsonFilterTest < Test::Unit::TestCase
|
7
7
|
setup do
|
8
8
|
Fluent::Test.setup
|
9
|
+
@time = event_time
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
def create_driver(conf = '')
|
13
|
+
Fluent::Test::Driver::Filter.new(Fluent::Plugin::JsonFilter).configure(conf)
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
sub_test_case 'configure' do
|
17
|
+
test 'test required section <check>' do
|
18
|
+
assert_raise(NameError) do
|
19
|
+
create_driver(conf)
|
20
|
+
end
|
21
|
+
end
|
16
22
|
|
17
|
-
|
18
|
-
|
23
|
+
test 'test required parameters' do
|
24
|
+
conf = %(
|
25
|
+
<check>
|
26
|
+
</check>
|
27
|
+
)
|
28
|
+
assert_raise(Fluent::ConfigError) do
|
29
|
+
create_driver(conf)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'test single check' do
|
34
|
+
conf = %(
|
35
|
+
<check>
|
36
|
+
pointer /test/
|
37
|
+
pattern /.*/
|
38
|
+
</check>
|
39
|
+
)
|
40
|
+
d = create_driver(conf)
|
41
|
+
assert_equal(1, d.instance.check.length)
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'test multiple checks' do
|
45
|
+
conf = %(
|
46
|
+
<check>
|
47
|
+
pointer /test/
|
48
|
+
pattern /.*/
|
49
|
+
</check>
|
50
|
+
<check>
|
51
|
+
pointer /test/
|
52
|
+
pattern /.*/
|
53
|
+
</check>
|
54
|
+
)
|
55
|
+
d = create_driver(conf)
|
56
|
+
assert_equal(2, d.instance.check.length)
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'test invalid pointer (JSON pointer should start with a slash)' do
|
60
|
+
conf = %(
|
61
|
+
<check>
|
62
|
+
pointer .
|
63
|
+
pattern /.*/
|
64
|
+
</check>
|
65
|
+
)
|
66
|
+
assert_raise(Fluent::ConfigError) do
|
67
|
+
create_driver(conf)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
sub_test_case 'filter' do
|
73
|
+
def records
|
74
|
+
[
|
75
|
+
{ 'log' => { 'user' => 'test', 'codes' => [123, 456], 'level' => 'info' } }
|
76
|
+
]
|
77
|
+
end
|
78
|
+
|
79
|
+
def filter(conf, records)
|
80
|
+
d = create_driver(conf)
|
81
|
+
d.run do
|
82
|
+
records.each do |record|
|
83
|
+
d.feed('filter.test', @time, record)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
d.filtered_records
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'test multiple checks' do
|
90
|
+
conf = %(
|
91
|
+
<check>
|
92
|
+
pointer /log/user
|
93
|
+
pattern /test/i
|
94
|
+
</check>
|
95
|
+
|
96
|
+
<check>
|
97
|
+
pointer /log/codes/0
|
98
|
+
pattern /123/
|
99
|
+
</check>
|
100
|
+
|
101
|
+
<check>
|
102
|
+
pointer /log/level
|
103
|
+
pattern /.*/
|
104
|
+
</check>
|
105
|
+
)
|
106
|
+
filtered_records = filter(conf, records)
|
107
|
+
assert_equal(records.values_at(0), filtered_records)
|
108
|
+
end
|
19
109
|
end
|
20
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Azeem Sajid
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
29
|
+
version: '2.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: hana
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +64,26 @@ dependencies:
|
|
58
64
|
- - "~>"
|
59
65
|
- !ruby/object:Gem::Version
|
60
66
|
version: '12.0'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: simplecov
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0.12'
|
74
|
+
- - "<="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.12.2
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.12'
|
84
|
+
- - "<="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 0.12.2
|
61
87
|
- !ruby/object:Gem::Dependency
|
62
88
|
name: test-unit
|
63
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,7 +138,7 @@ dependencies:
|
|
112
138
|
- - ">="
|
113
139
|
- !ruby/object:Gem::Version
|
114
140
|
version: 1.3.6
|
115
|
-
description: Fluentd filter plugin
|
141
|
+
description: Fluentd JSON filter plugin with JSON Pointer Support (RFC-6901) to pinpoint
|
116
142
|
elements.
|
117
143
|
email:
|
118
144
|
- azeem.sajid@gmail.com
|
@@ -120,7 +146,9 @@ executables: []
|
|
120
146
|
extensions: []
|
121
147
|
extra_rdoc_files: []
|
122
148
|
files:
|
149
|
+
- ".github/workflows/ci.yml"
|
123
150
|
- ".gitignore"
|
151
|
+
- ".rubocop.yml"
|
124
152
|
- Gemfile
|
125
153
|
- LICENSE
|
126
154
|
- README.md
|
@@ -152,7 +180,7 @@ rubyforge_project:
|
|
152
180
|
rubygems_version: 2.7.6
|
153
181
|
signing_key:
|
154
182
|
specification_version: 4
|
155
|
-
summary: Fluentd filter plugin
|
183
|
+
summary: Fluentd JSON filter plugin with JSON Pointer Support (RFC-6901)
|
156
184
|
test_files:
|
157
185
|
- test/helper.rb
|
158
186
|
- test/plugin/test_filter_json.rb
|