fluent-plugin-flatten-hash 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +25 -6
- data/fluent-plugin-flatten-hash.gemspec +2 -2
- data/lib/fluent/plugin/filter_flatten_hash.rb +18 -0
- data/lib/fluent/plugin/out_flatten_hash.rb +3 -17
- data/lib/fluent/plugin/util.rb +19 -0
- data/test/helper.rb +0 -14
- data/test/plugin/test_filter_flatten_hash.rb +57 -0
- data/test/plugin/test_out_flatten_hash.rb +1 -0
- metadata +22 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f772de761e1745118e528735b2eef31caec0f1d8
|
4
|
+
data.tar.gz: e40c3922daafb54256c362264813ad8f648311e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed1d12c01bdfbc22def38e47151899baf359fb82edb0269d99b2c7c55dbaee805f3b23512fb152c4d69aeb6f75804c0f99effc89de94088d4049edc9bbd833b3
|
7
|
+
data.tar.gz: 223aebc69f80a14abe9ac4cd5e1e05f2f0e06e3f2de3726cded8c987bda8f0e76f18f68cb2b828576b40fa1344ca99e1afbb5db4cc446c702ec0ed64ae52c51f
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# fluent-plugin-flatten-hash
|
1
|
+
# fluent-plugin-flatten-hash, a plugin for [Fluentd](http://fluentd.org)
|
2
2
|
|
3
3
|
A fluentd plugin to flatten nested hash structure as a flat record with unique keys generated by its path for each values.
|
4
4
|
|
@@ -18,6 +18,10 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Configuration
|
20
20
|
|
21
|
+
fluent-plugin-flatten-hash supports both Output and Filter plugin.
|
22
|
+
|
23
|
+
### Output
|
24
|
+
|
21
25
|
You can set a configuration like below:
|
22
26
|
|
23
27
|
```
|
@@ -41,7 +45,7 @@ In this configuration, if you get a following nested/complex message:
|
|
41
45
|
}
|
42
46
|
}
|
43
47
|
}
|
44
|
-
}
|
48
|
+
},
|
45
49
|
"days":[
|
46
50
|
"2013/08/24",
|
47
51
|
"2013/08/25"
|
@@ -54,12 +58,27 @@ The message is flattened like below:
|
|
54
58
|
```js
|
55
59
|
{
|
56
60
|
"message_today":"good day",
|
57
|
-
"message_tommorow_is_a_bad":"day"
|
58
|
-
"days_0"
|
59
|
-
"days_1"
|
61
|
+
"message_tommorow_is_a_bad":"day",
|
62
|
+
"days_0":"2013/08/24",
|
63
|
+
"days_1":"2013/08/25"
|
60
64
|
}
|
61
65
|
```
|
62
66
|
|
67
|
+
### Filter
|
68
|
+
|
69
|
+
You can set a configuration like below:
|
70
|
+
|
71
|
+
```
|
72
|
+
<filter message>
|
73
|
+
type flatten_hash
|
74
|
+
separator _
|
75
|
+
</filter>
|
76
|
+
|
77
|
+
<match message>
|
78
|
+
type stdout
|
79
|
+
</match>
|
80
|
+
```
|
81
|
+
|
63
82
|
## Contributing
|
64
83
|
|
65
84
|
1. Fork it
|
@@ -84,4 +103,4 @@ The message is flattened like below:
|
|
84
103
|
<tr>
|
85
104
|
<td>License</td><td>MIT License</td>
|
86
105
|
</tr>
|
87
|
-
</table>
|
106
|
+
</table>
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-flatten-hash"
|
7
|
-
spec.version = "0.0
|
7
|
+
spec.version = "0.1.0"
|
8
8
|
spec.authors = ["Masahiro Sano"]
|
9
9
|
spec.email = ["sabottenda@gmail.com"]
|
10
10
|
spec.description = %q{A fluentd plugin to flatten nested hash structure as a flat record}
|
@@ -17,6 +17,6 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "fluentd", "
|
20
|
+
spec.add_dependency "fluentd", ["> 0.10.0", "< 0.14.0"]
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fluent
|
2
|
+
class FlattenHashFilter < Filter
|
3
|
+
Plugin.register_filter('flatten_hash', self)
|
4
|
+
|
5
|
+
require_relative 'util'
|
6
|
+
include FlattenHashUtil
|
7
|
+
|
8
|
+
config_param :separator, :string, :default => '.'
|
9
|
+
|
10
|
+
def configure(conf)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def filter(tag, time, record)
|
15
|
+
flatten_record(record, [])
|
16
|
+
end
|
17
|
+
end if defined?(Filter)
|
18
|
+
end
|
@@ -3,6 +3,9 @@ module Fluent
|
|
3
3
|
include Fluent::HandleTagNameMixin
|
4
4
|
Fluent::Plugin.register_output('flatten_hash', self)
|
5
5
|
|
6
|
+
require_relative 'util'
|
7
|
+
include FlattenHashUtil
|
8
|
+
|
6
9
|
config_param :tag, :string, :default => nil
|
7
10
|
config_param :separator, :string, :default => '.'
|
8
11
|
|
@@ -31,22 +34,5 @@ module Fluent
|
|
31
34
|
end
|
32
35
|
chain.next
|
33
36
|
end
|
34
|
-
|
35
|
-
private
|
36
|
-
def flatten_record(record, prefix)
|
37
|
-
ret = {}
|
38
|
-
if record.is_a? Hash
|
39
|
-
record.each { |key, value|
|
40
|
-
ret.merge! flatten_record(value, prefix + [key.to_s])
|
41
|
-
}
|
42
|
-
elsif record.is_a? Array
|
43
|
-
record.each_with_index { |elem, index|
|
44
|
-
ret.merge! flatten_record(elem, prefix + [index.to_s])
|
45
|
-
}
|
46
|
-
else
|
47
|
-
return {prefix.join(@separator) => record}
|
48
|
-
end
|
49
|
-
ret
|
50
|
-
end
|
51
37
|
end
|
52
38
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fluent
|
2
|
+
module FlattenHashUtil
|
3
|
+
def flatten_record(record, prefix)
|
4
|
+
ret = {}
|
5
|
+
if record.is_a? Hash
|
6
|
+
record.each { |key, value|
|
7
|
+
ret.merge! flatten_record(value, prefix + [key.to_s])
|
8
|
+
}
|
9
|
+
elsif record.is_a? Array
|
10
|
+
record.each_with_index { |elem, index|
|
11
|
+
ret.merge! flatten_record(elem, prefix + [index.to_s])
|
12
|
+
}
|
13
|
+
else
|
14
|
+
return {prefix.join(@separator) => record}
|
15
|
+
end
|
16
|
+
ret
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/test/helper.rb
CHANGED
@@ -12,17 +12,3 @@ require 'test/unit'
|
|
12
12
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
14
|
require 'fluent/test'
|
15
|
-
unless ENV.has_key?('VERBOSE')
|
16
|
-
nulllogger = Object.new
|
17
|
-
nulllogger.instance_eval {|obj|
|
18
|
-
def method_missing(method, *args)
|
19
|
-
# pass
|
20
|
-
end
|
21
|
-
}
|
22
|
-
$log = nulllogger
|
23
|
-
end
|
24
|
-
|
25
|
-
require 'fluent/plugin/out_flatten_hash'
|
26
|
-
|
27
|
-
class Test::Unit::TestCase
|
28
|
-
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fluent/plugin/filter_flatten_hash'
|
3
|
+
|
4
|
+
class FlattenHashFilterTest < Test::Unit::TestCase
|
5
|
+
include Fluent
|
6
|
+
|
7
|
+
BASE_CONFIG = %[
|
8
|
+
type flatten_hash
|
9
|
+
]
|
10
|
+
CONFIG = BASE_CONFIG + %[
|
11
|
+
add_tag_prefix flattened
|
12
|
+
]
|
13
|
+
|
14
|
+
def setup
|
15
|
+
Fluent::Test.setup
|
16
|
+
@time = Fluent::Engine.now
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_driver(conf = '')
|
20
|
+
Test::FilterTestDriver.new(FlattenHashFilter).configure(conf, true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_flatten_record
|
24
|
+
d = create_driver
|
25
|
+
es = Fluent::MultiEventStream.new
|
26
|
+
now = Fluent::Engine.now
|
27
|
+
|
28
|
+
d.run do
|
29
|
+
d.emit({'message' => {'foo' => 'bar'}})
|
30
|
+
d.emit({"message" => {'foo' => 'bar', 'hoge' => 'fuga'}})
|
31
|
+
d.emit({"message" => {'nest' => {'foo' => 'bar'}}})
|
32
|
+
d.emit({"message" => {'nest' => {'nest' => {'foo' => 'bar'}}}})
|
33
|
+
d.emit({"message" => {'array' => ['foo', 'bar']}})
|
34
|
+
d.emit({"message" => {'array' => [{'foo' => 'bar'}, {'hoge' => 'fuga'}]}})
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal [
|
38
|
+
{"message.foo" => "bar"},
|
39
|
+
{"message.foo" => "bar", "message.hoge" => "fuga"},
|
40
|
+
{"message.nest.foo" => "bar"},
|
41
|
+
{"message.nest.nest.foo" => "bar"},
|
42
|
+
{"message.array.0" => "foo", "message.array.1" => "bar"},
|
43
|
+
{"message.array.0.foo" => "bar", "message.array.1.hoge" => "fuga"},
|
44
|
+
], d.filtered_as_array.map{|x| x[2]}
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_separator
|
48
|
+
d = create_driver CONFIG + %[separator /]
|
49
|
+
|
50
|
+
d.run do
|
51
|
+
d.emit({"message" => {'nest' => {'foo' => 'bar'}}})
|
52
|
+
end
|
53
|
+
assert_equal [
|
54
|
+
{"message/nest/foo" => "bar"},
|
55
|
+
], d.filtered_as_array.map{|x| x[2]}
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,46 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-flatten-hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Masahiro Sano
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-12-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: fluentd
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.10.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.14.0
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.10.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.14.0
|
30
33
|
- !ruby/object:Gem::Dependency
|
31
34
|
name: rake
|
32
35
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
36
|
requirements:
|
35
|
-
- -
|
37
|
+
- - ">="
|
36
38
|
- !ruby/object:Gem::Version
|
37
39
|
version: '0'
|
38
40
|
type: :development
|
39
41
|
prerelease: false
|
40
42
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
43
|
requirements:
|
43
|
-
- -
|
44
|
+
- - ">="
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: '0'
|
46
47
|
description: A fluentd plugin to flatten nested hash structure as a flat record
|
@@ -50,40 +51,43 @@ executables: []
|
|
50
51
|
extensions: []
|
51
52
|
extra_rdoc_files: []
|
52
53
|
files:
|
53
|
-
- .gitignore
|
54
|
+
- ".gitignore"
|
54
55
|
- Gemfile
|
55
56
|
- LICENSE.txt
|
56
57
|
- README.md
|
57
58
|
- Rakefile
|
58
59
|
- fluent-plugin-flatten-hash.gemspec
|
60
|
+
- lib/fluent/plugin/filter_flatten_hash.rb
|
59
61
|
- lib/fluent/plugin/out_flatten_hash.rb
|
62
|
+
- lib/fluent/plugin/util.rb
|
60
63
|
- test/helper.rb
|
64
|
+
- test/plugin/test_filter_flatten_hash.rb
|
61
65
|
- test/plugin/test_out_flatten_hash.rb
|
62
66
|
homepage: https://github.com/sabottenda/fluent-plugin-flatten-hash
|
63
67
|
licenses:
|
64
68
|
- MIT
|
69
|
+
metadata: {}
|
65
70
|
post_install_message:
|
66
71
|
rdoc_options: []
|
67
72
|
require_paths:
|
68
73
|
- lib
|
69
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
75
|
requirements:
|
72
|
-
- -
|
76
|
+
- - ">="
|
73
77
|
- !ruby/object:Gem::Version
|
74
78
|
version: '0'
|
75
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
80
|
requirements:
|
78
|
-
- -
|
81
|
+
- - ">="
|
79
82
|
- !ruby/object:Gem::Version
|
80
83
|
version: '0'
|
81
84
|
requirements: []
|
82
85
|
rubyforge_project:
|
83
|
-
rubygems_version:
|
86
|
+
rubygems_version: 2.2.2
|
84
87
|
signing_key:
|
85
|
-
specification_version:
|
88
|
+
specification_version: 4
|
86
89
|
summary: A fluentd plugin to flatten nested hash structure as a flat record
|
87
90
|
test_files:
|
88
91
|
- test/helper.rb
|
92
|
+
- test/plugin/test_filter_flatten_hash.rb
|
89
93
|
- test/plugin/test_out_flatten_hash.rb
|