fluent-plugin-flatten 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,13 +14,14 @@ When you have a config as below:
14
14
  <match test.**>
15
15
  type flatten
16
16
  key foo
17
+ add_tag_prefix flattened.
17
18
  </match>
18
19
  ```
19
20
 
20
21
  And you feed such a value into fluentd:
21
22
 
22
23
  ```
23
- {
24
+ "test" => {
24
25
  "foo" => '{"bar" : {"qux" : "quux", "hoe" : "poe" }, "baz" : "bazz" }',
25
26
  "hoge" => "fuga"
26
27
  }
@@ -29,7 +30,7 @@ And you feed such a value into fluentd:
29
30
  Then you'll get:
30
31
 
31
32
  ```
32
- {
33
+ "flattened.test" => {
33
34
  "foo" => '{"bar" : {"qux" : "quux", "hoe" : "poe" }, "baz" : "bazz" }',
34
35
  "hoge" => "fuga",
35
36
 
@@ -48,6 +49,12 @@ That is, JSON-formatted string in the value of the key `foo` is flattened and no
48
49
  The `key` is used to point a key whose value contains JSON-formatted
49
50
  string.
50
51
 
52
+ ### remove_tag_prefix, remove_tag_suffix, add_tag_prefix, add_tag_suffix
53
+
54
+ These params are included from `Fluent::HandleTagNameMixin`. See that code for details.
55
+
56
+ You must add at least one of these params.
57
+
51
58
  ## Installation
52
59
 
53
60
  Add this line to your application's Gemfile:
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'fluent-plugin-flatten'
3
- gem.version = '0.0.1'
3
+ gem.version = '0.0.2'
4
4
  gem.authors = ['Kentaro Kuribayashi']
5
5
  gem.email = ['kentarok@gmail.com']
6
6
  gem.homepage = 'http://github.com/kentaro/fluent-plugin-flatten'
@@ -2,14 +2,30 @@ require 'json'
2
2
 
3
3
  module Fluent
4
4
  class FlattenOutput < Output
5
+ include Fluent::HandleTagNameMixin
5
6
  class Error < StandardError; end
6
-
7
7
  Fluent::Plugin.register_output('flatten', self)
8
+
8
9
  config_param :key, :string
9
10
 
11
+ def configure(conf)
12
+ super
13
+
14
+ if !self.remove_tag_prefix && !self.remove_tag_suffix && !self.add_tag_prefix && !self.add_tag_suffix
15
+ raise ConfigError, "out_flatten: Set remove_tag_prefix, remove_tag_suffix, add_tag_prefix or add_tag_suffix."
16
+ end
17
+ end
18
+
10
19
  def emit(tag, es, chain)
11
20
  es.each do |time, record|
12
- Engine.emit(tag, time, flatten(record))
21
+ _tag = tag.clone
22
+ flattened = flatten(record)
23
+ filter_record(_tag, time, flattened)
24
+ if tag != _tag
25
+ Engine.emit(_tag, time, flattened)
26
+ else
27
+ $log.warn "Drop record #{record} tag '#{tag}' was not replaced. Can't emit record, cause infinity looping. Set remove_tag_prefix, remove_tag_suffix, add_tag_prefix or add_tag_suffix correctly."
28
+ end
13
29
  end
14
30
 
15
31
  chain.next
@@ -5,22 +5,23 @@ class FlattenOutputTest < Test::Unit::TestCase
5
5
  Fluent::Test.setup
6
6
  end
7
7
 
8
- def create_driver(conf, tag = 'test')
8
+ CONFIG = %[
9
+ key foo
10
+ add_tag_prefix flattened.
11
+ ]
12
+
13
+ def create_driver(conf = CONFIG, tag = 'test')
9
14
  Fluent::Test::OutputTestDriver.new(Fluent::FlattenOutput, tag).configure(conf)
10
15
  end
11
16
 
12
17
  def test_configure
13
- d = create_driver(%[
14
- key foo
15
- ])
16
-
18
+ d = create_driver
17
19
  assert_equal 'foo', d.instance.key
20
+ assert_equal 'flattened.', d.instance.add_tag_prefix
18
21
  end
19
22
 
20
23
  def test_emit
21
- d = create_driver(%[
22
- key foo
23
- ])
24
+ d = create_driver
24
25
 
25
26
  d.run do
26
27
  d.emit( 'foo' => '{"bar" : "baz"}', 'hoge' => 'fuga' )
@@ -35,5 +36,8 @@ class FlattenOutputTest < Test::Unit::TestCase
35
36
  assert_equal 'quux', emits[1][2]['foo.bar.qux']
36
37
  assert_equal 'poe', emits[1][2]['foo.bar.hoe']
37
38
  assert_equal 'bazz', emits[1][2]['foo.baz']
39
+
40
+ assert_equal 'flattened.test', emits[0][0]
41
+ assert_equal 'flattened.test', emits[1][0]
38
42
  end
39
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-flatten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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: 2012-11-27 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake