fluent-plugin-flatten-hash 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -0
- data/fluent-plugin-flatten-hash.gemspec +1 -1
- data/lib/fluent/plugin/filter_flatten_hash.rb +2 -1
- data/lib/fluent/plugin/flatten_hash_util.rb +7 -3
- data/lib/fluent/plugin/out_flatten_hash.rb +1 -0
- data/test/plugin/test_filter_flatten_array.rb +47 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd341b3cebe6a2b4dc68dbdc5b0e748acc25de57
|
4
|
+
data.tar.gz: 0c8ef3cc6db0d4324cef5a85a07340db96272a46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8a52a3dc1e4f390bbc7a8b1d1edbe19b78379b683d4682c5f2c340c8719d51cdc468fbf6078dcd9e85311d27a1cbb68f2e1340a2c40ea2270af4d36a80e36f2
|
7
|
+
data.tar.gz: 0b64864c3082f235285e90baf3d81a1bc7a2ab451d4673b04a350dd07a44325d9bf3e8e4765eb477a965961a8fc3102929b24aabaf58151c1c4128735a3570ac
|
data/README.md
CHANGED
@@ -66,6 +66,28 @@ The message is flattened like below:
|
|
66
66
|
}
|
67
67
|
```
|
68
68
|
|
69
|
+
In order to prevent arrays from being indexed, you can use a configuration like below:
|
70
|
+
|
71
|
+
```
|
72
|
+
<match message>
|
73
|
+
type flatten_hash
|
74
|
+
add_tag_prefix flattened.
|
75
|
+
separator _
|
76
|
+
flatten_array false
|
77
|
+
</match>
|
78
|
+
```
|
79
|
+
|
80
|
+
Using the same input, you'll instead end up with a message flattened like below:
|
81
|
+
|
82
|
+
```js
|
83
|
+
{
|
84
|
+
"message_today":"good day",
|
85
|
+
"message_tommorow_is_a_bad":"day",
|
86
|
+
"days":["2013/08/24","2013/08/25"]
|
87
|
+
}
|
88
|
+
```
|
89
|
+
|
90
|
+
|
69
91
|
### Filter
|
70
92
|
|
71
93
|
You can set a configuration like below:
|
@@ -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.
|
7
|
+
spec.version = "0.4.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}
|
@@ -7,9 +7,13 @@ module Fluent
|
|
7
7
|
ret.merge! flatten_record(value, prefix + [key.to_s])
|
8
8
|
}
|
9
9
|
elsif record.is_a? Array
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
if @flatten_array
|
11
|
+
record.each_with_index { |elem, index|
|
12
|
+
ret.merge! flatten_record(elem, prefix + [index.to_s])
|
13
|
+
}
|
14
|
+
else
|
15
|
+
return {prefix.join(@separator) => record}
|
16
|
+
end
|
13
17
|
else
|
14
18
|
return {prefix.join(@separator) => record}
|
15
19
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fluent/plugin/filter_flatten_hash'
|
3
|
+
|
4
|
+
class FlattenHashFlattenArrayFilterTest < 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
|
+
flatten_array false
|
13
|
+
]
|
14
|
+
|
15
|
+
def setup
|
16
|
+
Fluent::Test.setup
|
17
|
+
@time = Fluent::Engine.now
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_driver(conf = '')
|
21
|
+
Test::FilterTestDriver.new(FlattenHashFilter).configure(conf, true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_flatten_record_flatten_array_false
|
25
|
+
d = create_driver CONFIG
|
26
|
+
es = Fluent::MultiEventStream.new
|
27
|
+
now = Fluent::Engine.now
|
28
|
+
|
29
|
+
d.run do
|
30
|
+
d.emit({'message' => {'foo' => 'bar'}})
|
31
|
+
d.emit({"message" => {'foo' => 'bar', 'hoge' => 'fuga'}})
|
32
|
+
d.emit({"message" => {'nest' => {'foo' => 'bar'}}})
|
33
|
+
d.emit({"message" => {'nest' => {'nest' => {'foo' => 'bar'}}}})
|
34
|
+
d.emit({"message" => {'array' => ['foo', 'bar']}})
|
35
|
+
d.emit({"message" => {'array' => [{'foo' => 'bar'}, {'hoge' => 'fuga'}]}})
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_equal [
|
39
|
+
{"message.foo" => "bar"},
|
40
|
+
{"message.foo" => "bar", "message.hoge" => "fuga"},
|
41
|
+
{"message.nest.foo" => "bar"},
|
42
|
+
{"message.nest.nest.foo" => "bar"},
|
43
|
+
{"message.array"=>["foo", "bar"]},
|
44
|
+
{"message.array"=>[{"foo"=>"bar"}, {"hoge"=>"fuga"}]},
|
45
|
+
], d.filtered_as_array.map{|x| x[2]}
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-flatten-hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Sano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/fluent/plugin/flatten_hash_util.rb
|
71
71
|
- lib/fluent/plugin/out_flatten_hash.rb
|
72
72
|
- test/helper.rb
|
73
|
+
- test/plugin/test_filter_flatten_array.rb
|
73
74
|
- test/plugin/test_filter_flatten_hash.rb
|
74
75
|
- test/plugin/test_out_flatten_hash.rb
|
75
76
|
homepage: https://github.com/kazegusuri/fluent-plugin-flatten-hash
|
@@ -98,5 +99,6 @@ specification_version: 4
|
|
98
99
|
summary: A fluentd plugin to flatten nested hash structure as a flat record
|
99
100
|
test_files:
|
100
101
|
- test/helper.rb
|
102
|
+
- test/plugin/test_filter_flatten_array.rb
|
101
103
|
- test/plugin/test_filter_flatten_hash.rb
|
102
104
|
- test/plugin/test_out_flatten_hash.rb
|