fluent-plugin-rewrite 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "fluent-plugin-rewrite"
3
- gem.version = '0.0.8'
3
+ gem.version = '0.0.9'
4
4
  gem.authors = ["Kentaro Kuribayashi"]
5
5
  gem.email = ["kentarok@gmail.com"]
6
6
  gem.homepage = "http://github.com/kentaro/fluent-plugin-rewrite"
@@ -41,6 +41,8 @@ module Fluent
41
41
  end
42
42
 
43
43
  def emit(tag, es, chain)
44
+ _tag = tag.clone
45
+
44
46
  if @remove_prefix and
45
47
  ((tag.start_with?(@removed_prefix_string) && tag.length > @removed_length) || tag == @remove_prefix)
46
48
  tag = tag[@removed_length..-1] || ''
@@ -52,7 +54,11 @@ module Fluent
52
54
 
53
55
  es.each do |time, record|
54
56
  filtered_tag, record = rewrite(tag, record)
55
- Engine.emit(filtered_tag, time, record) if filtered_tag && record
57
+ if filtered_tag && record && _tag != filtered_tag
58
+ Engine.emit(filtered_tag, time, record)
59
+ else
60
+ $log.warn "Can not emit message because the tag(#{tag}) has not changed. Dropped record #{record}"
61
+ end
56
62
  end
57
63
 
58
64
  chain.next
@@ -289,6 +289,8 @@ class RewriteOutputTest < Test::Unit::TestCase
289
289
  assert_equal({ "path" => "/entries/1" }, emits[3][2])
290
290
 
291
291
  d2 = create_driver(%[
292
+ add_prefix filtered
293
+
292
294
  <rule>
293
295
  key path
294
296
  pattern \\?.+$
@@ -301,7 +303,38 @@ class RewriteOutputTest < Test::Unit::TestCase
301
303
  emits = d2.emits
302
304
 
303
305
  assert_equal 1, emits.size
304
- assert_equal('test', emits[0][0])
306
+ assert_equal('filtered.test', emits[0][0])
305
307
  assert_equal({ "path" => "/foo" }, emits[0][2])
308
+
309
+ # Test for not emit if the tag has not changed.
310
+ d3 = create_driver(%[
311
+ <rule>
312
+ key path
313
+ pattern \\?.+$
314
+ replace
315
+ </rule>
316
+ ])
317
+ d3.run do
318
+ d3.emit({ "path" => "/foo?bar=1" })
319
+ end
320
+
321
+ assert_equal 0, d3.emits.size
322
+
323
+ # Emit message if the rewrite tag rules have been defined, even if (add|remove)_prefix option is not set.
324
+ d4 = create_driver(%[
325
+ <rule>
326
+ key path
327
+ pattern ^\/(users|entries)
328
+ append_to_tag true
329
+ </rule>
330
+ ])
331
+ d4.run do
332
+ d4.emit({ "path" => "/users/studio3104" })
333
+ end
334
+ emits = d4.emits
335
+
336
+ assert_equal 1, emits.size
337
+ assert_equal('test.users', emits[0][0])
338
+ assert_equal({ "path" => "/users/studio3104" }, emits[0][2])
306
339
  end
307
340
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-rewrite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-04 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -104,4 +104,3 @@ summary: Fluentd plugin to rewrite tags/values along with pattern matching and r
104
104
  test_files:
105
105
  - test/plugin/test_out_rewrite.rb
106
106
  - test/test_helper.rb
107
- has_rdoc: