fluent-plugin-filter_typecast 0.0.1
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 +14 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +92 -0
- data/Rakefile +18 -0
- data/example.conf +14 -0
- data/fluent-plugin-filter_typecast.gemspec +24 -0
- data/lib/fluent/plugin/filter_typecast.rb +13 -0
- data/test/helper.rb +8 -0
- data/test/test_filter_typecast.rb +77 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1919117676570ea14329cf37d6f50b9a64aa9c9c
|
4
|
+
data.tar.gz: f5398fbf065a0dff9a47bd8d6d3ea27454682911
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17378ad33c8d69a6f208a73c7bfbede155ece0d53cc358f1021fd65351fbced042c1312f9266892705c697280b4aa40036e011004f4807484673bc4369f7b1f7
|
7
|
+
data.tar.gz: ff47c7167231a5dccffafcf53f842258ceb855a68e2cd061ff2207c0c7fad0d3ccf9cdc9f01c7ddfa1067a09c59fddef01d37533a261eff016c8685c92cac3de
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Naotoshi Seo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# fluent-plugin-filter_typecast
|
2
|
+
|
3
|
+
[](http://travis-ci.org/sonots/fluent-plugin-filter_typecast)
|
4
|
+
|
5
|
+
A Fluentd filter plugin to cast record types
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
Fluentd >= v0.12
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
Use RubyGems:
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install fluent-plugin-filter_typecast
|
17
|
+
```
|
18
|
+
|
19
|
+
## Configuration Example
|
20
|
+
|
21
|
+
```apache
|
22
|
+
<source>
|
23
|
+
type dummy
|
24
|
+
tag dummy
|
25
|
+
dummy {"field1":"1","field2":"2","field3":"2013-02-12 22:04:14 UTC","field4":"true","field5":"a,b,c"}
|
26
|
+
</source>
|
27
|
+
|
28
|
+
<filter **>
|
29
|
+
type typecast
|
30
|
+
types field1:integer,field2:string,field3:time,field4:bool,field5:array
|
31
|
+
</filter>
|
32
|
+
|
33
|
+
<match **>
|
34
|
+
type stdout
|
35
|
+
</match>
|
36
|
+
```
|
37
|
+
|
38
|
+
You should see casted records:
|
39
|
+
|
40
|
+
```
|
41
|
+
dummy {"field1":1,"field2":"2","field3":1418380657,"field4":true,"field5":["a","b","c"]}
|
42
|
+
```
|
43
|
+
|
44
|
+
## Parameters
|
45
|
+
|
46
|
+
* types
|
47
|
+
* KEY:TYPE pairs separated by comma(,)
|
48
|
+
* support types:
|
49
|
+
* integer
|
50
|
+
* float
|
51
|
+
* string
|
52
|
+
* time
|
53
|
+
* bool
|
54
|
+
* array
|
55
|
+
|
56
|
+
### time_format
|
57
|
+
|
58
|
+
Time format can be specified like `KEY:time:TIME_FORMAT` as:
|
59
|
+
|
60
|
+
```apache
|
61
|
+
<filter **>
|
62
|
+
type typecast
|
63
|
+
types field3:time:%d/%b/%Y:%H:%M:%S %z
|
64
|
+
</filter>
|
65
|
+
```
|
66
|
+
|
67
|
+
### array_delimiter
|
68
|
+
|
69
|
+
Array delimiter can be specified like `KEY:array:DELIMITER` as:
|
70
|
+
|
71
|
+
```apache
|
72
|
+
<filter **>
|
73
|
+
type typecast
|
74
|
+
types field5:array:.
|
75
|
+
</filter>
|
76
|
+
```
|
77
|
+
|
78
|
+
## ChangeLog
|
79
|
+
|
80
|
+
See [CHANGELOG.md](CHANGELOG.md) for details.
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
1. Fork it
|
85
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
86
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
87
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
88
|
+
5. Create new [Pull Request](../../pull/new/master)
|
89
|
+
|
90
|
+
## Copyright
|
91
|
+
|
92
|
+
Copyright (c) 2015 Naotoshi Seo. See [LICENSE](LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
desc 'Run test_unit based test'
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.test_files = Dir["test/**/test_*.rb"].sort
|
9
|
+
t.verbose = true
|
10
|
+
#t.warning = true
|
11
|
+
end
|
12
|
+
task :default => :test
|
13
|
+
|
14
|
+
desc 'Open an irb session preloaded with the gem library'
|
15
|
+
task :console do
|
16
|
+
sh 'irb -rubygems -I lib'
|
17
|
+
end
|
18
|
+
task :c => :console
|
data/example.conf
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
<source>
|
2
|
+
type dummy
|
3
|
+
tag dummy
|
4
|
+
dummy {"field1":"1","field2":"2","field3":"2013-02-12 22:04:14 UTC","field4":"true","field5":"a,b,c","other":"other"}
|
5
|
+
</source>
|
6
|
+
|
7
|
+
<filter **>
|
8
|
+
type typecast
|
9
|
+
types field1:integer,field2:string,field3:time,field4:bool,field5:array
|
10
|
+
</filter>
|
11
|
+
|
12
|
+
<match **>
|
13
|
+
type stdout
|
14
|
+
</match>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-filter_typecast"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Naotoshi Seo"]
|
8
|
+
s.email = ["sonots@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/sonots/fluent-plugin-filter_typecast"
|
10
|
+
s.summary = "A Fluentd filter plugin to cast record types"
|
11
|
+
s.description = s.summary
|
12
|
+
s.licenses = ["MIT"]
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency "fluentd", ">= 0.12"
|
20
|
+
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "test-unit"
|
22
|
+
s.add_development_dependency "pry"
|
23
|
+
s.add_development_dependency "pry-nav"
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Fluent
|
2
|
+
class TypecastFilter < Filter
|
3
|
+
Fluent::Plugin.register_filter('typecast', self)
|
4
|
+
|
5
|
+
include ::Fluent::TextParser::TypeConverter
|
6
|
+
|
7
|
+
def filter(tag, time, record)
|
8
|
+
record.map do |key, val|
|
9
|
+
[key, convert_type(key, val)]
|
10
|
+
end.to_h
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'fluent/plugin/filter_typecast'
|
3
|
+
|
4
|
+
class DupFilterTest < Test::Unit::TestCase
|
5
|
+
include Fluent
|
6
|
+
|
7
|
+
setup do
|
8
|
+
Fluent::Test.setup
|
9
|
+
@time = Fluent::Engine.now
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_driver(conf = '')
|
13
|
+
Test::FilterTestDriver.new(TypecastFilter).configure(conf, true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def filter(d, msgs)
|
17
|
+
d.run {
|
18
|
+
msgs.each {|msg|
|
19
|
+
d.filter(msg, @time)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
d.filtered_as_array
|
23
|
+
end
|
24
|
+
|
25
|
+
sub_test_case 'configure' do
|
26
|
+
def test_types
|
27
|
+
d = create_driver(%[
|
28
|
+
types string:string,integer:integer,float:float,bool:bool,time:time,array:array
|
29
|
+
])
|
30
|
+
types = d.instance.instance_variable_get(:@type_converters)
|
31
|
+
converters = ::Fluent::TextParser::TypeConverter::Converters
|
32
|
+
assert_equal converters['string'], types['string']
|
33
|
+
assert_equal converters['integer'], types['integer']
|
34
|
+
assert_equal converters['float'], types['float']
|
35
|
+
assert_equal converters['bool'], types['bool']
|
36
|
+
# assert_equal converters['time'], types['time']
|
37
|
+
# assert_equal converters['array'], types['array']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
sub_test_case 'test_type_cast' do
|
42
|
+
def test_types
|
43
|
+
d = create_driver(%[
|
44
|
+
types string:string,integer:integer,float:float,bool:bool,time:time,array:array
|
45
|
+
])
|
46
|
+
msg = {
|
47
|
+
'integer' => '1',
|
48
|
+
'string' => 'foo',
|
49
|
+
'time' => '2013-02-12 22:01:15 UTC',
|
50
|
+
'bool' => 'true',
|
51
|
+
'array' => 'a,b,c',
|
52
|
+
'other' => 'other',
|
53
|
+
}
|
54
|
+
filtered = filter(d, [msg]).first[2]
|
55
|
+
assert_equal 1, filtered['integer']
|
56
|
+
assert_equal 'foo', filtered['string']
|
57
|
+
assert_equal 1360706475, filtered['time']
|
58
|
+
assert_equal true, filtered['bool']
|
59
|
+
assert_equal ['a', 'b', 'c'], filtered['array']
|
60
|
+
assert_equal 'other', filtered['other']
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_time_format
|
64
|
+
d = create_driver(%[types time:time:%d/%b/%Y:%H:%M:%S %z])
|
65
|
+
msg = { 'time' => '12/Dec/2014:19:37:37 +0900' }
|
66
|
+
filtered = filter(d, [msg]).first[2]
|
67
|
+
assert_equal 1418380657, filtered['time']
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_array_delimiter
|
71
|
+
d = create_driver(%[types array:array:.])
|
72
|
+
msg = { 'array' => 'a.b.c' }
|
73
|
+
filtered = filter(d, [msg]).first[2]
|
74
|
+
assert_equal ['a','b','c'], filtered['array']
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-filter_typecast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naotoshi Seo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-27 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.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-nav
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A Fluentd filter plugin to cast record types
|
84
|
+
email:
|
85
|
+
- sonots@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CHANGELOG.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- example.conf
|
98
|
+
- fluent-plugin-filter_typecast.gemspec
|
99
|
+
- lib/fluent/plugin/filter_typecast.rb
|
100
|
+
- test/helper.rb
|
101
|
+
- test/test_filter_typecast.rb
|
102
|
+
homepage: https://github.com/sonots/fluent-plugin-filter_typecast
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: A Fluentd filter plugin to cast record types
|
126
|
+
test_files:
|
127
|
+
- test/helper.rb
|
128
|
+
- test/test_filter_typecast.rb
|