fluent-plugin-record_splitter 0.1.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 +7 -0
- data/.gitignore +39 -0
- data/Gemfile +3 -0
- data/README.md +69 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/fluent-plugin-record_splitter.gemspec +23 -0
- data/lib/fluent/plugin/out_record_splitter.rb +60 -0
- data/test/test_out_record_splitter.rb +92 -0
- metadata +114 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: faeed660e0eaba82e6fe96a667ccc4d4cc2eae39
|
|
4
|
+
data.tar.gz: 1d903b0a9fceb640c546ef5fc0dcf2ff30dbc2d3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c64f73f88e5fe20f7a74218ba45246e2a3b6f03aa075b143d4a23ef6023b91f658d47aeed3bc3d195b0fc8aac983f86fc520372874bffa3c40acb64ee56457b6
|
|
7
|
+
data.tar.gz: 3b217075b76f801f2db5ff8ab86ec54ff46361ce4fac8d13febe74f9766978b10fa3435cace3a5e104d0808a50743972a3fa980c5cfbe0ec9e38fde5f5f71059
|
data/.gitignore
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
*.swp
|
|
4
|
+
/.config
|
|
5
|
+
/coverage/
|
|
6
|
+
/InstalledFiles
|
|
7
|
+
/pkg/
|
|
8
|
+
/spec/reports/
|
|
9
|
+
/spec/examples.txt
|
|
10
|
+
/test/tmp/
|
|
11
|
+
/test/version_tmp/
|
|
12
|
+
/tmp/
|
|
13
|
+
|
|
14
|
+
Gemfile.lock
|
|
15
|
+
|
|
16
|
+
## Specific to RubyMotion:
|
|
17
|
+
.dat*
|
|
18
|
+
.repl_history
|
|
19
|
+
build/
|
|
20
|
+
|
|
21
|
+
## Documentation cache and generated files:
|
|
22
|
+
/.yardoc/
|
|
23
|
+
/_yardoc/
|
|
24
|
+
/doc/
|
|
25
|
+
/rdoc/
|
|
26
|
+
|
|
27
|
+
## Environment normalisation:
|
|
28
|
+
/.bundle/
|
|
29
|
+
/vendor/
|
|
30
|
+
/lib/bundler/man/
|
|
31
|
+
|
|
32
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
33
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
34
|
+
# Gemfile.lock
|
|
35
|
+
# .ruby-version
|
|
36
|
+
# .ruby-gemset
|
|
37
|
+
|
|
38
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
39
|
+
.rvmrc
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
fluent-plugin-record_splitter
|
|
2
|
+
=====================
|
|
3
|
+
|
|
4
|
+
Output split array plugin for fluentd.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
gem install fluent-plugin-record_splitter
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Configuration
|
|
13
|
+
|
|
14
|
+
<match pattern>
|
|
15
|
+
type record_splitter
|
|
16
|
+
tag foo.splitted
|
|
17
|
+
split_key target_field
|
|
18
|
+
keep_keys ["common","general"]
|
|
19
|
+
</match>
|
|
20
|
+
|
|
21
|
+
If following record is passed:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
{'common':'c', 'general':'g', 'other':'foo', 'target_field':[ {'k1':'v1'}, {'k2':'v2'} ] }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
then you got new records like below:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
{'common':'c', 'general':'g', 'k1':'v1'}
|
|
31
|
+
{'common':'c', 'general':'g', 'k2':'v2'}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
another configuration
|
|
35
|
+
|
|
36
|
+
<match pattern>
|
|
37
|
+
type record_splitter
|
|
38
|
+
tag foo.splitted
|
|
39
|
+
split_key target_field
|
|
40
|
+
keep_other_key true
|
|
41
|
+
remove_keys ["general"]
|
|
42
|
+
</match>
|
|
43
|
+
|
|
44
|
+
If following record is passed:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
{'common':'c', 'general':'g', 'other':'foo', 'target_field':[ {'k1':'v1'}, {'k2':'v2'} ] }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
then you got new records like below:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
{'common':'c', 'other':'foo', 'k1':'v1'}
|
|
54
|
+
{'common':'c', 'other':'foo', 'k2':'v2'}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Copyright
|
|
58
|
+
|
|
59
|
+
<table>
|
|
60
|
+
<tr>
|
|
61
|
+
<td>Author</td><td>Yuri Odagiri <ixixizko@gmail.com></td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td>Copyright</td><td>Copyright (c) 2015- Yuri Odagiri</td>
|
|
65
|
+
</tr>
|
|
66
|
+
<tr>
|
|
67
|
+
<td>License</td><td>MIT License</td>
|
|
68
|
+
</tr>
|
|
69
|
+
</table>
|
data/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
require 'bundler/gem_tasks'
|
|
3
|
+
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |test|
|
|
7
|
+
test.libs << 'lib' << 'test'
|
|
8
|
+
test.test_files = FileList['test/test_*.rb']
|
|
9
|
+
test.verbose = true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
task :default => [:build]
|
|
13
|
+
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.3
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.name = "fluent-plugin-record_splitter"
|
|
6
|
+
gem.description = "output split array plugin for fluentd"
|
|
7
|
+
gem.homepage = "https://github.com/ixixi/fluent-plugin-record_splitter"
|
|
8
|
+
gem.summary = gem.description
|
|
9
|
+
gem.version = File.read("VERSION").strip
|
|
10
|
+
gem.authors = ["Yuri Odagiri"]
|
|
11
|
+
gem.email = "ixixizko@gmail.com"
|
|
12
|
+
gem.has_rdoc = false
|
|
13
|
+
gem.license = 'MIT'
|
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
17
|
+
gem.require_paths = ['lib']
|
|
18
|
+
|
|
19
|
+
gem.add_dependency "fluentd", [">= 0.10.58", "< 2"]
|
|
20
|
+
gem.add_dependency "fluent-mixin-config-placeholders", ">= 0.3.0"
|
|
21
|
+
gem.add_dependency "fluent-mixin-rewrite-tag-name"
|
|
22
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
|
23
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'fluent/mixin/config_placeholders'
|
|
2
|
+
require 'fluent/mixin/rewrite_tag_name'
|
|
3
|
+
|
|
4
|
+
module Fluent
|
|
5
|
+
class RecordSplitterOutput < Output
|
|
6
|
+
Fluent::Plugin.register_output('record_splitter', self)
|
|
7
|
+
|
|
8
|
+
config_param :tag, :string
|
|
9
|
+
config_param :remove_prefix, :string, :default => nil
|
|
10
|
+
config_param :add_prefix, :string, :default => nil
|
|
11
|
+
config_param :split_key, :string
|
|
12
|
+
config_param :keep_other_key, :bool, :default => false
|
|
13
|
+
config_param :keep_keys, :array, :default => []
|
|
14
|
+
config_param :remove_keys, :array, :default => []
|
|
15
|
+
|
|
16
|
+
include SetTagKeyMixin
|
|
17
|
+
include Fluent::Mixin::ConfigPlaceholders
|
|
18
|
+
include Fluent::HandleTagNameMixin
|
|
19
|
+
include Fluent::Mixin::RewriteTagName
|
|
20
|
+
|
|
21
|
+
def configure(conf)
|
|
22
|
+
super
|
|
23
|
+
if not @keep_keys.empty? and not @remove_keys.empty?
|
|
24
|
+
raise Fluent::ConfigError, 'Cannot set both keep_keys and remove_keys.'
|
|
25
|
+
end
|
|
26
|
+
if @keep_other_key and not @keep_keys.empty?
|
|
27
|
+
raise Fluent::ConfigError, 'Cannot set keep_keys when keep_other_key is true.'
|
|
28
|
+
end
|
|
29
|
+
if not @keep_other_key and not @remove_keys.empty?
|
|
30
|
+
raise Fluent::ConfigError, 'Cannot set remove_keys when keep_other_key is false.'
|
|
31
|
+
end
|
|
32
|
+
if not @tag and not @remove_prefix and not @add_prefix
|
|
33
|
+
raise Fluent::ConfigError, "missing both of remove_prefix and add_prefix"
|
|
34
|
+
end
|
|
35
|
+
if @tag and (@remove_prefix or @add_prefix)
|
|
36
|
+
raise Fluent::ConfigError, "both of tag and remove_prefix/add_prefix must not be specified"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def emit(tag, es, chain)
|
|
41
|
+
emit_tag = tag.dup
|
|
42
|
+
es.each { |time, record|
|
|
43
|
+
filter_record(emit_tag, time, record)
|
|
44
|
+
if keep_other_key
|
|
45
|
+
common = record.reject{|key, value| key == @split_key or @remove_keys.include?(key) }
|
|
46
|
+
else
|
|
47
|
+
common = record.select{|key, value| @keep_keys.include?(key) }
|
|
48
|
+
end
|
|
49
|
+
if record.key?(@split_key)
|
|
50
|
+
record[@split_key].each{|v|
|
|
51
|
+
v.merge!(common) unless common.empty?
|
|
52
|
+
Engine.emit(emit_tag, time, v.merge(common))
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
}
|
|
56
|
+
chain.next
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require 'fluent/test'
|
|
2
|
+
require 'fluent/plugin/out_record_splitter'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class RecordSplitterOutputTest < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
Fluent::Test.setup
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
CONFIG = %[
|
|
11
|
+
type record_splitter
|
|
12
|
+
tag foo.splitted
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
def create_driver(conf = CONFIG)
|
|
16
|
+
Fluent::Test::OutputTestDriver.new(Fluent::RecordSplitterOutput, tag='test_tag').configure(conf)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_split_default
|
|
20
|
+
d = create_driver %[
|
|
21
|
+
type record_splitter
|
|
22
|
+
tag foo.splitted
|
|
23
|
+
split_key target_field
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
d.run do
|
|
27
|
+
d.emit('other'=>'foo','target_field' => [{'k1'=>'v1'},{'k2'=>'v2'}])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
assert_equal [
|
|
31
|
+
{'k1'=>'v1'},
|
|
32
|
+
{'k2'=>'v2'},
|
|
33
|
+
], d.records
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_split_with_keep_other_key
|
|
38
|
+
d = create_driver %[
|
|
39
|
+
type record_splitter
|
|
40
|
+
tag foo.splitted
|
|
41
|
+
split_key target_field
|
|
42
|
+
keep_other_key true
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
d.run do
|
|
46
|
+
d.emit('common'=>'c','general'=>'g','other'=>'foo','target_field' => [{'k1'=>'v1'},{'k2'=>'v2'}])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
assert_equal [
|
|
50
|
+
{'common'=>'c','general'=>'g','other'=>'foo','k1'=>'v1'},
|
|
51
|
+
{'common'=>'c','general'=>'g','other'=>'foo','k2'=>'v2'},
|
|
52
|
+
], d.records
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_split_with_keep_other_key_and_remove_key
|
|
56
|
+
d = create_driver %[
|
|
57
|
+
type record_splitter
|
|
58
|
+
tag foo.splitted
|
|
59
|
+
split_key target_field
|
|
60
|
+
keep_other_key true
|
|
61
|
+
remove_keys ["general","other"]
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
d.run do
|
|
65
|
+
d.emit('common'=>'c','general'=>'g','other'=>'foo','target_field' => [{'k1'=>'v1'},{'k2'=>'v2'}])
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
assert_equal [
|
|
69
|
+
{'common'=>'c','k1'=>'v1'},
|
|
70
|
+
{'common'=>'c','k2'=>'v2'},
|
|
71
|
+
], d.records
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_split_with_keep_keys
|
|
75
|
+
d = create_driver %[
|
|
76
|
+
type record_splitter
|
|
77
|
+
tag foo.splitted
|
|
78
|
+
split_key target_field
|
|
79
|
+
keep_keys ["common","general"]
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
d.run do
|
|
83
|
+
d.emit('common'=>'c','general'=>'g','other'=>'foo','target_field' => [{'k1'=>'v1'},{'k2'=>'v2'}])
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
assert_equal [
|
|
87
|
+
{'common'=>'c','general'=>'g','k1'=>'v1'},
|
|
88
|
+
{'common'=>'c','general'=>'g','k2'=>'v2'},
|
|
89
|
+
], d.records
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: fluent-plugin-record_splitter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yuri Odagiri
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: fluentd
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.10.58
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '2'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.10.58
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: fluent-mixin-config-placeholders
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.3.0
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.3.0
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: fluent-mixin-rewrite-tag-name
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rake
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 0.9.2
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 0.9.2
|
|
75
|
+
description: output split array plugin for fluentd
|
|
76
|
+
email: ixixizko@gmail.com
|
|
77
|
+
executables: []
|
|
78
|
+
extensions: []
|
|
79
|
+
extra_rdoc_files: []
|
|
80
|
+
files:
|
|
81
|
+
- ".gitignore"
|
|
82
|
+
- Gemfile
|
|
83
|
+
- README.md
|
|
84
|
+
- Rakefile
|
|
85
|
+
- VERSION
|
|
86
|
+
- fluent-plugin-record_splitter.gemspec
|
|
87
|
+
- lib/fluent/plugin/out_record_splitter.rb
|
|
88
|
+
- test/test_out_record_splitter.rb
|
|
89
|
+
homepage: https://github.com/ixixi/fluent-plugin-record_splitter
|
|
90
|
+
licenses:
|
|
91
|
+
- MIT
|
|
92
|
+
metadata: {}
|
|
93
|
+
post_install_message:
|
|
94
|
+
rdoc_options: []
|
|
95
|
+
require_paths:
|
|
96
|
+
- lib
|
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
|
+
requirements:
|
|
104
|
+
- - ">="
|
|
105
|
+
- !ruby/object:Gem::Version
|
|
106
|
+
version: '0'
|
|
107
|
+
requirements: []
|
|
108
|
+
rubyforge_project:
|
|
109
|
+
rubygems_version: 2.4.1
|
|
110
|
+
signing_key:
|
|
111
|
+
specification_version: 4
|
|
112
|
+
summary: output split array plugin for fluentd
|
|
113
|
+
test_files:
|
|
114
|
+
- test/test_out_record_splitter.rb
|