fluent-plugin-num-comparison 0.1.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 +7 -0
- data/.github/workflows/test.yaml +20 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +81 -0
- data/Rakefile +13 -0
- data/fluent-plugin-num-comparison.gemspec +27 -0
- data/lib/fluent/plugin/filter_num_comparison.rb +52 -0
- data/test/helper.rb +8 -0
- data/test/plugin/test_filter_num_comparison.rb +94 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 72074742508a0fa851aea8e1d0b00d7d2e480f308bf92ea11712fe8b784c0cda
|
4
|
+
data.tar.gz: f5a80daddb2ee54bd8cb7b67ab72d1f5828ba334747a13a2339ed03aaec3eefa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9fec99c11d6134e8c9a039596c133695fbf496131d47e2bf3f26b448517df889dcfe1732a27cd6975d9bcac888cb7d13a22d3436df8bab1c2302621f22eb0d6
|
7
|
+
data.tar.gz: ee3f0162b8139ee69c3df234702d3f1f78d6c48f0662748cffe61ca39c106de591ab02176f740a5e3c095e0de2c4170e17f507a4b28fe61c9bcc28b9ecac72f3
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: RakeTest
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby 2.7.2
|
13
|
+
uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.7.2
|
16
|
+
- name: test
|
17
|
+
run: |
|
18
|
+
gem install bundler rake
|
19
|
+
bundle install
|
20
|
+
bundle exec rake test
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 homirun
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# fluent-plugin-num-comparison
|
2
|
+
[](https://github.com/homirun/fluent-plugin-num-comparison/actions/workflows/test.yaml)
|
3
|
+
|
4
|
+
fluent-plugin-num-comparison is a fluent-plugin that compares the value of a specified key with a threshold value and extracts only the larger or smaller ones.
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
### RubyGems
|
10
|
+
```
|
11
|
+
$ gem install fluent-plugin-num-comparison
|
12
|
+
```
|
13
|
+
|
14
|
+
### Bundler
|
15
|
+
|
16
|
+
Add following line to your Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem "fluent-plugin-num-comparison"
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ bundle
|
26
|
+
```
|
27
|
+
|
28
|
+
## Configuration
|
29
|
+
|
30
|
+
### InputExample
|
31
|
+
```json
|
32
|
+
{"access_count": 29},
|
33
|
+
{"access_count": 30},
|
34
|
+
{"access_count": 31},
|
35
|
+
```
|
36
|
+
|
37
|
+
### ConfigExample
|
38
|
+
```
|
39
|
+
<source>
|
40
|
+
@type tail
|
41
|
+
path input.txt
|
42
|
+
pos_file input.pos
|
43
|
+
format json
|
44
|
+
tag test
|
45
|
+
</source>
|
46
|
+
|
47
|
+
<filter test>
|
48
|
+
@type num_comparison
|
49
|
+
record_key access_count
|
50
|
+
threshold 30
|
51
|
+
inequality larger
|
52
|
+
</filter>
|
53
|
+
|
54
|
+
<match test>
|
55
|
+
@type stdout
|
56
|
+
</match>
|
57
|
+
|
58
|
+
```
|
59
|
+
|
60
|
+
### OutputExample
|
61
|
+
```json
|
62
|
+
{"access_count": 30},
|
63
|
+
{"access_count": 31},
|
64
|
+
```
|
65
|
+
|
66
|
+
## Params
|
67
|
+
- record_key: string
|
68
|
+
The key of the event record to be compared.
|
69
|
+
|
70
|
+
- threshold: integer
|
71
|
+
The threshold value to compare with the event record.
|
72
|
+
- inequality: string (`larger` || `smaller`)
|
73
|
+
Decide whether to output a comparison object that is larger or smaller than the threshold.
|
74
|
+
The default value is `larger`.
|
75
|
+
|
76
|
+
|
77
|
+
## Copyright
|
78
|
+
|
79
|
+
* Copyright(c) 2021- homirun
|
80
|
+
* License
|
81
|
+
* MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs.push("lib", "test")
|
8
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
9
|
+
t.verbose = true
|
10
|
+
t.warning = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: [:test]
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "fluent-plugin-num-comparison"
|
6
|
+
spec.version = "0.1.0"
|
7
|
+
spec.authors = ["homirun"]
|
8
|
+
spec.email = ["me@homi.run"]
|
9
|
+
|
10
|
+
spec.summary = %q{This plugin that compares thresholds and extracts only the larger or smaller ones.}
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = "https://github.com/homirun/fluent-plugin-num-comparison"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
test_files, files = `git ls-files -z`.split("\x0").partition do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.files = files
|
19
|
+
spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = test_files
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "test-unit"
|
26
|
+
spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2021- homirun
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "fluent/plugin/filter"
|
17
|
+
|
18
|
+
module Fluent
|
19
|
+
module Plugin
|
20
|
+
class NumComparisonFilter < Fluent::Plugin::Filter
|
21
|
+
Fluent::Plugin.register_filter("num_comparison", self)
|
22
|
+
|
23
|
+
config_param :record_key, :string
|
24
|
+
config_param :threshold, :integer
|
25
|
+
# larger or smaller
|
26
|
+
config_param :inequality, :string, default: "larger"
|
27
|
+
|
28
|
+
def configure(conf)
|
29
|
+
super
|
30
|
+
@record_key = @record_key.to_s
|
31
|
+
@threshold = @threshold.to_i
|
32
|
+
@inequality_flag = @inequality == "smaller" ? 0 : 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def filter_stream(tag, es)
|
36
|
+
new_es = Fluent::MultiEventStream.new
|
37
|
+
es.each do |time, record|
|
38
|
+
if @inequality_flag == 0
|
39
|
+
if record[@record_key].to_i < @threshold
|
40
|
+
new_es.add(time, record)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
if record[@record_key].to_i > @threshold
|
44
|
+
new_es.add(time, record)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
new_es
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
|
2
|
+
require "test-unit"
|
3
|
+
require "fluent/test"
|
4
|
+
require "fluent/test/driver/filter"
|
5
|
+
require "fluent/test/helpers"
|
6
|
+
|
7
|
+
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
8
|
+
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/plugin/filter_num_comparison.rb"
|
3
|
+
|
4
|
+
class NumComparisonFilterTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
sub_test_case 'filter' do
|
10
|
+
test 'If inequality-property is <larger> and the value is larger than the threshold, do not delete record.' do
|
11
|
+
config = %[
|
12
|
+
inequality larger
|
13
|
+
record_key count
|
14
|
+
threshold 10
|
15
|
+
]
|
16
|
+
d = create_driver(config)
|
17
|
+
data = d.run(default_tag: 'test') do
|
18
|
+
d.feed(event_time,
|
19
|
+
{
|
20
|
+
"count" => "11"
|
21
|
+
})
|
22
|
+
end
|
23
|
+
assert_equal 1, data.count
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'If inequality-property is <larger> and the value is smaller than the threshold, delete record.' do
|
27
|
+
config = %[
|
28
|
+
inequality larger
|
29
|
+
record_key count
|
30
|
+
threshold 10
|
31
|
+
]
|
32
|
+
d = create_driver(config)
|
33
|
+
data = d.run(default_tag: 'test') do
|
34
|
+
d.feed(event_time,
|
35
|
+
{
|
36
|
+
"count" => "9"
|
37
|
+
})
|
38
|
+
end
|
39
|
+
assert_equal 0, data.count
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'If inequality-property is <smaller> and the value is smaller than the threshold, do not delete record.' do
|
43
|
+
config = %[
|
44
|
+
inequality smaller
|
45
|
+
record_key count
|
46
|
+
threshold 10
|
47
|
+
]
|
48
|
+
d = create_driver(config)
|
49
|
+
data = d.run(default_tag: 'test') do
|
50
|
+
d.feed(event_time,
|
51
|
+
{
|
52
|
+
"count" => "9"
|
53
|
+
})
|
54
|
+
end
|
55
|
+
assert_equal 1, data.count
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'If inequality-property is <smaller> and the value is larger than the threshold, delete record.' do
|
59
|
+
config = %[
|
60
|
+
inequality smaller
|
61
|
+
record_key count
|
62
|
+
threshold 10
|
63
|
+
]
|
64
|
+
d = create_driver(config)
|
65
|
+
data = d.run(default_tag: 'test') do
|
66
|
+
d.feed(event_time,
|
67
|
+
{
|
68
|
+
"count" => "11"
|
69
|
+
})
|
70
|
+
end
|
71
|
+
assert_equal 0, data.count
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'if the value is equal to the threshold, delete record.' do
|
75
|
+
config = %[
|
76
|
+
inequality smaller
|
77
|
+
record_key count
|
78
|
+
threshold 10
|
79
|
+
]
|
80
|
+
d = create_driver(config)
|
81
|
+
data = d.run(default_tag: 'test') do
|
82
|
+
d.feed(event_time,
|
83
|
+
{
|
84
|
+
"count" => "10"
|
85
|
+
})
|
86
|
+
end
|
87
|
+
assert_equal 0, data.count
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def create_driver(conf)
|
92
|
+
Fluent::Test::Driver::Filter.new(Fluent::Plugin::NumComparisonFilter).configure(conf)
|
93
|
+
end
|
94
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-num-comparison
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- homirun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.10
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 0.14.10
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '2'
|
75
|
+
description: This plugin that compares thresholds and extracts only the larger or
|
76
|
+
smaller ones.
|
77
|
+
email:
|
78
|
+
- me@homi.run
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- ".github/workflows/test.yaml"
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- fluent-plugin-num-comparison.gemspec
|
89
|
+
- lib/fluent/plugin/filter_num_comparison.rb
|
90
|
+
- test/helper.rb
|
91
|
+
- test/plugin/test_filter_num_comparison.rb
|
92
|
+
homepage: https://github.com/homirun/fluent-plugin-num-comparison
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.1.4
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: This plugin that compares thresholds and extracts only the larger or smaller
|
115
|
+
ones.
|
116
|
+
test_files:
|
117
|
+
- test/helper.rb
|
118
|
+
- test/plugin/test_filter_num_comparison.rb
|