fluent-plugin-threshold 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db9e91133907aab98d70c390290b03e9d1898232
4
+ data.tar.gz: d8bc2ac9a0db0006e3564302adb7e48ea1b1e1ec
5
+ SHA512:
6
+ metadata.gz: f222aea881afd23b1d6fe469a4722684b991143b9295ffd7986ab99acd8e1fc13be771cc399ff6c7e831385e0f83416fee7fb53eefe20b3261a75ef9119c7788
7
+ data.tar.gz: 894c4801adeae51d73fc46f10500295bd779484770a5ae9b9a80a42398786102a38ea67119db19c0ae2a69a4e97decbac2bb299a797fbd72610695d3f5de4d36
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ matrix:
3
+ include:
4
+ - rvm: 1.9.3
5
+ gemfile: 1.9.3.gemfile
6
+ - rvm: 2.0.0
7
+ gemfile: 2.0.0.gemfile
8
+ - rvm: 2.1.1
9
+ gemfile: 2.1.1.gemfile
10
+ - rvm: 2.3.1
11
+ gemfile: 2.3.1.gemfile
data/1.9.3.gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-threshold.gemspec
4
+ gem 'fluentd', '= 0.10.55'
5
+ gem 'rake', '= 0.9.2.2'
6
+ gem 'fluent-mixin-config-placeholders', '0.3.0'
7
+ gem 'fluent-mixin-plaintextformatter', '0.2.6'
8
+ gemspec
data/2.0.0.gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-threshold.gemspec
4
+ gem 'fluentd', '= 0.10.55'
5
+ gem 'rake', '= 0.9.2.2'
6
+ gem 'fluent-mixin-config-placeholders', '0.3.0'
7
+ gem 'fluent-mixin-plaintextformatter', '0.2.6'
8
+ gemspec
data/2.1.1.gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-threshold.gemspec
4
+ gemspec
data/2.3.1.gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-threshold.gemspec
4
+ gemspec
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at yoshimura-takuya@kayac.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-threshold.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 moulin
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Fluent::Plugin::Threshold
2
+ [![Build Status](https://travis-ci.org/takyoshi/fluent-plugin-threshold.svg?branch=master)](https://travis-ci.org/takyoshi/fluent-plugin-threshold)
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'fluent-plugin-threshold'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fluent-plugin-threshold
19
+
20
+ ## Usage
21
+
22
+ configuration:
23
+ ```xml
24
+ <match th>
25
+ type threshold
26
+ condition ge
27
+ threshold 15
28
+ target_key count
29
+ add_tag_prefix th.
30
+ </match>
31
+ ```
32
+
33
+
34
+ input JSON:
35
+ ```json
36
+ {"user_id": "123", "count": 11, "uri": "/*"}
37
+ {"user_id": "125", "count": 13, "uri": "/*"}
38
+ {"user_id": "127", "count": 14, "uri": "/*"}
39
+ {"user_id": "126", "count": 15, "uri": "/*"}
40
+ {"user_id": "124", "count": 16, "uri": "/*"}
41
+ {"user_id": "128", "count": 17, "uri": "/*"}
42
+ ```
43
+
44
+ output JSON:
45
+ ```json
46
+ {"user_id": "126", "count": 15, "uri": "/*"}
47
+ {"user_id": "124", "count": 16, "uri": "/*"}
48
+ {"user_id": "128", "count": 17, "uri": "/*"}
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/takyoshi/fluent-plugin-threshold. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ # -*- mode:ruby -*-
3
+ require "bundler/gem_tasks"
4
+
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.pattern = 'test/**/test_*.rb'
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/threshold"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent/plugin/threshold/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent-plugin-threshold"
8
+ spec.version = Fluent::Plugin::Threshold::VERSION
9
+ spec.authors = ["moulin"]
10
+ spec.email = ["yoshimura-takuya@kayac.com"]
11
+
12
+ spec.summary = %q{fluent-plugin-threshold is the simple filter using a threshold.}
13
+ spec.description = %q{fluent-plugin-threshold filters input by a numeric threshold, and filtered record passes into output as it is.}
14
+ spec.homepage = "https://github.com/takyoshi/fluent-plugin-threshold"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "fluentd", "~> 0.10.0"
24
+ spec.add_runtime_dependency "test-unit", "~> 3.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.7"
27
+ spec.add_development_dependency "rake", "~> 0.9"
28
+ end
@@ -0,0 +1,107 @@
1
+ # coding: utf-8
2
+ module Fluent
3
+ class ThresholdOutput < Output
4
+ include Fluent::HandleTagNameMixin
5
+
6
+ Fluent::Plugin.register_output('threshold', self)
7
+
8
+ config_param :condition, :string
9
+ config_param :threshold, :string
10
+ config_param :target_key, :string
11
+
12
+ unless method_defined?(:router)
13
+ define_method("router") { Fluent::Engine }
14
+ end
15
+
16
+ # <match *>
17
+ # condition eq | ne | gl | ge | lt | le
18
+ # threshold <float> | <integer>
19
+ # target_key <key_name>
20
+ # </match>
21
+ def initialize
22
+ super
23
+ end
24
+
25
+ def configure(conf)
26
+ super
27
+
28
+ @labelled = !conf['@label'].nil?
29
+
30
+ if !@labelled && !@remove_tag_prefix && !@remove_tag_suffix && !@add_tag_prefix && !@add_tag_suffix
31
+ raise ConfigError, "fluent-plugin-threshold: Set 'remove_tag_prefix', 'remove_tag_suffix', 'add_tag_prefix' or 'add_tag_suffix'."
32
+ end
33
+
34
+ # You can also refer raw parameter via conf[name].
35
+ unless @condition
36
+ raise ConfigError, "fluent-plugin-threshold: 'filter' parameter is required"
37
+ end
38
+
39
+ unless @threshold
40
+ raise ConfigError, "fluent-plugin-threshold: 'threshold' parameter is required"
41
+ end
42
+
43
+ unless @target_key
44
+ raise ConfigError, "fluent-plugin-threshold: 'target_key' parameter is required"
45
+ end
46
+ end
47
+
48
+ def start
49
+ super
50
+ end
51
+
52
+ def shutdown
53
+ super
54
+ end
55
+
56
+ # This method is called when an event reaches to Fluentd.
57
+ # Convert the event to a raw string.
58
+ def filter_record(tag, time, record)
59
+ super
60
+
61
+ filter_record = {}
62
+ case @condition
63
+ when "eq"
64
+ if record.member?(@target_key) && record[@target_key].to_f == threshold.to_f
65
+ filter_record = record
66
+ end
67
+ when "ne"
68
+ if record.member?(@target_key) && record[@target_key].to_f != threshold.to_f
69
+ filter_record = record
70
+ end
71
+ when "ge"
72
+ if record.member?(@target_key) && record[@target_key].to_f >= threshold.to_f
73
+ filter_record = record
74
+ end
75
+ when "gt"
76
+ if record.member?(@target_key) && record[@target_key].to_f > threshold.to_f
77
+ filter_record = record
78
+ end
79
+ when "le"
80
+ if record.member?(@target_key) && record[@target_key].to_f <= threshold.to_f
81
+ filter_record = record
82
+ end
83
+ when "lt"
84
+ if record.member?(@target_key) && record[@target_key].to_f < threshold.to_f
85
+ filter_record = record
86
+ end
87
+ else
88
+ raise ArgumentError.new("no such condition: #{@condition}")
89
+ end
90
+
91
+ filter_record
92
+ end
93
+
94
+ def emit(tag, es, chain)
95
+ es.each do |time, record|
96
+ _tag = tag.clone
97
+ record = filter_record(_tag, time, record)
98
+
99
+ if record.any?
100
+ router.emit(_tag, time, record)
101
+ end
102
+ end
103
+
104
+ chain.next
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,7 @@
1
+ module Fluent
2
+ module Plugin
3
+ module Threshold
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-threshold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - moulin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ description: fluent-plugin-threshold filters input by a numeric threshold, and filtered
70
+ record passes into output as it is.
71
+ email:
72
+ - yoshimura-takuya@kayac.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - 1.9.3.gemfile
80
+ - 2.0.0.gemfile
81
+ - 2.1.1.gemfile
82
+ - 2.3.1.gemfile
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - fluent-plugin-threshold.gemspec
91
+ - lib/fluent/plugin/out_threshold.rb
92
+ - lib/fluent/plugin/threshold/version.rb
93
+ homepage: https://github.com/takyoshi/fluent-plugin-threshold
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: fluent-plugin-threshold is the simple filter using a threshold.
117
+ test_files: []