Skip to content

Instantly share code, notes, and snippets.

@y-ken
Last active December 14, 2015 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-ken/5091010 to your computer and use it in GitHub Desktop.
Save y-ken/5091010 to your computer and use it in GitHub Desktop.
I'd like to support mixin for my Fluentd Plugins. But It won't work. Would you please tell me the way to work fine? (FluentdプラグインのMixin対応を行おうとしているが、期待した動作にならない訳は何故でしょうか。)
### Test Run Command(テスト実行したコマンド)
curl http://localhost:8888/test -F 'json={"message":"foo"}'
### actual logging output(実際のログ出力)
2013-03-06 00:14:53 +0900 debug.mixin: {"message":"foo"}
### expected logging output(期待したログ出力)
2013-03-06 00:14:53 +0900 debug.mixin: {"message":"foo","my_tag":"test","my_time":"2013-03-05T15:14:53Z"}
<source>
type http
port 8888
</source>
<match test>
type rewrite_tag_filter
rewriterule1 message .+ debug.mixin
include_time_key true
time_key my_time
include_tag_key true
tag_key my_tag
</match>
diff --git a/lib/fluent/plugin/out_rewrite_tag_filter.rb b/lib/fluent/plugin/out_rewrite_tag_filter.rb
index eec8e4f..890ceba 100644
--- a/lib/fluent/plugin/out_rewrite_tag_filter.rb
+++ b/lib/fluent/plugin/out_rewrite_tag_filter.rb
@@ -1,6 +1,14 @@
class Fluent::RewriteTagFilterOutput < Fluent::Output
Fluent::Plugin.register_output('rewrite_tag_filter', self)
+ include Fluent::HandleTagNameMixin
+
+ include Fluent::SetTagKeyMixin
+ config_set_default :include_tag_key, true
+
+ include Fluent::SetTimeKeyMixin
+ config_set_default :include_time_key, true
+
PATTERN_MAX_NUM = 200
config_param :rewriterule1, :string # string: NAME REGEXP
@y-ken
Copy link
Author

y-ken commented Mar 5, 2013

After I added filter_record() before emit call, it works fine. Thank you.

@@ -53,7 +61,9 @@ class Fluent::RewriteTagFilterOutput < Fluent::Output
         tag = rewritetag.gsub(/\$\d+/, backreference_table)
         break
       end
-      Fluent::Engine.emit(tag, time, record) if (rewrite)
+      next unless rewrite
+      filter_record(tag, time, record)
+      Fluent::Engine.emit(tag, time, record)
     end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment