fluent-plugin-rewrite 0.0.13 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40314ef9366b2cf1732c79b0e5a6ab867730442c
4
- data.tar.gz: 7a457baa66e080cadb1abb01874eb571911a6b37
3
+ metadata.gz: ab3e54318cc3b8fd6ddc45766eb8e035c60d18ea
4
+ data.tar.gz: e6dbbdb1e22264cc26980df004ff0b119f9d5ff7
5
5
  SHA512:
6
- metadata.gz: 05200ecb8ae2de70ef77e99ae5e9355930516dbaa52b6fef0d8b9b1c06af7116815ee21cec74ad9cfcf6ed0d257c79f60ac39e6f4f9eef8462581930ed2da505
7
- data.tar.gz: 323146000fbba0988f5f695643d52ded4121726edc11488ec8f06d08e38592035e811c3f8334fc4be96ef2d2c6e78af17cfdbd9a24475db49d9254a2c3c5ce26
6
+ metadata.gz: 3ac903ed8fd460b43d625e2bcec91d45fc49fcce0dd27d1cb146881a6934d0764e1fa1244f6b5b0b14733708317e875b91cbf5387ac87e727ba3a34203d784a2
7
+ data.tar.gz: 1eb9034188bb8f0724363301e7f7700b5b531628371123ea4d912c7331d7774db720dc7f0887968f300341e70a2a795ea7c4100eb31b388f49b83c60ccd51756
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ gemfile:
3
+ - gemfiles/fluentd_0.14.gemfile
4
+ rvm:
5
+ - 2.3.1
6
+ - 2.2
7
+ - 2.1
8
+ script:
9
+ - bundle exec rake test
@@ -0,0 +1,3 @@
1
+ appraise "fluentd_0.14" do
2
+ gem "fluentd", "~> 0.14.0"
3
+ end
data/README.md CHANGED
@@ -11,7 +11,7 @@ matching and re-emit them.
11
11
 
12
12
  ```
13
13
  <match apache.log.**>
14
- type rewrite
14
+ @type rewrite
15
15
 
16
16
  remove_prefix apache.log
17
17
  add_prefix filtered
@@ -220,6 +220,55 @@ will be replaced by the second rule as usual.
220
220
  { "path" => "/baz" }
221
221
  ```
222
222
 
223
+ ### RewriteFilter
224
+
225
+ Filter plugin to modify messages' values along with pattern
226
+ matching and filter them.
227
+
228
+ Note that filter version of rewrite plugin does not have append/add tags functionality.
229
+
230
+ Thus, this filter version does not able to specify `append_to_tag`, `tag`, and `fallback` rules.
231
+
232
+ ## Synopsis
233
+
234
+ ```
235
+ <filter apache.log.**>
236
+ @type rewrite
237
+
238
+ <rule>
239
+ key path
240
+ pattern \\?.+$
241
+ replace
242
+ </rule>
243
+ <rule>
244
+ key path
245
+ pattern (/[^/]+)\\?([^=]+)=(\\d)
246
+ replace \\1/\\2/\\3
247
+ </rule>
248
+ <rule>
249
+ key status
250
+ pattern ^500$
251
+ ignore true
252
+ </rule>
253
+ </match>
254
+ ```
255
+
256
+ ## Configuration
257
+
258
+ Note: This filter version of rewrite plugin does not have `remove_prefix` and `add_prefix` configuration.
259
+
260
+ ### rule: replace
261
+
262
+ Same as OutputRewrite section's [rule: replace](#rule-replace).
263
+
264
+ ### rule: ignore
265
+
266
+ Same as OutputRewrite section's [rule: ignore](#rule-ignore).
267
+
268
+ ### rule: last
269
+
270
+ Same as OutputRewrite section's [rule: last](#rule-last).
271
+
223
272
  ## Installation
224
273
 
225
274
  Add this line to your application's Gemfile:
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "fluent-plugin-rewrite"
3
- gem.version = '0.0.13'
3
+ gem.version = '0.1.0'
4
4
  gem.authors = ["Kentaro Kuribayashi"]
5
5
  gem.email = ["kentarok@gmail.com"]
6
6
  gem.homepage = "http://github.com/kentaro/fluent-plugin-rewrite"
