fluent-plugin-forest 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/fluent-plugin-forest.gemspec +1 -1
- data/lib/fluent/plugin/out_forest.rb +21 -14
- data/test/plugin/test_out_forest.rb +55 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea721095d308823baadbc9e6296c076c75d1011f
|
4
|
+
data.tar.gz: d5d3ae86ae4638783e7f8286373c1b47906068b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0ce28f5b60185e4758367ef918990cf18537e8a5b5bcaa308b7d554efd4ff810c0bda0825262fd11510abdbaced8c39ff85566b8cc51d21df88b849db759d65
|
7
|
+
data.tar.gz: 061c8287095c952c4fc94be45bc24e755f86dc067c1130fc34b1ab1a4830bb7d4cf9bdab1a6ee48522c6b18ca498495c53bad71f8df0227619a0e1f4a28181f5
|
data/README.md
CHANGED
@@ -15,7 +15,8 @@ Other supported placeholders:
|
|
15
15
|
* \_\_ESCAPED\_TAG\_\_ (or ${escaped\_tag})
|
16
16
|
* replaced with escaped tag. Escaped tag is replaced '.' with a character specified by 'escape\_tag\_separator' (default: '\_')
|
17
17
|
* \_\_TAG_PARTS[n]\_\_ (or ${tag_parts[n]})
|
18
|
-
* it acts accessing the index which split the tag with '.' (dot). It will get 'td' by ${tag_parts[0]} and '
|
18
|
+
* it acts accessing the index which split the tag with '.' (dot). It will get 'td' by ${tag_parts[0]}, 'apache' by ${tag_parts[1]} and 'access' by ${tag_parts[-1]} when the tag was `td.apache.access`.
|
19
|
+
* you can also use range index like '1..4' or '1...3' (e.g. ${tag_parts[1..-1]} will return 'apache.access' on giving tag same as previous.)
|
19
20
|
|
20
21
|
You SHOULD NOT use ForestOutput for tags increasing infinitly.
|
21
22
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "fluent-plugin-forest"
|
4
|
-
gem.version = "0.2.
|
4
|
+
gem.version = "0.2.3"
|
5
5
|
gem.authors = ["TAGOMORI Satoshi"]
|
6
6
|
gem.email = ["tagomoris@gmail.com"]
|
7
7
|
gem.description = %q{create sub-plugin dynamically per tags, with template configuration and parameters}
|
@@ -32,12 +32,6 @@ class Fluent::ForestOutput < Fluent::MultiOutput
|
|
32
32
|
# read and throw away to supress unread configuration warning
|
33
33
|
touch_recursive(element)
|
34
34
|
|
35
|
-
element.each do |k,v|
|
36
|
-
unless v.match(/\$\{tag_parts\[\d\.\.\.?\d\]\}/).nil? or v.match(/__TAG_PARTS\[\d\.\.\.?\d\]__/).nil?
|
37
|
-
raise Fluent::ConfigError, "${tag_parts[n]} and __TAG_PARTS[n]__ placeholder does not support range specify at #{k} #{v}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
35
|
case element.name
|
42
36
|
when 'template'
|
43
37
|
@template = element
|
@@ -67,17 +61,30 @@ class Fluent::ForestOutput < Fluent::MultiOutput
|
|
67
61
|
end
|
68
62
|
|
69
63
|
def parameter(tag, e, name = 'instance', arg = '')
|
70
|
-
tag_parts =
|
71
|
-
tag.split('.').each_with_index do |t, idx|
|
72
|
-
tag_parts["${tag_parts[#{idx}]}"] = t
|
73
|
-
tag_parts["__TAG_PARTS[#{idx}]__"] = t
|
74
|
-
end
|
64
|
+
tag_parts = tag.split('.')
|
75
65
|
escaped_tag = tag.gsub('.', @escape_tag_separator)
|
76
66
|
pairs = {}
|
77
67
|
e.each do |k,v|
|
78
|
-
v = v.gsub(/
|
79
|
-
|
80
|
-
|
68
|
+
v = v.gsub(/__TAG_PARTS\[-?[0-9]+(?:\.\.\.?-?[0-9]+)?\]__|\$\{tag_parts\[-?[0-9]+(?:\.\.\.?-?[0-9]+)?\]\}/) do |tag_parts_matched|
|
69
|
+
matched = /\[(?<first>-?[0-9]+)(?<range_part>(?<range_type>\.\.\.?)(?<last>-?[0-9]+))?\]/.match(tag_parts_matched)
|
70
|
+
if matched && matched[:range_part]
|
71
|
+
exclude_end = (matched[:range_type] == '...')
|
72
|
+
range = Range.new(matched[:first].to_i, matched[:last].to_i, exclude_end)
|
73
|
+
if tag_parts[range]
|
74
|
+
tag_parts[range].join(".")
|
75
|
+
else
|
76
|
+
$log.warn "out_forest: missing placeholder. tag:#{tag} placeholder:#{tag_parts_matched} conf:#{k} #{v}"
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
elsif matched # non range index (without range_part)
|
80
|
+
index = matched[:first].to_i
|
81
|
+
unless tag_parts[index]
|
82
|
+
$log.warn "out_forest: missing placeholder. tag:#{tag} placeholder:#{tag_parts_matched} conf:#{k} #{v}"
|
83
|
+
end
|
84
|
+
tag_parts[index]
|
85
|
+
else
|
86
|
+
raise "BUG: gsub regex matches but index regex does not match"
|
87
|
+
end
|
81
88
|
end
|
82
89
|
v = v.gsub('__ESCAPED_TAG__', escaped_tag).gsub('${escaped_tag}', escaped_tag)
|
83
90
|
pairs[k] = v.gsub('__TAG__', tag).gsub('${tag}', tag).gsub('__HOSTNAME__', @hostname).gsub('${hostname}', @hostname)
|
@@ -285,43 +285,79 @@ escape_tag_separator +
|
|
285
285
|
assert_equal 'zzzzzz.xx+1+2', conf['keyz']
|
286
286
|
end
|
287
287
|
|
288
|
-
def
|
289
|
-
assert_raise(Fluent::ConfigError) {
|
290
|
-
d = create_driver %[
|
291
|
-
subtype hoge
|
292
|
-
<template>
|
293
|
-
keyx ${tag_parts[0..2]}.__TAG_PARTS[0..2]__
|
294
|
-
</template>
|
295
|
-
]
|
296
|
-
}
|
288
|
+
def test_spec_split_tag_by_dot_with_int_index
|
297
289
|
d = create_driver %[
|
298
290
|
subtype hoge
|
299
291
|
<template>
|
300
|
-
|
301
|
-
|
292
|
+
keya aaaaaa
|
293
|
+
keyb bbbbbb.${tag_parts[0]}
|
302
294
|
unknown_tag_parts bar${tag_parts[999]}__TAG_PARTS[999]__
|
303
295
|
</template>
|
304
296
|
<case xx.*>
|
305
|
-
|
297
|
+
keyc cccccc.${tag_parts[0]}.${tag_parts[1]}
|
298
|
+
keyd dddddd.${tag_parts[-2]}.${tag_parts[-1]}
|
306
299
|
alt_key a
|
307
300
|
</case>
|
308
301
|
<case xx.**>
|
309
|
-
|
302
|
+
keyc cccccc.__TAG_PARTS[0]__.__TAG_PARTS[2]__
|
303
|
+
keyd dddddd.__TAG_PARTS[-2]__.__TAG_PARTS[-1]__
|
310
304
|
alt_key b
|
311
305
|
</case>
|
312
306
|
]
|
313
307
|
|
314
308
|
conf = d.instance.spec('xx.1')
|
315
|
-
assert_equal '
|
316
|
-
assert_equal '
|
317
|
-
assert_equal '
|
309
|
+
assert_equal 'aaaaaa', conf['keya']
|
310
|
+
assert_equal 'bbbbbb.xx', conf['keyb']
|
311
|
+
assert_equal 'cccccc.xx.1', conf['keyc']
|
312
|
+
assert_equal 'dddddd.xx.1', conf['keyd']
|
318
313
|
assert_equal 'bar', conf['unknown_tag_parts']
|
319
314
|
assert_equal 'a', conf['alt_key']
|
320
315
|
|
321
316
|
conf = d.instance.spec('xx.1.2')
|
322
|
-
assert_equal '
|
323
|
-
assert_equal '
|
324
|
-
assert_equal '
|
317
|
+
assert_equal 'aaaaaa', conf['keya']
|
318
|
+
assert_equal 'bbbbbb.xx', conf['keyb']
|
319
|
+
assert_equal 'cccccc.xx.2', conf['keyc']
|
320
|
+
assert_equal 'dddddd.1.2', conf['keyd']
|
321
|
+
assert_equal 'b', conf['alt_key']
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_spec_split_tag_by_dot_with_range_index
|
325
|
+
d = create_driver %[
|
326
|
+
subtype hoge
|
327
|
+
<template>
|
328
|
+
keya aaaaaa
|
329
|
+
keyb bbbbbb.${tag_parts[0]}
|
330
|
+
unknown_tag_parts bar${tag_parts[999..1000]}__TAG_PARTS[999...1001]__
|
331
|
+
</template>
|
332
|
+
<case xx.*>
|
333
|
+
keyc cccccc.${tag_parts[0..1]}
|
334
|
+
keyd dddddd.${tag_parts[-2..-1]}
|
335
|
+
keye eeeeee.${tag_parts[1..1000]}
|
336
|
+
alt_key a
|
337
|
+
</case>
|
338
|
+
<case xx.**>
|
339
|
+
keyc cccccc.__TAG_PARTS[1...3]__
|
340
|
+
keyd dddddd.__TAG_PARTS[-3...-1]__
|
341
|
+
keye eeeeee.__TAG_PARTS[1...1000]__
|
342
|
+
alt_key b
|
343
|
+
</case>
|
344
|
+
]
|
345
|
+
|
346
|
+
conf = d.instance.spec('xx.1')
|
347
|
+
assert_equal 'aaaaaa', conf['keya']
|
348
|
+
assert_equal 'bbbbbb.xx', conf['keyb']
|
349
|
+
assert_equal 'cccccc.xx.1', conf['keyc']
|
350
|
+
assert_equal 'dddddd.xx.1', conf['keyd']
|
351
|
+
assert_equal 'eeeeee.1', conf['keye']
|
352
|
+
assert_equal 'bar', conf['unknown_tag_parts']
|
353
|
+
assert_equal 'a', conf['alt_key']
|
354
|
+
|
355
|
+
conf = d.instance.spec('xx.1.2')
|
356
|
+
assert_equal 'aaaaaa', conf['keya']
|
357
|
+
assert_equal 'bbbbbb.xx', conf['keyb']
|
358
|
+
assert_equal 'cccccc.1.2', conf['keyc']
|
359
|
+
assert_equal 'dddddd.xx.1', conf['keyd']
|
360
|
+
assert_equal 'eeeeee.1.2', conf['keye']
|
325
361
|
assert_equal 'b', conf['alt_key']
|
326
362
|
end
|
327
363
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-forest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAGOMORI Satoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|