fluent-plugin-conditional_filter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cab6711bb735bb3f4cdba2f091567ce6d432645d
4
+ data.tar.gz: 85e70261a231649cc302071c8a49459df4712432
5
+ SHA512:
6
+ metadata.gz: ad91077d850402e1d1a5c373920d92218459b7607a999a382d521e5bfa259b7f8c9c696def3f849daa415b413d6b16483eab9deb8da95a3339b90f8bb8e9f5cd
7
+ data.tar.gz: d29859f4d660c79ed199c5cecc071a5123e692057c2646250020ed827a4bf32d5a1efaaead58b44fa3429071de5be25bf883086242fbf47f1f7e8e386ed9501f
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/
19
+
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - ruby-head
7
+ - rbx-19mode
8
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kentaro Kuribayashi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Fluent::Plugin::ConditionalFilter [![BuildStatus](https://secure.travis-ci.org/kentaro/fluent-plugin-conditional_filter)](http://travis-ci.org/kentaro/fluent-plugin-conditional_filter)
2
+
3
+ ## Component
4
+
5
+ ### ConditionalFilterOutput
6
+
7
+ fluent-plugin-conditional_filter provides a simple filter that filters out key/value pairs that don't match a condition.
8
+
9
+ ## Usage
10
+
11
+ ### Synopsis
12
+
13
+ ```
14
+ <match test.**>
15
+ key_pattern @example.com$
16
+ condition 10
17
+ filter numeric_upward
18
+ </match>
19
+ ```
20
+
21
+ ### Params
22
+
23
+ #### `key_pattern` (required)
24
+
25
+ Key pattern to check.
26
+
27
+ #### `condition` (optional: default = 'http')
28
+
29
+ Condition for the filter below.
30
+
31
+ #### `filter` (required)
32
+
33
+ Set filtering strategy.
34
+
35
+ #### `remove_tag_prefix`, `remove_tag_suffix`, `add_tag_prefix`, `add_tag_suffix`
36
+
37
+ You can also use the params above inherited from [Fluent::HandleTagNameMixin](https://github.com/fluent/fluentd/blob/master/lib/fluent/mixin.rb).
38
+
39
+ ## Installation
40
+
41
+ Add this line to your application's Gemfile:
42
+
43
+ gem 'fluent-plugin-conditional_filter'
44
+
45
+ And then execute:
46
+
47
+ $ bundle
48
+
49
+ Or install it yourself as:
50
+
51
+ $ gem install fluent-plugin-conditional_filter
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
60
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ spec.ruby_opts = %w[-w]
8
+ end
9
+
10
+ task :default => :spec
11
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'fluent-plugin-conditional_filter'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Kentaro Kuribayashi']
9
+ spec.email = ['kentarok@gmail.com']
10
+ spec.description = %q{A fluent plugin that provides conditional filters}
11
+ spec.summary = %q{A fluent plugin that provides conditional filters}
12
+ spec.homepage = 'http://github.com/kentaro/fluent-plugin-conditional_filter'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'fluentd'
21
+
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+ end
26
+
@@ -0,0 +1,53 @@
1
+ class Fluent::ConditionalFilterOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('conditional_filter', self)
3
+
4
+ include Fluent::HandleTagNameMixin
5
+
6
+ config_param :key_pattern, :string
7
+ config_param :condition, :string
8
+ config_param :filter, :string
9
+
10
+ def configure(conf)
11
+ super
12
+
13
+ not_configured_params = %w[key_pattern condition filter].select { |p| !send(p.to_sym) }
14
+ if not_configured_params.any?
15
+ raise Fluent::ConfigError(
16
+ "[out_conditional_filter] missing mandatory parameter: #{not_configured_params.join(',')}"
17
+ )
18
+ end
19
+
20
+ @key_pattern_regexp = /#{key_pattern}/
21
+ end
22
+
23
+ def emit(tag, es, chain)
24
+ es.each do |time, record|
25
+ t = tag.dup
26
+ record = filter_record(t, time, record)
27
+
28
+ if record.any?
29
+ Fluent::Engine.emit(t, time, record)
30
+ end
31
+ end
32
+
33
+ chain.next
34
+ end
35
+
36
+ private
37
+
38
+ def filter_record(tag, time, record)
39
+ case filter
40
+ when 'numeric_upward'
41
+ filter_record = record.select do |key, value|
42
+ key.match(@key_pattern_regexp) &&
43
+ record[key].to_f >= condition.to_f
44
+ end
45
+ else
46
+ raise ArgumentError.new("[out_conditional_filter] no such filter: #{filter}")
47
+ end
48
+
49
+ filter_record
50
+ end
51
+ end
52
+
53
+
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fluent::ConditionalFilterOutput do
4
+ describe '#configure' do
5
+
6
+ context "success" do
7
+ let(:conf) {
8
+ %[
9
+ key_pattern @example.com$
10
+ condition 10
11
+ filter numeric_upward
12
+ ]
13
+ }
14
+
15
+ let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf) }
16
+ subject {
17
+ driver.instance
18
+ }
19
+
20
+ it {
21
+ expect(subject).to be_an_instance_of described_class
22
+ expect(subject.key_pattern).to be == '@example.com$'
23
+ expect(subject.instance_variable_get(:@key_pattern_regexp)).to be == /@example.com$/
24
+ }
25
+ end
26
+
27
+ context "failure" do
28
+ context 'key_pattern not set' do
29
+ let(:conf) {
30
+ %[
31
+ condition 10
32
+ filter numeric_upward
33
+ ]
34
+ }
35
+
36
+ it {
37
+ expect {
38
+ Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf)
39
+ }.to raise_error(Fluent::ConfigError)
40
+ }
41
+ end
42
+
43
+ context 'condition not set' do
44
+ let(:conf) {
45
+ %[
46
+ key_pattern @example.com$
47
+ filter numeric_upward
48
+ ]
49
+ }
50
+
51
+ it {
52
+ expect {
53
+ Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf)
54
+ }.to raise_error(Fluent::ConfigError)
55
+ }
56
+ end
57
+
58
+ context 'filter not set' do
59
+ let(:conf) {
60
+ %[
61
+ key_pattern @example.com$
62
+ condition 10
63
+ ]
64
+ }
65
+
66
+ it {
67
+ expect {
68
+ Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf)
69
+ }.to raise_error(Fluent::ConfigError)
70
+ }
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "#emit" do
76
+ context('numeric_upward') do
77
+ let(:conf) {
78
+ %[
79
+ key_pattern @example.com$
80
+ condition 10
81
+ filter numeric_upward
82
+ ]
83
+ }
84
+
85
+ let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf) }
86
+ subject {
87
+ driver.instance
88
+ }
89
+
90
+ context('with 0 matched key/value pair') do
91
+ before {
92
+ driver.run {
93
+ driver.emit('foo@example.com' => 8, 'bar@example.com' => 6, 'baz@baz.com' => 15)
94
+ }
95
+ }
96
+
97
+ it {
98
+ expect(driver.emits[0]).to be_nil
99
+ }
100
+ end
101
+
102
+ context('with 1 matched key/value pair') do
103
+ before {
104
+ driver.run {
105
+ driver.emit('foo@example.com' => 12, 'bar@example.com' => 6, 'baz@baz.com' => 15)
106
+ }
107
+ }
108
+
109
+ it {
110
+ expect(driver.emits[0][2].keys.length).to be == 1
111
+ }
112
+ end
113
+
114
+ context('with 2 matched key/value pairs') do
115
+ before {
116
+ driver.run {
117
+ driver.emit('foo@example.com' => 12, 'bar@example.com' => 10, 'baz@baz.com' => 15)
118
+ }
119
+ }
120
+
121
+ it {
122
+ expect(driver.emits[0][2].keys.length).to be == 2
123
+ }
124
+ end
125
+ end
126
+ end
127
+ end
128
+
@@ -0,0 +1,24 @@
1
+ require 'fluent/test'
2
+ require 'fluent/plugin/out_conditional_filter'
3
+
4
+ RSpec.configure do |config|
5
+ end
6
+
7
+ unless ENV.has_key?('VERBOSE')
8
+ nulllogger = Object.new
9
+ nulllogger.instance_eval {|obj|
10
+ def message
11
+ @message
12
+ end
13
+
14
+ def reset
15
+ @message = nil
16
+ end
17
+
18
+ def method_missing(method, *args)
19
+ @message = args.first
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-conditional_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kentaro Kuribayashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-11 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'
20
+ type: :runtime
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: bundler
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: rake
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A fluent plugin that provides conditional filters
70
+ email:
71
+ - kentarok@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - fluent-plugin-conditional_filter.gemspec
83
+ - lib/fluent/plugin/out_conditional_filter.rb
84
+ - spec/lib/out_conditional_filter_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: http://github.com/kentaro/fluent-plugin-conditional_filter
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A fluent plugin that provides conditional filters
110
+ test_files:
111
+ - spec/lib/out_conditional_filter_spec.rb
112
+ - spec/spec_helper.rb