Permalink
Browse files

Fixed a bug that go into an infinite loop when the tag has not changed.

  • Loading branch information...
1 parent 49bf052 commit db722f3956933fa928bb9bbae8f775228c2eb817 Satoshi SUZUKI committed Jan 15, 2013
Showing with 41 additions and 2 deletions.
  1. +7 −1 lib/fluent/plugin/out_rewrite.rb
  2. +34 −1 test/plugin/test_out_rewrite.rb
@@ -41,6 +41,8 @@ def shutdown
end
def emit(tag, es, chain)
+ _tag = tag.clone
+
if @remove_prefix and
((tag.start_with?(@removed_prefix_string) && tag.length > @removed_length) || tag == @remove_prefix)
tag = tag[@removed_length..-1] || ''
@@ -52,7 +54,11 @@ def emit(tag, es, chain)
es.each do |time, record|
filtered_tag, record = rewrite(tag, record)
- Engine.emit(filtered_tag, time, record) if filtered_tag && record
+ if filtered_tag && record && _tag != filtered_tag
+ Engine.emit(filtered_tag, time, record)
+ else
+ $log.warn "Can not emit message because the tag(#{tag}) has not changed. Dropped record #{record}"
+ end
end
chain.next
@@ -289,6 +289,8 @@ def test_emit
assert_equal({ "path" => "/entries/1" }, emits[3][2])
d2 = create_driver(%[
+ add_prefix filtered
+
<rule>
key path
pattern \\?.+$
@@ -301,7 +303,38 @@ def test_emit
emits = d2.emits
assert_equal 1, emits.size
- assert_equal('test', emits[0][0])
+ assert_equal('filtered.test', emits[0][0])
assert_equal({ "path" => "/foo" }, emits[0][2])
+
+ # Test for not emit if the tag has not changed.
+ d3 = create_driver(%[
+ <rule>
+ key path
+ pattern \\?.+$
+ replace
+ </rule>
+ ])
+ d3.run do
+ d3.emit({ "path" => "/foo?bar=1" })
+ end
+
+ assert_equal 0, d3.emits.size
+
+ # Emit message if the rewrite tag rules have been defined, even if (add|remove)_prefix option is not set.
+ d4 = create_driver(%[
+ <rule>
+ key path
+ pattern ^\/(users|entries)
+ append_to_tag true
+ </rule>
+ ])
+ d4.run do
+ d4.emit({ "path" => "/users/studio3104" })
+ end
+ emits = d4.emits
+
+ assert_equal 1, emits.size
+ assert_equal('test.users', emits[0][0])
+ assert_equal({ "path" => "/users/studio3104" }, emits[0][2])
end
end

0 comments on commit db722f3

Please sign in to comment.