fluent-plugin-inline-classifier 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-inline-classifier.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,47 @@
1
+ # fluent-plugin-inline-classifier
2
+ [![Build Status](https://drone.io/github.com/yosisa/fluent-plugin-inline-classifier/status.png)](https://drone.io/github.com/yosisa/fluent-plugin-inline-classifier/latest)
3
+
4
+ fluent-plugin-inline-classifier is a plugin for [Fluentd](http://fluentd.org), which provides some features to classify each incoming message. A new keys added into the message and that values hold classified result by user-defined rules.
5
+
6
+ This is especially useful for converting numeric values into some categories. Because categories are limited, classified messages is easy to grep, or even easy to search by Elasticsearch and Kibana!
7
+
8
+ The plugin tested on ruby 1.9.3-p448 and fluentd-0.10.45.
9
+
10
+ ## Installation
11
+ Using gem:
12
+
13
+ $ gem install fluent-plugin-inline-classifier
14
+
15
+ ## Configuration
16
+ To use the plugin, specify `type` to `inline_classifier`. Also, `add_prefix` and `remove_prefix` are needed in most cases to prevent the loop.
17
+
18
+ Each classifying rule is specified in the `rule` section. `rule` sections can be written multiple times.
19
+
20
+ * `key`: specifies the input key of each message, the corresponding value is used to classify.
21
+ * `type`: specifies classifier type, currently supported value is `range` only.
22
+ * `store`: specifies the output key of each message, a classified result stores to the corresponding value.
23
+ * `classN`: specifies class name and conditions which depend on classifier type. `N` is a integer number. Classifiers evaluate conditions in the order of N and determine what a class is by a first matching condition.
24
+
25
+ ### range classifier
26
+ Conditions specified as `min max` form. A min value is inclusive, by contrast, a max value is exclusive. min and max values have a special form `*`, which means the classifier no matter what a value is.
27
+
28
+ Note: `* *` is not supported currently.
29
+
30
+ ```
31
+ <match raw.**>
32
+ type inline_classifier
33
+ add_prefix classified
34
+ remove_prefix raw
35
+ <rule>
36
+ key reqtime
37
+ type range
38
+ store speed
39
+ class1 fast * 0.1
40
+ class2 normal 0.1 0.5
41
+ class3 slow 0.5 *
42
+ </rule>
43
+ </match>
44
+ ```
45
+
46
+ ## License
47
+ Apache License, Version 2.0
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.test_files = FileList['test/**/test_*.rb']
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,24 @@
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-inline-classifier"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Yoshihisa Tanaka"]
9
+ spec.email = ["yt.hisa@gmail.com"]
10
+ spec.description = %q{Fluentd plugin to classify each message and inject the result into it}
11
+ spec.summary = %q{Fluentd plugin to classify each message and inject the result into it}
12
+ spec.homepage = ""
13
+ spec.license = "Apache License, Version 2.0"
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
+ requires = ["fluentd"]
21
+ requires.each {|name| spec.add_runtime_dependency name}
22
+ requires += ["rake"]
23
+ requires.each {|name| spec.add_development_dependency name}
24
+ end
@@ -0,0 +1,111 @@
1
+ class Fluent::InlineClassifierOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('inline_classifier', self)
3
+
4
+ class Classifier
5
+ attr_accessor :key
6
+ attr_accessor :store
7
+ attr_accessor :rules
8
+
9
+ def initialize(key, store, rules)
10
+ @key = key
11
+ @store = store
12
+ @rules = rules
13
+ end
14
+
15
+ def classify(record)
16
+ return nil if not record.has_key?(@key)
17
+
18
+ target = record[@key]
19
+ @rules.each {|name, func|
20
+ if func.call(target)
21
+ return name
22
+ end
23
+ }
24
+ return nil
25
+ end
26
+
27
+ def run!(record)
28
+ if (name = classify(record)) != nil
29
+ record[@store] = name
30
+ end
31
+ end
32
+ end
33
+
34
+ class RangeClassifier < Classifier
35
+ def initialize(key, store, rules)
36
+ super
37
+ @rules = []
38
+ rules.each {|name, args|
39
+ args = args.split()
40
+ from = args[0].to_f
41
+ to = args[1].to_f
42
+
43
+ if args[0] == '*'
44
+ func = lambda {|v| v.to_f < to}
45
+ elsif args[1] == '*'
46
+ func = lambda {|v| from <= v.to_f}
47
+ else
48
+ func = lambda {|v| v = v.to_f; from <= v and v < to}
49
+ end
50
+
51
+ @rules << [name, func]
52
+ }
53
+ end
54
+ end
55
+
56
+ CLASSIFIERS = {'range' => RangeClassifier}
57
+
58
+ config_param :add_prefix, :string, :default => 'classified'
59
+ config_param :remove_prefix, :string, :default => nil
60
+
61
+ attr_accessor :classifiers
62
+
63
+ def initialize
64
+ super
65
+ @classifiers = []
66
+ end
67
+
68
+ def configure(conf)
69
+ super
70
+ conf.elements.select {|element|
71
+ element.name == 'rule'
72
+ }.each {|element|
73
+ klass = CLASSIFIERS[element['type']]
74
+ key = element['key']
75
+ element.has_key? 'store' # To suppress unused configuration warning
76
+ store = element.fetch('store', key + '_class')
77
+
78
+ rules = []
79
+ element.keys.each {|key|
80
+ if m = /^class(\d+)$/.match(key)
81
+ rules[m[1].to_i] = element[key].split(' ', 2)
82
+ end
83
+ }
84
+
85
+ @classifiers << klass.new(key, store, rules.compact)
86
+ }
87
+ end
88
+
89
+ def strip_tag_prefix(tag)
90
+ if tag.start_with?(@remove_prefix)
91
+ head = tag[@remove_prefix.length]
92
+ return '' if head == nil
93
+ return tag[@remove_prefix.length+1..-1] if head == '.'
94
+ end
95
+ return tag
96
+ end
97
+
98
+ def emit(tag, es, chain)
99
+ tag = strip_tag_prefix(tag)
100
+ tag = tag.length > 0 ? [@add_prefix, tag].join('.') : @add_prefix
101
+
102
+ es.each {|time, record|
103
+ @classifiers.each {|classifier|
104
+ classifier.run!(record)
105
+ }
106
+ Fluent::Engine.emit(tag, time, record)
107
+ }
108
+
109
+ chain.next
110
+ end
111
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_inline_classifier'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,148 @@
1
+ require 'helper'
2
+
3
+ class ClassifierTest < Test::Unit::TestCase
4
+ def create_classifier
5
+ rules = [['ok', lambda {|v| v == 'yes'}], ['ng', lambda {|v| v == 'no'}]]
6
+ Fluent::InlineClassifierOutput::Classifier.new('answer', 'class', rules)
7
+ end
8
+
9
+ def test_classify
10
+ c = create_classifier
11
+ assert_equal nil, c.classify({})
12
+ assert_equal 'ok', c.classify({'answer' => 'yes'})
13
+ assert_equal 'ng', c.classify({'answer' => 'no'})
14
+ assert_equal nil, c.classify({'answer' => '?'})
15
+ end
16
+
17
+ def test_run!
18
+ c = create_classifier
19
+ _do_test = Proc.new {|record, expected|
20
+ c.run!(record)
21
+ assert_equal expected, record
22
+ }
23
+
24
+ _do_test.call({}, {})
25
+ _do_test.call({'answer' => 'yes'}, {'answer' => 'yes', 'class' => 'ok'})
26
+ _do_test.call({'answer' => 'no'}, {'answer' => 'no', 'class' => 'ng'})
27
+ _do_test.call({'answer' => '?'}, {'answer' => '?'})
28
+ end
29
+ end
30
+
31
+ class RangeClassifierTest < Test::Unit::TestCase
32
+ def test_classify
33
+ rules = {'fast' => '* 0.1', 'normal' => '0.1 0.5', 'slow' => '0.5 *'}
34
+ c = Fluent::InlineClassifierOutput::RangeClassifier.new('time', 'speed', rules)
35
+ assert_equal 'fast', c.classify({'time' => 0})
36
+ assert_equal 'fast', c.classify({'time' => 0.0999999999})
37
+ assert_equal 'normal', c.classify({'time' => 0.1})
38
+ assert_equal 'normal', c.classify({'time' => 0.4999999999})
39
+ assert_equal 'slow', c.classify({'time' => 0.5})
40
+ assert_equal 'slow', c.classify({'time' => 500})
41
+ assert_equal 'normal', c.classify({'time' => '0.1'})
42
+ assert_equal 'slow', c.classify({'time' => '1'})
43
+ end
44
+ end
45
+
46
+ class InlineClassifierOutputTest < Test::Unit::TestCase
47
+ def setup
48
+ Fluent::Test.setup
49
+ end
50
+
51
+ CONFIG = %[
52
+ add_prefix cls
53
+ remove_prefix raw
54
+ <rule>
55
+ key reqtime
56
+ type range
57
+ class1 fast * 0.1
58
+ class2 normal 0.1 0.5
59
+ class3 slow 0.5 *
60
+ </rule>
61
+ <rule>
62
+ key status
63
+ store status_type
64
+ type range
65
+ class10 4xx 400 500
66
+ class1 2xx 200 300
67
+ </rule>
68
+ ]
69
+
70
+ def create_driver(conf=CONFIG, tag='test')
71
+ Fluent::Test::OutputTestDriver.new(Fluent::InlineClassifierOutput, tag).configure(conf)
72
+ end
73
+
74
+ def test_configure
75
+ plugin = create_driver(%[]).instance
76
+ assert_equal 'classified', plugin.add_prefix
77
+ assert_equal nil, plugin.remove_prefix
78
+ assert_equal [], plugin.classifiers
79
+
80
+ plugin = create_driver.instance
81
+ assert_equal 'cls', plugin.add_prefix
82
+ assert_equal 'raw', plugin.remove_prefix
83
+ assert_equal 2, plugin.classifiers.length
84
+
85
+ classifier = plugin.classifiers[0]
86
+ assert_equal Fluent::InlineClassifierOutput::RangeClassifier, classifier.class
87
+ assert_equal 'reqtime', classifier.key
88
+ assert_equal 'reqtime_class', classifier.store
89
+ assert_equal 3, classifier.rules.length
90
+ assert_equal ['fast', 'normal', 'slow'], classifier.rules.map {|x| x[0]}
91
+
92
+ classifier = plugin.classifiers[1]
93
+ assert_equal Fluent::InlineClassifierOutput::RangeClassifier, classifier.class
94
+ assert_equal 'status', classifier.key
95
+ assert_equal 'status_type', classifier.store
96
+ assert_equal 2, classifier.rules.length
97
+ assert_equal ['2xx', '4xx'], classifier.rules.map {|x| x[0]}
98
+
99
+ classifier = create_driver(%[
100
+ <rule>
101
+ key reqtime
102
+ type range
103
+ class1 ~20ms * 0.02
104
+ class2 20-100ms 0.02 0.1
105
+ class3 100ms~ 0.1 *
106
+ </rule>
107
+ ]).instance.classifiers[0]
108
+ assert_equal Fluent::InlineClassifierOutput::RangeClassifier, classifier.class
109
+ assert_equal 'reqtime', classifier.key
110
+ assert_equal 'reqtime_class', classifier.store
111
+ assert_equal 3, classifier.rules.length
112
+ assert_equal ['~20ms', '20-100ms', '100ms~'], classifier.rules.map {|x| x[0]}
113
+ end
114
+
115
+ def test_strip_tag_prefix
116
+ plugin = create_driver.instance
117
+ assert_equal 'foo', plugin.strip_tag_prefix('foo')
118
+ assert_equal '', plugin.strip_tag_prefix('raw')
119
+ assert_equal 'foo', plugin.strip_tag_prefix('raw.foo')
120
+ assert_equal 'foo.bar', plugin.strip_tag_prefix('raw.foo.bar')
121
+ assert_equal 'foo.raw.bar', plugin.strip_tag_prefix('foo.raw.bar')
122
+ end
123
+
124
+ def test_emit
125
+ d = create_driver
126
+ now = Time.now.to_i
127
+ d.expect_emit('cls.test', now, {'reqtime' => 0.2, 'reqtime_class' => 'normal'})
128
+ d.expect_emit('cls', now, {'status' => 200, 'status_type' => '2xx'})
129
+ d.expect_emit('cls.foo', now, {'reqtime' => 1, 'reqtime_class' => 'slow',
130
+ 'status' => 404, 'status_type' => '4xx'})
131
+
132
+ d.run {
133
+ d.emit({'reqtime' => 0.2}, now)
134
+ d.tag = 'raw'
135
+ d.emit({'status' => 200}, now)
136
+ d.tag = 'raw.foo'
137
+ d.emit({'reqtime' => 1, 'status' => 404}, now)
138
+ }
139
+
140
+ d = create_driver(%[
141
+ add_prefix cls
142
+ ], 'foo')
143
+ d.expect_emit('cls.foo', now, {'status' => 200})
144
+ d.run {
145
+ d.emit({'status' => 200}, now)
146
+ }
147
+ end
148
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-inline-classifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yoshihisa Tanaka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Fluentd plugin to classify each message and inject the result into it
63
+ email:
64
+ - yt.hisa@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - fluent-plugin-inline-classifier.gemspec
75
+ - lib/fluent/plugin/out_inline_classifier.rb
76
+ - test/helper.rb
77
+ - test/plugin/test_out_inline_classifier.rb
78
+ homepage: ''
79
+ licenses:
80
+ - Apache License, Version 2.0
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ segments:
92
+ - 0
93
+ hash: 3650910587117014165
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ segments:
101
+ - 0
102
+ hash: 3650910587117014165
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.23
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Fluentd plugin to classify each message and inject the result into it
109
+ test_files:
110
+ - test/helper.rb
111
+ - test/plugin/test_out_inline_classifier.rb