@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
15
15
 
16
16
  gem.add_development_dependency "rake"
17
17
  gem.add_development_dependency "test-unit", "~> 3.1"
18
- gem.add_runtime_dependency "fluentd"
18
+ gem.add_development_dependency "appraisal"
19
+ gem.add_runtime_dependency "fluentd", [">= 0.14.8", "< 2"]
19
20
  end
20
-
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "fluentd", "~> 0.14.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,26 @@
1
+ module Fluent::Plugin
2
+ class RewriteFilter < Filter
3
+ Fluent::Plugin.register_filter('rewrite', self)
4
+
5
+ attr_reader :rewrite_rule
6
+
7
+ def configure(conf)
8
+ require 'fluent/plugin/rewrite_rule'
9
+
10
+ super
11
+
12
+ @rewrite_rule = Fluent::RewriteRule.new(self, conf)
13
+ end
14
+
15
+ def filter_stream(tag, es)
16
+ new_es = Fluent::MultiEventStream.new
17
+
18
+ es.each do |time, record|
19
+ record = @rewrite_rule.rewrite(record)
20
+ new_es.add(time, record) if record
21
+ end
22
+
23
+ new_es
24
+ end
25
+ end
26
+ end
@@ -1,19 +1,22 @@
1
- module Fluent
1
+ require 'fluent/plugin/output'
2
+
3
+ module Fluent::Plugin
2
4
  class RewriteOutput < Output
3
5
  Fluent::Plugin.register_output('rewrite', self)
4
6
 
5
- # Define `router` method of v0.12 to support v0.10.57 or earlier
6
- unless method_defined?(:router)
7
- define_method("router") { Engine }
8
- end
7
+ helpers :event_emitter
9
8
 
10
- config_param :remove_prefix, :string, :default => nil
11
- config_param :add_prefix, :string, :default => nil
9
+ config_param :remove_prefix, :string, :default => nil,
10
+ deprecated: "use @label instead for event routing"
11
+ config_param :add_prefix, :string, :default => nil,
12
+ deprecated: "use @label instead for event routing"
12
13
  config_param :enable_warnings, :bool, :default => false
13
14
 
14
- attr_reader :rules
15
+ attr_reader :rewrite_rule
15
16
 
16
17
  def configure(conf)
18
+ require 'fluent/plugin/rewrite_rule'
19
+
17
20
  super
18
21
 
19
22
  if @remove_prefix
@@ -24,15 +27,7 @@ module Fluent
24
27
  @added_prefix_string = @add_prefix + '.'
25
28
  end
26
29
 
27
- @rules = conf.elements.select {|element| element.name == 'rule' }.map do |element|
28
- rule = {}
29
- element.keys.each do |key|
30
- # read and throw away to supress unread configuration warning
31
- rule[key] = element[key]
32
- end
33
- rule["regex"] = Regexp.new(element["pattern"]) if element.has_key?("pattern")
34
- rule
35
- end
30
+ @rewrite_rule = Fluent::RewriteRule.new(self, conf)
36
31
  end
37
32
 
38
33
  def start
@@ -43,7 +38,7 @@ module Fluent
43
38
  super
44
39
  end
45
40
 
46
- def emit(tag, es, chain)
41
+ def process(tag, es)
47
42
  _tag = tag.clone
48
43
 
49
44
  if @remove_prefix and
@@ -56,7 +51,7 @@ module Fluent
56
51
  end
57
52
 
58
53
  es.each do |time, record|
59
- filtered_tag, record = rewrite(tag, record)
54
+ filtered_tag, record = @rewrite_rule.rewrite(tag, record)
60
55
  if filtered_tag && record && _tag != filtered_tag
61
56
  router.emit(filtered_tag, time, record)
62
57
  else
@@ -65,58 +60,6 @@ module Fluent
65
60
  end
66
61
  end
67
62
  end
68
-
69
- chain.next
70
- end
71
-
72
- def rewrite(tag, record)
73
- rules.each do |rule|
74
- tag, record, last = apply_rule(rule, tag, record)
75
-
76
- break if last
77
- return if !tag && !record
78
- end
79
-
80
- [tag, record]
81
- end
82
-
83
- def apply_rule(rule, tag, record)
84
- tag_prefix = tag && tag.length > 0 ? "." : ""
85
- key = rule["key"]
86
- pattern = rule["pattern"]
87
- last = nil
88
-
89
- return [tag, record] if !key || !record.has_key?(key)
90
- return [tag, record] unless pattern
91
-
92
- if matched = record[key].match(rule["regex"])
93
- return if rule["ignore"]
94
-
95
- if rule["replace"]
96
- replace = rule["replace"]
97
- record[key] = record[key].gsub(rule["regex"], replace)
98
- end
99
-
100
- if rule["append_to_tag"]
101
- if rule["tag"]
102
- tag += (tag_prefix + rule["tag"])
103
- else
104
- matched.captures.each do |m|
105
- tag += (tag_prefix + "#{m}")
106
- end
107
- end
108
- end
109
-
110
- if rule["last"]
111
- last = true
112
- end
113
- else
114
- if rule["append_to_tag"] && rule["fallback"]
115
- tag += (tag_prefix + rule["fallback"])
116
- end
117
- end
118
-
119
- [tag, record, last]
120
63
  end
121
64
  end
122
65
  end
