fluent-plugin-forest 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0a7d7f3b087e4e98b95b64c59cba05d0e7414ae
4
- data.tar.gz: 0de19f3bffae6681c880ba68eed4189875c30ca7
3
+ metadata.gz: 068cf7b8d91c92de946e8654ff085d8f2774976e
4
+ data.tar.gz: eb6b060dcadae7ee75634e762bce1101242278a1
5
5
  SHA512:
6
- metadata.gz: d8058bf19db99b46c8af6c0f181fec8af939f6fb8785c99447c59aa87ae6abbc816f023c692ea2ccb2ab8fb215c3ce9cb89affd0bda9f35df9c595e36b9db9ef
7
- data.tar.gz: 6e49a2ad4a71002ef3eaa67db20782fda87d0271b9ef2fda4eccabb89b4d986004cba88879dd27e7e878657d7ab3256f8242fd5f35f0bc811d9f435672e93788
6
+ metadata.gz: 270e18f43d93d9c0ae18aa1ed852d2fdd85ad8b2b614a79f4ca43a75f240086aaa311f3fb5fbd1f1c60c869789cd896d1a477b937dc722505c7ee29653178ac5
7
+ data.tar.gz: 0bfea56fe80e620a2e955fba8604a179cb34b2436b3cb1be23dd886bccfc71405e986bc0101d1dd90b5128c7dcf2cca6d94d584650a6ae1539cf841fe6c9f170
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/README.md CHANGED
@@ -14,6 +14,8 @@ Other supported placeholders:
14
14
  * replaced with string specified by 'hostname' configuration value, or (default) result of 'hostname' command
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
+ * \_\_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 'apache' by ${tag_parts[1]} when the tag was `td.apache.access`.
17
19
 
18
20
  You SHOULD NOT use ForestOutput for tags increasing infinitly.
19
21
 
@@ -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.1"
4
+ gem.version = "0.2.2"
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,6 +32,12 @@ 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
+
35
41
  case element.name
36
42
  when 'template'
37
43
  @template = element
@@ -61,9 +67,18 @@ class Fluent::ForestOutput < Fluent::MultiOutput
61
67
  end
62
68
 
63
69
  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
75
  escaped_tag = tag.gsub('.', @escape_tag_separator)
65
76
  pairs = {}
66
77
  e.each do |k,v|
78
+ v = v.gsub(/(__TAG_PARTS\[[0-9]+\]__|\${tag_parts\[[0-9]+\]})/) do
79
+ $log.warn "out_forest: missing placeholder. tag:#{tag} placeholder:#{$1} conf:#{k} #{v}" unless tag_parts.include?($1)
80
+ tag_parts[$1]
81
+ end
67
82
  v = v.gsub('__ESCAPED_TAG__', escaped_tag).gsub('${escaped_tag}', escaped_tag)
68
83
  pairs[k] = v.gsub('__TAG__', tag).gsub('${tag}', tag).gsub('__HOSTNAME__', @hostname).gsub('${hostname}', @hostname)
69
84
  end
@@ -285,6 +285,46 @@ escape_tag_separator +
285
285
  assert_equal 'zzzzzz.xx+1+2', conf['keyz']
286
286
  end
287
287
 
288
+ def test_spec_split_tag_by_dot
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
+ }
297
+ d = create_driver %[
298
+ subtype hoge
299
+ <template>
300
+ keyx xxxxxx
301
+ keyy yyyyyy.${tag_parts[0]}
302
+ unknown_tag_parts bar${tag_parts[999]}__TAG_PARTS[999]__
303
+ </template>
304
+ <case xx.*>
305
+ keyz zzzzzz.${tag_parts[0]}.${tag_parts[1]}
306
+ alt_key a
307
+ </case>
308
+ <case xx.**>
309
+ keyz zzzzzz.__TAG_PARTS[0]__.__TAG_PARTS[2]__
310
+ alt_key b
311
+ </case>
312
+ ]
313
+
314
+ conf = d.instance.spec('xx.1')
315
+ assert_equal 'xxxxxx', conf['keyx']
316
+ assert_equal 'yyyyyy.xx', conf['keyy']
317
+ assert_equal 'zzzzzz.xx.1', conf['keyz']
318
+ assert_equal 'bar', conf['unknown_tag_parts']
319
+ assert_equal 'a', conf['alt_key']
320
+
321
+ conf = d.instance.spec('xx.1.2')
322
+ assert_equal 'xxxxxx', conf['keyx']
323
+ assert_equal 'yyyyyy.xx', conf['keyy']
324
+ assert_equal 'zzzzzz.xx.2', conf['keyz']
325
+ assert_equal 'b', conf['alt_key']
326
+ end
327
+
288
328
  def test_spec_hostname
289
329
  d = create_driver %[
290
330
  subtype hoge
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.1
4
+ version: 0.2.2
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-09-03 00:00:00.000000000 Z
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -47,6 +47,7 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - .gitignore
50
+ - .travis.yml
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.md