不具合修正版 fluent-plugin-rewrite-tag-filter v1.3.1 をリリースしました #fluentd
ログ収集ツールFluentdに、Apacheのmod_rewriteのようにtagを自在に書き換える機能を追加する、fluent-plugin-rewrite-tag-filterのv1.3.1をリリースしました。
- https://github.com/y-ken/fluent-plugin-rewrite-tag-filter
- http://rubygems.org/gems/fluent-plugin-rewrite-tag-filter
今回は不具合修正のみです。
変更内容概要
修正履歴より紹介します。
特に前者の不具合は影響が大きいため、詳細な説明を行います。
「後方参照・タグプレースホルダが正常に動作しない現象」の詳細
後方参照またはタグプレースホルダを利用した場合に、以下の不具合が発生します。 是非アップデートをお願いします。
不具合例 その1
agent.ie.${tag}
を元にそれぞれ別のタグに書き換わる挙動が意図通りです。
しかし最初にagent.ie.${tag}
を通った時にagent.ie.ap01
に展開されてしまうため、rewriterule1 agent MSIE
に該当するパターンは以後全てagent.ie.ap01
というタグに書き換えられる現象が発生します。
# 設定例 <match apache.access.*> type rewrite_tag_filter rewriterule1 agent MSIE agent.ie.${tag} remove_tag_prefix apache.access </match>
v1.1.0〜v1.3.0での挙動
apache.access.ap01
→agent.ie.ap01
apache.access.ap02
→agent.ie.ap01
※ap02ではなくap01となっている
本来の意図
apache.access.ap01
→agent.ie.ap01
apache.access.ap02
→agent.ie.ap02
不具合例 その2
site.$1
を元にそれぞれ別のタグに書き換わる挙動が意図通りです。
# 設定例 <match apache.access.*> type rewrite_tag_filter rewriterule1 domain ([a-z])\.com site.$1 </match>
v1.1.0〜v1.3.0での挙動
- domainが
foo.com
→site.foo
- domainが
bar.com
→site.foo
※barではなくfooとなっている
- domainが
本来の意図
- domainが
foo.com
→site.foo
- domainが
bar.com
→site.bar
- domainが
謝辞
タグプレースホルダの不具合は、
Tad@JP
Tad@JP (@tad_jp)さんによる報告です。
ありがとうございます。
反省点
破壊的メソッドの使い方を誤ったことによる不具合でした。 以下に該当のソースを抜粋します。
@rewriterules.each do |rewritekey, regexp, match_operator, rewritetag| ...snip... `rewritetag.gsub!(/(\${[a-z]+}|__[A-Z]+__)/, placeholder)` ...snip...
configureで作成した変数@rewriterules
の中身、rewritetag
をgsub!
で書き換えていました。
あとがき
修正した際にテストを追加できなかったことが心苦しいです。
Fluentdで、 <match foo.*> 的なワイルドカードを用いた複数タグを受け入れるときのユニットテストの実装方法が分からない。create_driverした後に、emitする際の引数に渡したら動くようにしたい。
— Y.Kentaro (@yoshi_ken) 2013, 7月 19
Fluentdのユニットテストで、<match apache.*>
といった入力の
テスト実装方法があれば、どなたか助言頂けると嬉しいです。