@@ -0,0 +1,73 @@
1
+ module Fluent
2
+ class RewriteRule
3
+ attr_reader :rules
4
+
5
+ def initialize(plugin, conf)
6
+ @plugin = plugin
7
+ @rules = conf.elements.select {|element| element.name == 'rule' }.map do |element|
8
+ rule = {}
9
+ element.keys.each do |key|
10
+ # read and throw away to supress unread configuration warning
11
+ rule[key] = element[key]
12
+ end
13
+ rule["regex"] = Regexp.new(element["pattern"]) if element.has_key?("pattern")
14
+ rule
15
+ end
16
+ end
17
+
18
+ def rewrite(tag=nil, record)
19
+ @rules.each do |rule|
20
+ tag, record, last = apply_rule(rule, tag, record)
21
+
22
+ break if last
23
+ if @plugin.is_a?(Fluent::Plugin::Output)
24
+ return if !tag && !record
25
+ else
26
+ return if !record
27
+ end
28
+ end
29
+
30
+ return [record] if not @plugin.is_a?(Fluent::Plugin::Output)
31
+ return [tag, record] if @plugin.is_a?(Fluent::Plugin::Output)
32
+ end
33
+
34
+ def apply_rule(rule, tag=nil, record)
35
+ tag_prefix = tag && tag.length > 0 ? "." : ""
36
+ key = rule["key"]
37
+ pattern = rule["pattern"]
38
+ last = nil
39
+
40
+ return [tag, record] if !key || !record.has_key?(key)
41
+ return [tag, record] unless pattern
42
+
43
+ if matched = record[key].match(rule["regex"])
44
+ return if rule["ignore"]
45
+
46
+ if rule["replace"]
47
+ replace = rule["replace"]
48
+ record[key] = record[key].gsub(rule["regex"], replace)
49
+ end
50
+
51
+ if rule["append_to_tag"] && @plugin.is_a?(Fluent::Plugin::Output)
52
+ if rule["tag"]
53
+ tag += (tag_prefix + rule["tag"])
54
+ else
55
+ matched.captures.each do |m|
56
+ tag += (tag_prefix + "#{m}")
57
+ end
58
+ end
59
+ end
60
+
61
+ if rule["last"]
62
+ last = true
63
+ end
64
+ else
65
+ if rule["append_to_tag"] && rule["fallback"] && @plugin.is_a?(Fluent::Plugin::Output)
66
+ tag += (tag_prefix + rule["fallback"])
67
+ end
68
+ end
69
+
70
+ return [tag, record, last]
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,213 @@
1
+ require 'test_helper'
2
+ require 'fluent/test/driver/filter'
3
+
4
+ class RewriteFilterTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ def create_driver(conf)
10
+ Fluent::Test::Driver::Filter.new(Fluent::Plugin::RewriteFilter).configure(conf)
11
+ end
12
+
13
+ def test_configure
14
+ d = create_driver(%[
15
+ <rule>
16
+ key foo
17
+ </rule>
18
+ <to_be_ignored>
19
+ key bar
20
+ </to_be_ignored>
21
+ <rule>
22
+ key baz
23
+ </rule>
24
+ ])
25
+
26
+ assert_equal 2, d.instance.rewrite_rule.rules.size
27
+ end
28
+
29
+ class TestRewrite < self
30
+ def test_replace
31
+ d = create_driver(%[
32
+ <rule>
33
+ key path
34
+ pattern \\?.+$
35
+ replace
36
+ </rule>
37
+ ])
38
+
39
+ assert_equal(
40
+ [ { "path" => "/foo" } ],
41
+ d.instance.rewrite_rule.rewrite({ "path" => "/foo?bar=1" })
42
+ )
43
+ end
44
+
45
+ def test_replace_with_capture
46
+ d = create_driver(%[
47
+ <rule>
48
+ key path
49
+ pattern (/[^/]+)\\?([^=]+)=(\\d)
50
+ replace \\1/\\2/\\3
51
+ </rule>
52
+ ])
53
+
54
+ assert_equal(
55
+ [ { "path" => "/foo/bar/1" } ],
56
+ d.instance.rewrite_rule.rewrite({ "path" => "/foo?bar=1" })
57
+ )
58
+ end
59
+ end
60
+
61
+ class TestRewriteIgnore < self
62
+ def test_pattern
63
+ d = create_driver(%[
64
+ <rule>
65
+ key status
66
+ pattern ^500$
67
+ ignore true
68
+ </rule>
69
+ ])
70
+
71
+ assert_equal(
72
+ nil,
73
+ d.instance.rewrite_rule.rewrite({ "status" => "500" })
74
+ )
75
+ end
76
+
77
+ def test_negate_pattern
78
+ d = create_driver(%[
79
+ <rule>
80
+ key status
81
+ pattern ^(?!200)\\d+$
82
+ ignore true
83
+ </rule>
84
+ ])
85
+
86
+ assert_equal(
87
+ [ { "status" => "200" } ],
88
+ d.instance.rewrite_rule.rewrite({ "status" => "200" })
89
+ )
90
+ %w[301 404 500].each do |status|
91
+ assert_equal(
92
+ nil,
93
+ d.instance.rewrite_rule.rewrite({ "status" => status })
94
+ )
95
+ end
96
+ end
97
+
98
+ def test_entire_ignore
99
+ d = create_driver(%[
100
+ <rule>
101
+ key flag
102
+ pattern ^$
103
+ ignore true
104
+ </rule>
105
+ ])
106
+
107
+ assert_equal(
108
+ nil,
109
+ d.instance.rewrite_rule.rewrite({ "flag" => "" })
110
+ )
111
+ end
112
+ end
113
+
114
+ def test_last
115
+ d = create_driver(%[
116
+ <rule>
117
+ key path
118
+ pattern ^/foo$
119
+ replace /bar
120
+ last true
121
+ </rule>
122
+ <rule>
123
+ key path
124
+ pattern ^/bar$
125
+ replace /baz
126
+ </rule>
127
+ ])
128
+
129
+ assert_equal(
130
+ [ { "path" => "/bar" } ],
131
+ d.instance.rewrite_rule.rewrite({ "path" => "/foo" })
132
+ )
133
+ assert_equal(
134
+ [ { "path" => "/baz" } ],
135
+ d.instance.rewrite_rule.rewrite({ "path" => "/bar" })
136
+ )
137
+ end
138
+
139
+ def test_rewrite_rules
140
+ d = create_driver(%[
141
+ <rule>
142
+ key path
143
+ pattern \\?.+$
144
+ replace
145
+ </rule>
146
+ <rule>
147
+ key status
148
+ pattern ^500$
149
+ ignore true
150
+ </rule>
151
+ ])
152
+
153
+ assert_equal(
154
+ [ { "path" => "/foo" } ],
155
+ d.instance.rewrite_rule.rewrite({ "path" => "/foo?bar=1" })
156
+ )
157
+ assert_equal(
158
+ [ { "path" => "/users/antipop" } ],
159
+ d.instance.rewrite_rule.rewrite({ "path" => "/users/antipop?hoge=1" })
160
+ )
161
+ assert_equal(
162
+ nil,
163
+ d.instance.rewrite_rule.rewrite({ "path" => "/foo?bar=1", "status" => "500" })
164
+ )
165
+ end
166
+
167
+ class TestFilter < self
168
+ def test_with_multiple_rules
169
+ d = create_driver(%[
170
+ <rule>
171
+ key path
172
+ pattern \\?.+$
173
+ replace
174
+ </rule>
175
+ <rule>
176
+ key status
177
+ pattern ^500$
178
+ ignore true
179
+ </rule>
180
+ ])
181
+
182
+ d.run(default_tag: 'test') do
183
+ d.feed({ "path" => "/foo?bar=1" })
184
+ d.feed({ "path" => "/foo?bar=1", "status" => "500" })
185
+ d.feed({ "path" => "/users/antipop" })
186
+ d.feed({ "path" => "/users/kentaro" })
187
+ end
188
+ filtered = d.filtered
189
+
190
+ assert_equal 3, filtered.size
191
+ assert_equal([{ "path" => "/foo" }], filtered[0][1])
192
+ assert_equal([{ "path" => "/users/antipop" }], filtered[1][1]) # nothing to do
193
+ assert_equal([{ "path" => "/users/kentaro" }], filtered[2][1]) # nothing to do
194
+ end
195
+
196
+ def test_remove_query_params
197
+ d = create_driver(%[
198
+ <rule>
199
+ key path
200
+ pattern \\?.+$
201
+ replace
202
+ </rule>
203
+ ])
204
+ d.run(default_tag: 'test') do
205
+ d.feed({ "path" => "/foo?bar=1" })
206
+ end
207
+ filtered = d.filtered
208
+
209
+ assert_equal 1, filtered.size
210
+ assert_equal([{ "path" => "/foo" }], filtered[0][1])
211
+ end
212
+ end
213
+ end
@@ -1,12 +1,13 @@
1
1
  require 'test_helper'
2
+ require 'fluent/test/driver/output'
2
3
 
3
4
  class RewriteOutputTest < Test::Unit::TestCase
4
5
  def setup
5
6
  Fluent::Test.setup
6
7
  end
7
8
 
8
- def create_driver(conf, tag = 'test')
9
- Fluent::Test::OutputTestDriver.new(Fluent::RewriteOutput, tag).configure(conf)
9
+ def create_driver(conf)
10
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::RewriteOutput).configure(conf)
10
11
  end
11
12
 
12
13
  def test_configure
@@ -27,7 +28,7 @@ class RewriteOutputTest < Test::Unit::TestCase
27
28
 
28
29
  assert_equal "test", d.instance.remove_prefix
29
30
  assert_equal "filtered", d.instance.add_prefix
30
- assert_equal 2, d.instance.rules.size
31
+ assert_equal 2, d.instance.rewrite_rule.rules.size
31
32
  end
32
33
 
33
34
  def test_rewrite_replace
@@ -41,7 +42,7 @@ class RewriteOutputTest < Test::Unit::TestCase
41
42
 
42
43
  assert_equal(
43
44
  [ "test", { "path" => "/foo" } ],
44
- d1.instance.rewrite("test", { "path" => "/foo?bar=1" })
45
+ d1.instance.rewrite_rule.rewrite("test", { "path" => "/foo?bar=1" })
45
46
  )
46
47
 
47
48
  d2 = create_driver(%[
@@ -54,7 +55,7 @@ class RewriteOutputTest < Test::Unit::TestCase
54
55
 
55
56
  assert_equal(
56
57
  [ "test", { "path" => "/foo/bar/1" } ],
57
- d2.instance.rewrite("test", { "path" => "/foo?bar=1" })
58
+ d2.instance.rewrite_rule.rewrite("test", { "path" => "/foo?bar=1" })
58
59
  )
59
60
  end
60
61
 
@@ -69,7 +70,7 @@ class RewriteOutputTest < Test::Unit::TestCase
69
70
 
70
71
  assert_equal(
71
72
  nil,
72
- d1.instance.rewrite("test", { "status" => "500" })
73
+ d1.instance.rewrite_rule.rewrite("test", { "status" => "500" })
73
74
  )
74
75
 
75
76
  d2 = create_driver(%[
@@ -82,12 +83,12 @@ class RewriteOutputTest < Test::Unit::TestCase
82
83
 
83
84
  assert_equal(
84
85
  [ "test", { "status" => "200" } ],
85
- d2.instance.rewrite("test", { "status" => "200" })
86
+ d2.instance.rewrite_rule.rewrite("test", { "status" => "200" })
86
87
  )
87
88
  %w[301 404 500].each do |status|
88
89
  assert_equal(
89
90
  nil,
90
- d2.instance.rewrite("test", { "status" => status })
91
+ d2.instance.rewrite_rule.rewrite("test", { "status" => status })
91
92
  )
92
93
  end
93
94
 
@@ -101,7 +102,7 @@ class RewriteOutputTest < Test::Unit::TestCase
101
102
 
102
103
  assert_equal(
103
104
  nil,
104
- d3.instance.rewrite("test", { "flag" => "" })
105
+ d3.instance.rewrite_rule.rewrite("test", { "flag" => "" })
105
106
  )
106
107
  end
107
108
 
@@ -116,11 +117,11 @@ class RewriteOutputTest < Test::Unit::TestCase
116
117
 
117
118
  assert_equal(
118
119
  [ "test.users", { "path" => "/users/antipop" } ],
119
- d1.instance.rewrite("test", { "path" => "/users/antipop" })
120
+ d1.instance.rewrite_rule.rewrite("test", { "path" => "/users/antipop" })
120
121
  )
121
122
  assert_equal(
122
123
  [ "test", { "path" => "/unmatched/path" } ],
123
- d1.instance.rewrite("test", { "path" => "/unmatched/path" })
124
+ d1.instance.rewrite_rule.rewrite("test", { "path" => "/unmatched/path" })
124
125
  )
125
126
 
126
127
  d2 = create_driver(%[
@@ -134,11 +135,11 @@ class RewriteOutputTest < Test::Unit::TestCase
134
135
 
135
136
  assert_equal(
136
137
  [ "test.users", { "path" => "/users/antipop" } ],
137
- d2.instance.rewrite("test", { "path" => "/users/antipop" })
138
+ d2.instance.rewrite_rule.rewrite("test", { "path" => "/users/antipop" })
138
139
  )
139
140
  assert_equal(
140
141
  [ "test.others", { "path" => "/unmatched/path" } ],
141
- d2.instance.rewrite("test", { "path" => "/unmatched/path" })
142
+ d2.instance.rewrite_rule.rewrite("test", { "path" => "/unmatched/path" })
142
143
  )
143
144
 
144
145
  d3 = create_driver(%[
@@ -152,11 +153,11 @@ class RewriteOutputTest < Test::Unit::TestCase
152
153
 
153
154
  assert_equal(
154
155
  [ "test.user", { "is_logged_in" => "1" } ],
155
- d3.instance.rewrite("test", { "is_logged_in" => "1" })
156
+ d3.instance.rewrite_rule.rewrite("test", { "is_logged_in" => "1" })
156
157
  )
157
158
  assert_equal(
158
159
  [ "test", { "is_logged_in" => "0" } ],
159
- d3.instance.rewrite("test", { "is_logged_in" => "0" })
160
+ d3.instance.rewrite_rule.rewrite("test", { "is_logged_in" => "0" })
160
161
  )
161
162
 
162
163
  d4 = create_driver(%[
@@ -169,7 +170,7 @@ class RewriteOutputTest < Test::Unit::TestCase
169
170
 
170
171
  assert_equal(
171
172
  [ "test.users", { "path" => "/users/antipop" } ],
172
- d4.instance.rewrite("test", { "path" => "/users/antipop" })
173
+ d4.instance.rewrite_rule.rewrite("test", { "path" => "/users/antipop" })
173
174
  )
174
175
 
175
176
  d5 = create_driver(%[
@@ -183,7 +184,7 @@ class RewriteOutputTest < Test::Unit::TestCase
183
184
 
184
185
  assert_equal(
185
186
  [ "test.user", { "is_logged_in" => "1" } ],
186
- d5.instance.rewrite("test", { "is_logged_in" => "1" })
187
+ d5.instance.rewrite_rule.rewrite("test", { "is_logged_in" => "1" })
187
188
  )
188
189
  end
189
190
 
@@ -204,11 +205,11 @@ class RewriteOutputTest < Test::Unit::TestCase
204
205
 
205
206
  assert_equal(
206
207
  [ "test", { "path" => "/bar" } ],
207
- d.instance.rewrite("test", { "path" => "/foo" })
208
+ d.instance.rewrite_rule.rewrite("test", { "path" => "/foo" })
208
209
  )
209
210
  assert_equal(
210
211
  [ "test", { "path" => "/baz" } ],
211
- d.instance.rewrite("test", { "path" => "/bar" })
212
+ d.instance.rewrite_rule.rewrite("test", { "path" => "/bar" })
212
213
  )
213
214
  end
214
215
 
@@ -234,15 +235,15 @@ class RewriteOutputTest < Test::Unit::TestCase
234
235
 
235
236
  assert_equal(
236
237
  [ "test.others", { "path" => "/foo" } ],
237
- d.instance.rewrite("test", { "path" => "/foo?bar=1" })
238
+ d.instance.rewrite_rule.rewrite("test", { "path" => "/foo?bar=1" })
238
239
  )
239
240
  assert_equal(
240
241
  [ "test.users", { "path" => "/users/antipop" } ],
241
- d.instance.rewrite("test", { "path" => "/users/antipop?hoge=1" })
242
+ d.instance.rewrite_rule.rewrite("test", { "path" => "/users/antipop?hoge=1" })
242
243
  )
243
244
  assert_equal(
244
245
  nil,
245
- d.instance.rewrite("test", { "path" => "/foo?bar=1", "status" => "500" })
246
+ d.instance.rewrite_rule.rewrite("test", { "path" => "/foo?bar=1", "status" => "500" })
246
247
  )
247
248
  end
248
249
 
@@ -269,24 +270,24 @@ class RewriteOutputTest < Test::Unit::TestCase
269
270
  </rule>
270
271
  ])
271
272
 
272
- d1.run do
273
- d1.emit({ "path" => "/foo?bar=1" })
274
- d1.emit({ "path" => "/foo?bar=1", "status" => "500" })
275
- d1.emit({ "path" => "/users/antipop" })
276
- d1.emit({ "path" => "/users/kentaro" })
277
- d1.emit({ "path" => "/entries/1" })
273
+ d1.run(default_tag: 'test') do
274
+ d1.feed({ "path" => "/foo?bar=1" })
275
+ d1.feed({ "path" => "/foo?bar=1", "status" => "500" })
276
+ d1.feed({ "path" => "/users/antipop" })
277
+ d1.feed({ "path" => "/users/kentaro" })
278
+ d1.feed({ "path" => "/entries/1" })
278
279
  end
279
- emits = d1.emits
280
-
281
- assert_equal 4, emits.size
282
- assert_equal('filtered.others', emits[0][0])
283
- assert_equal({ "path" => "/foo" }, emits[0][2])
284
- assert_equal('filtered.users', emits[1][0])
285
- assert_equal({ "path" => "/users/antipop" }, emits[1][2])
286
- assert_equal('filtered.users', emits[2][0])
287
- assert_equal({ "path" => "/users/kentaro" }, emits[2][2])
288
- assert_equal('filtered.entries', emits[3][0])
289
- assert_equal({ "path" => "/entries/1" }, emits[3][2])
280
+ events = d1.events
281
+
282
+ assert_equal 4, events.size
283
+ assert_equal('filtered.others', events[0][0])
284
+ assert_equal({ "path" => "/foo" }, events[0][2])
285
+ assert_equal('filtered.users', events[1][0])
286
+ assert_equal({ "path" => "/users/antipop" }, events[1][2])
287
+ assert_equal('filtered.users', events[2][0])
288
+ assert_equal({ "path" => "/users/kentaro" }, events[2][2])
289
+ assert_equal('filtered.entries', events[3][0])
290
+ assert_equal({ "path" => "/entries/1" }, events[3][2])
290
291
 
291
292
  d2 = create_driver(%[
292
293
  add_prefix filtered
@@ -297,14 +298,14 @@ class RewriteOutputTest < Test::Unit::TestCase
297
298
  replace
298
299
  </rule>
299
300
  ])
300
- d2.run do
301
- d2.emit({ "path" => "/foo?bar=1" })
301
+ d2.run(default_tag: 'test') do
302
+ d2.feed({ "path" => "/foo?bar=1" })
302
303
  end
303
- emits = d2.emits
304
+ events = d2.events
304
305
 
305
- assert_equal 1, emits.size
306
- assert_equal('filtered.test', emits[0][0])
307
- assert_equal({ "path" => "/foo" }, emits[0][2])
306
+ assert_equal 1, events.size
307
+ assert_equal('filtered.test', events[0][0])
308
+ assert_equal({ "path" => "/foo" }, events[0][2])
308
309
 
309
310
  # Test for not emit if the tag has not changed.
310
311
  d3 = create_driver(%[
@@ -314,11 +315,11 @@ class RewriteOutputTest < Test::Unit::TestCase
314
315
  replace
315
316
  </rule>
316
317
  ])
317
- d3.run do
318
- d3.emit({ "path" => "/foo?bar=1" })
318
+ d3.run(default_tag: 'test') do
319
+ d3.feed({ "path" => "/foo?bar=1" })
319
320
  end
320
321
 
321
- assert_equal 0, d3.emits.size
322
+ assert_equal 0, d3.events.size
322
323
 
323
324
  # Emit message if the rewrite tag rules have been defined, even if (add|remove)_prefix option is not set.
324
325
  d4 = create_driver(%[
@@ -328,13 +329,13 @@ class RewriteOutputTest < Test::Unit::TestCase
328
329
  append_to_tag true
329
330
  </rule>
330
331
  ])
331
- d4.run do
332
- d4.emit({ "path" => "/users/studio3104" })
332
+ d4.run(default_tag: 'test') do
333
+ d4.feed({ "path" => "/users/studio3104" })
333
334
  end
334
- emits = d4.emits
335
+ events = d4.events
335
336
 
336
- assert_equal 1, emits.size
337
- assert_equal('test.users', emits[0][0])
338
- assert_equal({ "path" => "/users/studio3104" }, emits[0][2])
337
+ assert_equal 1, events.size
338
+ assert_equal('test.users', events[0][0])
339
+ assert_equal({ "path" => "/users/studio3104" }, events[0][2])
339
340
  end
340
341
  end
@@ -27,6 +27,7 @@ unless ENV.has_key?('VERBOSE')
27
27
  end
28
28
 
29
29
  require 'fluent/plugin/out_rewrite'
30
+ require 'fluent/plugin/filter_rewrite'
30
31
 
31
32
  class Test::Unit::TestCase
32
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-rewrite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Kuribayashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-20 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -39,19 +39,39 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: fluentd
42
+ name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :runtime
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
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.8
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.8
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '2'
55
75
  description: Fluentd plugin to rewrite tags/values along with pattern matching and
56
76
  re-emit them.
57
77
  email:
@@ -61,12 +81,18 @@ extensions: []
61
81
  extra_rdoc_files: []
62
82
  files:
63
83
  - ".gitignore"
84
+ - ".travis.yml"
85
+ - Appraisals
64
86
  - Gemfile
65
87
  - LICENSE
66
88
  - README.md
67
89
  - Rakefile
68
90
  - fluent-plugin-rewrite.gemspec
91
+ - gemfiles/fluentd_0.14.gemfile
92
+ - lib/fluent/plugin/filter_rewrite.rb
69
93
  - lib/fluent/plugin/out_rewrite.rb
94
+ - lib/fluent/plugin/rewrite_rule.rb
95
+ - test/plugin/test_filter_rewrite.rb
70
96
  - test/plugin/test_out_rewrite.rb
71
97
  - test/test_helper.rb
72
98
  homepage: http://github.com/kentaro/fluent-plugin-rewrite
@@ -89,11 +115,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
115
  version: '0'
90
116
  requirements: []
91
117
  rubyforge_project:
92
- rubygems_version: 2.4.5
118
+ rubygems_version: 2.4.5.1
93
119
  signing_key:
94
120
  specification_version: 4
95
121
  summary: Fluentd plugin to rewrite tags/values along with pattern matching and re-emit
96
122
  them.
97
123
  test_files:
124
+ - test/plugin/test_filter_rewrite.rb
98
125
  - test/plugin/test_out_rewrite.rb
99
126
  - test/test_helper.rb