fluent-plugin-rewrite-tag-filter 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +6 -0
- data/README.md +43 -11
- data/fluent-plugin-rewrite-tag-filter.gemspec +2 -1
- data/lib/fluent/plugin/out_rewrite_tag_filter.rb +18 -2
- data/test/plugin/test_out_rewrite_tag_filter.rb +39 -0
- metadata +5 -3
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# fluent-plugin-rewrite-tag-filter
|
1
|
+
# fluent-plugin-rewrite-tag-filter [![Build Status](https://travis-ci.org/fluent/fluent-plugin-rewrite-tag-filter.png?branch=master)](https://travis-ci.org/fluent/fluent-plugin-rewrite-tag-filter)
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
|
@@ -11,12 +11,14 @@ user-agent, request-uri, regex-backreference and so on with regular expression.
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
+
install with gem or fluent-gem command as:
|
15
|
+
|
14
16
|
```
|
15
|
-
#
|
16
|
-
gem install fluent-plugin-rewrite-tag-filter
|
17
|
+
# for fluentd
|
18
|
+
$ gem install fluent-plugin-rewrite-tag-filter
|
17
19
|
|
18
|
-
# td-agent
|
19
|
-
/usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-rewrite-tag-filter
|
20
|
+
# for td-agent
|
21
|
+
$ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-rewrite-tag-filter
|
20
22
|
```
|
21
23
|
|
22
24
|
## Configuration
|
@@ -26,7 +28,8 @@ gem install fluent-plugin-rewrite-tag-filter
|
|
26
28
|
```
|
27
29
|
rewriterule<num> <attribute> <regex_pattern> <new_tag>
|
28
30
|
|
29
|
-
# Optional: Capitalize every matched regex backreference. (ex:
|
31
|
+
# Optional: Capitalize letter for every matched regex backreference. (ex: maps -> Maps)
|
32
|
+
# for more details, see usage.
|
30
33
|
capitalize_regex_backreference <yes/no> (default no)
|
31
34
|
|
32
35
|
# Optional: remove tag prefix for tag placeholder. (see the section of "Tag placeholder")
|
@@ -50,6 +53,7 @@ It's a sample to exclude some static file log before split tag by domain.
|
|
50
53
|
pos_file /var/log/td-agent/apache_access.pos
|
51
54
|
</source>
|
52
55
|
|
56
|
+
# "capitalize_regex_backreference yes" affects converting every matched first letter of backreference to upper case. ex: maps -> Maps
|
53
57
|
# At rewriterule2, redirect to tag named "clear" which unmatched for status code 200.
|
54
58
|
# At rewriterule3, redirect to tag named "clear" which is not end with ".com"
|
55
59
|
# At rewriterule6, "site.$2$1" to be "site.ExampleMail" by capitalize_regex_backreference option.
|
@@ -110,19 +114,30 @@ $ tailf /var/log/td-agent/td-agent.log
|
|
110
114
|
|
111
115
|
### Tag placeholder
|
112
116
|
|
113
|
-
It is
|
117
|
+
It is supported these placeholder for new_tag (rewrited tag).
|
114
118
|
|
115
119
|
- `${tag}`
|
116
120
|
- `__TAG__`
|
121
|
+
- `{$tag_parts[n]}`
|
122
|
+
- `__TAG_PARTS[n]__`
|
123
|
+
- `${hostname}`
|
124
|
+
- `__HOSTNAME__`
|
125
|
+
|
126
|
+
The placeholder of `{$tag_parts[n]}` and `__TAG_PARTS[n]__` acts accessing the index which split the tag with "." (dot).
|
127
|
+
For example with `td.apache.access` tag, it will get `td` by `${tag_parts[0]}` and `apache` by `${tag_parts[1]}`.
|
128
|
+
|
129
|
+
**Note** Currently, range expression ```${tag_parts[0..2]}``` is not supported.
|
130
|
+
|
131
|
+
#### Placeholder Option
|
132
|
+
|
133
|
+
* `remove_tag_prefix`
|
117
134
|
|
118
|
-
It's available to use this placeholder with `remove_tag_prefix` option.
|
119
135
|
This option adds removing tag prefix for `${tag}` or `__TAG__` in placeholder.
|
120
136
|
|
121
|
-
|
122
|
-
- `__HOSTNAME__`
|
137
|
+
* `hostname_command`
|
123
138
|
|
124
139
|
By default, execute command as `hostname` to get full hostname.
|
125
|
-
|
140
|
+
On your needs, it could override hostname command using `hostname_command` option.
|
126
141
|
It comes short hostname with `hostname_command hostname -s` configuration specified.
|
127
142
|
|
128
143
|
#### Placeholder Usage
|
@@ -149,6 +164,12 @@ It's a sample to rewrite a tag with placeholder.
|
|
149
164
|
rewriterule1 domain ^(mail)\.(example)\.com$ rewrited.$2$1.${hostname}
|
150
165
|
hostname_command hostname -s
|
151
166
|
</match>
|
167
|
+
|
168
|
+
# It will get "rewrited.game.pool"
|
169
|
+
<match app.game.pool.activity>
|
170
|
+
type rewrite_tag_filter
|
171
|
+
rewriterule1 domain ^.+$ rewrited.${tag_parts[1]}.${tag_parts[2]}
|
172
|
+
</match>
|
152
173
|
```
|
153
174
|
|
154
175
|
## Example
|
@@ -185,6 +206,17 @@ http://y-ken.hatenablog.com/entry/fluent-plugin-rewrite-tag-filter-v1.2.1
|
|
185
206
|
- 待望の正規表現の否定パターンに対応した fluent-plugin-rewrite-tag-filter v1.3.0 をリリースしました #fluentd
|
186
207
|
http://y-ken.hatenablog.com/entry/fluent-plugin-rewrite-tag-filter-v1.3.0
|
187
208
|
|
209
|
+
- 不具合修正版 fluent-plugin-rewrite-tag-filter v1.3.1 をリリースしました #fluentd
|
210
|
+
http://y-ken.hatenablog.com/entry/fluent-plugin-rewrite-tag-filter-v1.3.1
|
211
|
+
|
212
|
+
- PostgreSQLのログをfluentdで回収する設定 — still deeper
|
213
|
+
http://chopl.in/blog/2013/06/07/postgresql_csv_log_with_fluentd.html
|
214
|
+
|
215
|
+
- S3とFluentdを用いた効率的なログ管理 | SmartNews開発者ブログ
|
216
|
+
http://developer.smartnews.be/blog/2013/09/02/an-effective-log-management-technique-which-uses-fluentd-and-s3/
|
217
|
+
|
218
|
+
- fluentd(td-agent) の導入 : Raccoon Tech Blog [株式会社ラクーン 技術戦略部ブログ]
|
219
|
+
http://techblog.raccoon.ne.jp/archives/35031163.html
|
188
220
|
|
189
221
|
## TODO
|
190
222
|
|
@@ -3,7 +3,8 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-rewrite-tag-filter"
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.4.0"
|
7
|
+
s.license = "Apache 2.0"
|
7
8
|
s.authors = ["Kentaro Yoshida"]
|
8
9
|
s.email = ["y.ken.studio@gmail.com"]
|
9
10
|
s.homepage = "https://github.com/y-ken/fluent-plugin-rewrite-tag-filter"
|
@@ -19,6 +19,11 @@ class Fluent::RewriteTagFilterOutput < Fluent::Output
|
|
19
19
|
if regexp.nil? || rewritetag.nil?
|
20
20
|
raise Fluent::ConfigError, "failed to parse rewriterules at #{key} #{conf[key]}"
|
21
21
|
end
|
22
|
+
|
23
|
+
unless rewritetag.match(/\$\{tag_parts\[\d\.\.\.?\d\]\}/).nil? or rewritetag.match(/__TAG_PARTS\[\d\.\.\.?\d\]__/).nil?
|
24
|
+
raise Fluent::ConfigError, "${tag_parts[n]} and __TAG_PARTS[n]__ placeholder does not support range specify at #{key} #{conf[key]}"
|
25
|
+
end
|
26
|
+
|
22
27
|
@rewriterules.push([rewritekey, /#{trim_regex_quote(regexp)}/, get_match_operator(regexp), rewritetag])
|
23
28
|
rewriterule_names.push(rewritekey + regexp)
|
24
29
|
$log.info "adding rewrite_tag_filter rule: #{key} #{@rewriterules.last}"
|
@@ -61,7 +66,10 @@ class Fluent::RewriteTagFilterOutput < Fluent::Output
|
|
61
66
|
backreference_table = get_backreference_table($~.captures)
|
62
67
|
rewritetag = rewritetag.gsub(/\$\d+/, backreference_table)
|
63
68
|
end
|
64
|
-
rewritetag = rewritetag.gsub(/(\${[a-
|
69
|
+
rewritetag = rewritetag.gsub(/(\${[a-z_]+(\[[0-9]+\])?}|__[A-Z_]+__)/) do
|
70
|
+
$log.warn "rewrite_tag_filter: unknown placeholder found. :placeholder=>#{$1} :tag=>#{tag} :rewritetag=>#{rewritetag}" unless placeholder.include?($1)
|
71
|
+
placeholder[$1]
|
72
|
+
end
|
65
73
|
return rewritetag
|
66
74
|
end
|
67
75
|
return nil
|
@@ -99,12 +107,20 @@ class Fluent::RewriteTagFilterOutput < Fluent::Output
|
|
99
107
|
|
100
108
|
def get_placeholder(tag)
|
101
109
|
tag = tag.sub(@remove_tag_prefix, '') if @remove_tag_prefix
|
102
|
-
|
110
|
+
|
111
|
+
result = {
|
103
112
|
'__HOSTNAME__' => @hostname,
|
104
113
|
'${hostname}' => @hostname,
|
105
114
|
'__TAG__' => tag,
|
106
115
|
'${tag}' => tag,
|
107
116
|
}
|
117
|
+
|
118
|
+
tag.split('.').each_with_index do |t, idx|
|
119
|
+
result.store("${tag_parts[#{idx}]}", t)
|
120
|
+
result.store("__TAG_PARTS[#{idx}]__", t)
|
121
|
+
end
|
122
|
+
|
123
|
+
return result
|
108
124
|
end
|
109
125
|
end
|
110
126
|
|
@@ -55,6 +55,14 @@ class RewriteTagFilterOutputTest < Test::Unit::TestCase
|
|
55
55
|
rewriterule20 domain ^news\.google\.com$ site.GoogleNews
|
56
56
|
]
|
57
57
|
|
58
|
+
# split by tag
|
59
|
+
CONFIG_SPLIT_BY_TAG = %[
|
60
|
+
rewriterule1 user_name ^Lynn Minmay$ vip.${tag_parts[1]}.remember_love
|
61
|
+
rewriterule2 user_name ^Harlock$ ${tag_parts[2]}.${tag_parts[0]}.${tag_parts[1]}
|
62
|
+
rewriterule3 world ^(alice|chaos)$ application.${tag_parts[0]}.$1_server
|
63
|
+
rewriterule4 world ^[a-z]+$ application.${tag_parts[1]}.future_server
|
64
|
+
]
|
65
|
+
|
58
66
|
def create_driver(conf=CONFIG,tag='test')
|
59
67
|
Fluent::Test::OutputTestDriver.new(Fluent::RewriteTagFilterOutput, tag).configure(conf)
|
60
68
|
end
|
@@ -69,6 +77,12 @@ class RewriteTagFilterOutputTest < Test::Unit::TestCase
|
|
69
77
|
assert_raise(Fluent::ConfigError) {
|
70
78
|
d = create_driver('rewriterule1 foo foo')
|
71
79
|
}
|
80
|
+
assert_raise(Fluent::ConfigError) {
|
81
|
+
d = create_driver('rewriterule1 hoge hoge.${tag_parts[0..2]}.__TAG_PARTS[0..2]__')
|
82
|
+
}
|
83
|
+
assert_raise(Fluent::ConfigError) {
|
84
|
+
d = create_driver('rewriterule1 fuga fuga.${tag_parts[1...2]}.__TAG_PARTS[1...2]__')
|
85
|
+
}
|
72
86
|
d = create_driver %[
|
73
87
|
rewriterule1 domain ^www.google.com$ site.Google
|
74
88
|
rewriterule2 domain ^news.google.com$ site.GoogleNews
|
@@ -188,5 +202,30 @@ class RewriteTagFilterOutputTest < Test::Unit::TestCase
|
|
188
202
|
assert_equal 'site.GoogleNews', emits[1][0] # tag
|
189
203
|
end
|
190
204
|
|
205
|
+
def test_emit8_split_by_tag
|
206
|
+
d1 = create_driver(CONFIG_SPLIT_BY_TAG, 'game.production.api')
|
207
|
+
d1.run do
|
208
|
+
d1.emit({'user_id' => '10000', 'world' => 'chaos', 'user_name' => 'gamagoori'})
|
209
|
+
d1.emit({'user_id' => '10001', 'world' => 'chaos', 'user_name' => 'sanageyama'})
|
210
|
+
d1.emit({'user_id' => '10002', 'world' => 'nehan', 'user_name' => 'inumuta'})
|
211
|
+
d1.emit({'user_id' => '77777', 'world' => 'space', 'user_name' => 'Lynn Minmay'})
|
212
|
+
d1.emit({'user_id' => '99999', 'world' => 'space', 'user_name' => 'Harlock'})
|
213
|
+
end
|
214
|
+
emits = d1.emits
|
215
|
+
p emits
|
216
|
+
assert_equal 5, emits.length
|
217
|
+
p emits[0]
|
218
|
+
assert_equal 'application.game.chaos_server', emits[0][0]
|
219
|
+
p emits[1]
|
220
|
+
assert_equal 'application.game.chaos_server', emits[1][0]
|
221
|
+
p emits[2]
|
222
|
+
assert_equal 'application.production.future_server', emits[2][0]
|
223
|
+
p emits[3]
|
224
|
+
assert_equal 'vip.production.remember_love', emits[3][0]
|
225
|
+
p emits[4]
|
226
|
+
assert_equal 'api.game.production', emits[4][0]
|
227
|
+
end
|
228
|
+
|
229
|
+
|
191
230
|
end
|
192
231
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-rewrite-tag-filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
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: 2013-
|
12
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -51,6 +51,7 @@ extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
53
|
- .gitignore
|
54
|
+
- .travis.yml
|
54
55
|
- Gemfile
|
55
56
|
- LICENSE.txt
|
56
57
|
- README.md
|
@@ -62,7 +63,8 @@ files:
|
|
62
63
|
- test/helper.rb
|
63
64
|
- test/plugin/test_out_rewrite_tag_filter.rb
|
64
65
|
homepage: https://github.com/y-ken/fluent-plugin-rewrite-tag-filter
|
65
|
-
licenses:
|
66
|
+
licenses:
|
67
|
+
- Apache 2.0
|
66
68
|
post_install_message:
|
67
69
|
rdoc_options: []
|
68
70
|
require_paths:
|