fluent-plugin-rewrite-tag-filter 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/README.md +38 -12
- data/fluent-plugin-rewrite-tag-filter.gemspec +1 -2
- data/lib/fluent/plugin/out_rewrite_tag_filter.rb +8 -2
- data/test/plugin/test_out_rewrite_tag_filter.rb +39 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4e1ce31eba327c311153c8eb2e96b8aef667bca6b92f9695c7b5a3fb11e7d58
|
4
|
+
data.tar.gz: fc5e7682a7476dffcfdef523f06401508dcb888d3b4cff39edab742950bf9506
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '018336a8cf161d92674c7845fc021f4b01a11ce0762ff555067707345671b7d7b40d63f84ce308493beb36ce90ed581c90788905bdb0c14dc62125349ebcdc31'
|
7
|
+
data.tar.gz: ecbd7f9591d477aba1fa776a58648e04ac085f442ec685aefbd0dc7d48160c3ca2cd819fc79bc3a59910aa8c5663d595c0339f8e7ab14f32b2d7f542667add00
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
## Overview
|
4
4
|
|
5
5
|
Rewrite Tag Filter for [Fluentd](http://fluentd.org). It is designed to rewrite tags like mod_rewrite.
|
6
|
-
Re-emit the record with
|
6
|
+
Re-emit the record with rewritten tag when a value matches/unmatches with a regular expression.
|
7
7
|
Also you can change a tag from Apache log by domain, status code (ex. 500 error),
|
8
8
|
user-agent, request-uri, regex-backreference and so on with regular expression.
|
9
9
|
|
@@ -31,7 +31,7 @@ $ sudo td-agent-gem install fluent-plugin-rewrite-tag-filter -v 1.6.0
|
|
31
31
|
$ sudo td-agent-gem install fluent-plugin-rewrite-tag-filter
|
32
32
|
```
|
33
33
|
|
34
|
-
For more details, see [Plugin Management](https://docs.fluentd.org/
|
34
|
+
For more details, see [Plugin Management](https://docs.fluentd.org/deployment/plugin-management)
|
35
35
|
|
36
36
|
## Configuration
|
37
37
|
|
@@ -200,7 +200,7 @@ When original tag is `kubernetes.var.log`, this will be converted to `default.ku
|
|
200
200
|
|
201
201
|
### Tag placeholder
|
202
202
|
|
203
|
-
It is supported these placeholder for new_tag (
|
203
|
+
It is supported these placeholder for new_tag (rewritten tag).
|
204
204
|
|
205
205
|
- `${tag}`
|
206
206
|
- `__TAG__`
|
@@ -214,12 +214,16 @@ For example with `td.apache.access` tag, it will get `td` by `${tag_parts[0]}` a
|
|
214
214
|
|
215
215
|
**Note** Currently, range expression ```${tag_parts[0..2]}``` is not supported.
|
216
216
|
|
217
|
-
#### Placeholder
|
217
|
+
#### Placeholder Options
|
218
218
|
|
219
219
|
* `remove_tag_prefix`
|
220
220
|
|
221
221
|
This option adds removing tag prefix for `${tag}` or `__TAG__` in placeholder.
|
222
222
|
|
223
|
+
* `remove_tag_regexp`
|
224
|
+
|
225
|
+
This option adds removing tag regexp for `${tag}` or `__TAG__` in placeholder.
|
226
|
+
|
223
227
|
* `hostname_command`
|
224
228
|
|
225
229
|
By default, execute command as `hostname` to get full hostname.
|
@@ -231,45 +235,67 @@ It comes short hostname with `hostname_command hostname -s` configuration specif
|
|
231
235
|
It's a sample to rewrite a tag with placeholder.
|
232
236
|
|
233
237
|
```
|
234
|
-
# It will get "
|
238
|
+
# It will get "rewritten.access.ExampleMail"
|
235
239
|
<match apache.access>
|
236
240
|
@type rewrite_tag_filter
|
237
241
|
remove_tag_prefix apache
|
238
242
|
<rule>
|
239
243
|
key domain
|
240
244
|
pattern ^(mail)\.(example)\.com$
|
241
|
-
tag
|
245
|
+
tag rewritten.${tag}.$2$1
|
246
|
+
</rule>
|
247
|
+
</match>
|
248
|
+
|
249
|
+
# It will get "rewritten.access.ExampleMail"
|
250
|
+
<match apache.access>
|
251
|
+
@type rewrite_tag_filter
|
252
|
+
remove_tag_regexp /^apache\./
|
253
|
+
<rule>
|
254
|
+
key domain
|
255
|
+
pattern ^(mail)\.(example)\.com$
|
256
|
+
tag rewritten.${tag}.$2$1
|
257
|
+
</rule>
|
258
|
+
</match>
|
259
|
+
|
260
|
+
# It will get "http.access.log"
|
261
|
+
<match input.{apache,nginx}.access.log>
|
262
|
+
@type rewrite_tag_filter
|
263
|
+
remove_tag_regexp /^input\.(apache|nginx)\./
|
264
|
+
<rule>
|
265
|
+
key domain
|
266
|
+
pattern ^.+$
|
267
|
+
tag http.${tag}
|
242
268
|
</rule>
|
243
269
|
</match>
|
244
270
|
|
245
|
-
# It will get "
|
271
|
+
# It will get "rewritten.ExampleMail.app30-124.foo.com" when hostname is "app30-124.foo.com"
|
246
272
|
<match apache.access>
|
247
273
|
@type rewrite_tag_filter
|
248
274
|
<rule>
|
249
275
|
key domain
|
250
276
|
pattern ^(mail)\.(example)\.com$
|
251
|
-
tag
|
277
|
+
tag rewritten.$2$1.${hostname}
|
252
278
|
</rule>
|
253
279
|
</match>
|
254
280
|
|
255
|
-
# It will get "
|
281
|
+
# It will get "rewritten.ExampleMail.app30-124" when hostname is "app30-124.foo.com"
|
256
282
|
<match apache.access>
|
257
283
|
@type rewrite_tag_filter
|
258
284
|
hostname_command hostname -s
|
259
285
|
<rule>
|
260
286
|
key domain
|
261
287
|
pattern ^(mail)\.(example)\.com$
|
262
|
-
tag
|
288
|
+
tag rewritten.$2$1.${hostname}
|
263
289
|
</rule>
|
264
290
|
</match>
|
265
291
|
|
266
|
-
# It will get "
|
292
|
+
# It will get "rewritten.game.pool"
|
267
293
|
<match app.game.pool.activity>
|
268
294
|
@type rewrite_tag_filter
|
269
295
|
<rule>
|
270
296
|
key domain
|
271
297
|
pattern ^.+$
|
272
|
-
tag
|
298
|
+
tag rewritten.${tag_parts[1]}.${tag_parts[2]}
|
273
299
|
</rule>
|
274
300
|
</match>
|
275
301
|
```
|
@@ -1,9 +1,8 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
|
4
3
|
Gem::Specification.new do |s|
|
5
4
|
s.name = "fluent-plugin-rewrite-tag-filter"
|
6
|
-
s.version = "2.
|
5
|
+
s.version = "2.3.0"
|
7
6
|
s.license = "Apache-2.0"
|
8
7
|
s.authors = ["Kentaro Yoshida"]
|
9
8
|
s.email = ["y.ken.studio@gmail.com"]
|
@@ -10,6 +10,8 @@ class Fluent::Plugin::RewriteTagFilterOutput < Fluent::Plugin::Output
|
|
10
10
|
config_param :capitalize_regex_backreference, :bool, :default => false
|
11
11
|
desc 'Remove tag prefix for tag placeholder.'
|
12
12
|
config_param :remove_tag_prefix, :string, :default => nil
|
13
|
+
desc "Remove tag regexp for tag placeholder."
|
14
|
+
config_param :remove_tag_regexp, :regexp, default: nil
|
13
15
|
desc 'Override hostname command for placeholder.'
|
14
16
|
config_param :hostname_command, :string, :default => 'hostname'
|
15
17
|
desc "The emit mode. If `batch`, this plugin will emit events per rewritten tag."
|
@@ -58,8 +60,12 @@ class Fluent::Plugin::RewriteTagFilterOutput < Fluent::Plugin::Output
|
|
58
60
|
raise Fluent::ConfigError, "duplicated rewriterules found #{@rewriterules.inspect}"
|
59
61
|
end
|
60
62
|
|
63
|
+
if @remove_tag_prefix && @remove_tag_regexp
|
64
|
+
raise Fluent::ConfigError, "remove_tag_prefix and remove_tag_regexp are exclusive"
|
65
|
+
end
|
66
|
+
|
61
67
|
unless @remove_tag_prefix.nil?
|
62
|
-
@
|
68
|
+
@remove_tag_regexp = /^#{Regexp.escape(@remove_tag_prefix)}\.?/
|
63
69
|
end
|
64
70
|
|
65
71
|
@batch_mode = @emit_mode == :batch
|
@@ -135,7 +141,7 @@ class Fluent::Plugin::RewriteTagFilterOutput < Fluent::Plugin::Output
|
|
135
141
|
end
|
136
142
|
|
137
143
|
def get_placeholder(tag)
|
138
|
-
tag = tag.sub(@
|
144
|
+
tag = tag.sub(@remove_tag_regexp, '') if @remove_tag_regexp
|
139
145
|
|
140
146
|
result = {
|
141
147
|
'__HOSTNAME__' => @hostname,
|
@@ -41,6 +41,21 @@ class RewriteTagFilterOutputTest < Test::Unit::TestCase
|
|
41
41
|
d = create_driver(conf)
|
42
42
|
assert_equal(/.+/, d.instance.rules.first.pattern)
|
43
43
|
end
|
44
|
+
|
45
|
+
test "remove_tag_prefix and remove_tag_regexp are exclusive" do
|
46
|
+
conf = %[
|
47
|
+
remove_tag_prefix prefix
|
48
|
+
remove_tag_regexp /^prefix\./
|
49
|
+
<rule>
|
50
|
+
key message
|
51
|
+
pattern .+
|
52
|
+
tag ${tag}
|
53
|
+
</rule>
|
54
|
+
]
|
55
|
+
assert_raise(Fluent::ConfigError) do
|
56
|
+
create_driver(conf)
|
57
|
+
end
|
58
|
+
end
|
44
59
|
end
|
45
60
|
|
46
61
|
sub_test_case "section style" do
|
@@ -127,6 +142,30 @@ class RewriteTagFilterOutputTest < Test::Unit::TestCase
|
|
127
142
|
assert_equal 'access', events[0][0] # tag
|
128
143
|
end
|
129
144
|
|
145
|
+
sub_test_case "remove_tag_regexp" do
|
146
|
+
test "plain" do
|
147
|
+
config = %[
|
148
|
+
remove_tag_regexp /^input\.(apache|nginx)\./
|
149
|
+
<rule>
|
150
|
+
key domain
|
151
|
+
pattern ^www\.google\.com$
|
152
|
+
tag rewritten.${tag}
|
153
|
+
</rule>
|
154
|
+
]
|
155
|
+
d = create_driver(config)
|
156
|
+
d.run do
|
157
|
+
d.feed('input.apache.access', event_time, {'domain' => 'www.google.com', 'path' => '/foo/bar?key=value', 'agent' => 'Googlebot', 'response_time' => 1000000})
|
158
|
+
d.feed('input.nginx.access', event_time, {'domain' => 'www.google.com', 'path' => '/foo/bar?key=value', 'agent' => 'Googlebot', 'response_time' => 1000000})
|
159
|
+
d.feed('input.tomcat.access', event_time, {'domain' => 'www.google.com', 'path' => '/foo/bar?key=value', 'agent' => 'Googlebot', 'response_time' => 1000000})
|
160
|
+
end
|
161
|
+
events = d.events
|
162
|
+
assert_equal 3, events.length
|
163
|
+
assert_equal 'rewritten.access', events[0][0]
|
164
|
+
assert_equal 'rewritten.access', events[1][0]
|
165
|
+
assert_equal 'rewritten.input.tomcat.access', events[2][0]
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
130
169
|
test "short hostname" do
|
131
170
|
config = %[
|
132
171
|
remove_tag_prefix input
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-rewrite-tag-filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kentaro Yoshida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.1.2
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Fluentd Output filter plugin. It has designed to rewrite tag like mod_rewrite.
|