fluent-plugin-typecast 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "fluentd", "~> 0.10.0"
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem "rdoc", "~> 3.12"
9
+ gem "jeweler", "~> 1.8.4"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ cool.io (1.1.0)
5
+ iobuffer (>= 1.0.0)
6
+ fluentd (0.10.32)
7
+ cool.io (~> 1.1.0)
8
+ http_parser.rb (~> 0.5.1)
9
+ json (>= 1.4.3)
10
+ msgpack (~> 0.4.4)
11
+ yajl-ruby (~> 1.0)
12
+ git (1.2.5)
13
+ http_parser.rb (0.5.3)
14
+ iobuffer (1.1.2)
15
+ jeweler (1.8.4)
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ rdoc
20
+ json (1.7.7)
21
+ msgpack (0.4.7)
22
+ rake (10.0.3)
23
+ rdoc (3.12.2)
24
+ json (~> 1.4)
25
+ yajl-ruby (1.1.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ fluentd (~> 0.10.0)
32
+ jeweler (~> 1.8.4)
33
+ rdoc (~> 3.12)
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2013 MORIYA Taro
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = fluent-plugin-typecast
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to fluent-plugin-typecast
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Taro Moriya. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "fluent-plugin-typecast"
18
+ gem.homepage = "http://github.com/tarom/fluent-plugin-typecast"
19
+ gem.license = "Apache License 2.0"
20
+ gem.summary = %Q{typecast output plugin for fluentd}
21
+ gem.description = gem.summary
22
+ gem.email = "taro.toys@gmail.com"
23
+ gem.authors = ["MORIYA Taro"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "fluent-plugin-typecast #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fluent-plugin-typecast}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["MORIYA Taro"]
12
+ s.date = %q{2013-03-25}
13
+ s.description = %q{typecast output plugin for fluentd}
14
+ s.email = %q{taro.toys@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "fluent-plugin-typecast.gemspec",
28
+ "lib/fluent/plugin/out_typecast.rb",
29
+ "test/helper.rb",
30
+ "test/plugin/test_out_typecast.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/tarom/fluent-plugin-typecast}
33
+ s.licenses = ["Apache License 2.0"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.6.0}
36
+ s.summary = %q{typecast output plugin for fluentd}
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<fluentd>, ["~> 0.10.0"])
43
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
44
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
45
+ else
46
+ s.add_dependency(%q<fluentd>, ["~> 0.10.0"])
47
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<fluentd>, ["~> 0.10.0"])
52
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,60 @@
1
+ module Fluent
2
+ class TypecastOutput < Output
3
+ Fluent::Plugin.register_output('typecast', self)
4
+
5
+ config_param :item_types, default: nil do |value|
6
+ map = value.split(',').map do |type|
7
+ key, type = type.split(/:/)
8
+ if ITEM_TYPES.include?(type)
9
+ [key, type]
10
+ else
11
+ raise ConfigError, "typecast: 'item_types' parameter format is \"KEY:TYPE,...\"\nTYPE is #{ITEM_TYPES.join(', ')}"
12
+ end
13
+ end
14
+ Hash[*map.flatten(1)]
15
+ end
16
+ config_param :time_format, :string, default: nil
17
+ config_param :tag, :string, default: nil
18
+ config_param :prefix, :string, default: nil
19
+
20
+ ITEM_TYPES = ['string', 'integer', 'bool', 'time', 'array']
21
+
22
+ def configure(conf)
23
+ super
24
+ raise ConfigError, "typecast: 'prefix' or 'tag' is required" unless @tag or @prefix
25
+ end
26
+
27
+ def emit(tag, es, chain)
28
+ tag =
29
+ if @tag
30
+ @tag
31
+ elsif @prefix
32
+ "#{@prefix}.#{tag}"
33
+ end
34
+ es.each do |time, record|
35
+ record.keys.each do |key|
36
+ record[key] = cast(key, record[key])
37
+ end
38
+ Fluent::Engine.emit(tag, time, record)
39
+ end
40
+ chain.next
41
+ end
42
+
43
+ def cast(key, value)
44
+ case @item_types[key]
45
+ when 'string'
46
+ value.to_s
47
+ when 'integer'
48
+ value.to_i
49
+ when 'bool'
50
+ Config.bool_value(value)
51
+ when 'time'
52
+ Time.strptime(value, @time_format)
53
+ when 'array'
54
+ value.split(/\s*,\s*/)
55
+ else
56
+ value
57
+ end
58
+ end
59
+ end
60
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ require 'fluent/plugin/out_typecast'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,77 @@
1
+ require 'helper'
2
+
3
+ class TestTypecastOutput < Test::Unit::TestCase
4
+
5
+ DEFAULT_CONFIG = %[
6
+ type typecast
7
+ ]
8
+
9
+ def setup
10
+ Fluent::Test.setup
11
+ end
12
+
13
+ def teardown
14
+ end
15
+
16
+ def test_configure
17
+ time_format = "%d/%b/%Y:%H:%M:%S %z"
18
+ tag = "test.tag"
19
+ prefix = "prefix"
20
+ d = create_driver(DEFAULT_CONFIG + %[
21
+ item_types test1:integer,test2:string,test3:time,test4:bool
22
+ time_format #{time_format}
23
+ tag #{tag}
24
+ prefix #{prefix}
25
+ ]).instance
26
+
27
+ assert_equal('integer', d.item_types['test1'])
28
+ assert_equal('string', d.item_types['test2'])
29
+ assert_equal('time', d.item_types['test3'])
30
+ assert_equal('bool', d.item_types['test4'])
31
+
32
+ assert_equal(time_format, d.time_format)
33
+ assert_equal(tag, d.tag)
34
+ assert_equal(prefix, d.prefix)
35
+ end
36
+
37
+ def test_typecast
38
+ d = create_driver(DEFAULT_CONFIG + %[
39
+ tag test.tag
40
+ item_types i:integer,s:string,t:time,b:bool,a:array
41
+ time_format %Y-%m-%d %H:%M:%S %z
42
+ ])
43
+ time = Time.parse('2013-02-12 22:01:15 UTC').to_i
44
+ t = '2013-02-12 22:04:14 UTC'
45
+ record = {'i' => '1', 's' => 'foo', 't' => t, 'b' => 'true', 'a' => 'a, b, c', 'o' => 'other'}
46
+ d.run do
47
+ d.emit(record, time)
48
+ end
49
+ emits = d.emits
50
+ assert_equal 1, emits.length
51
+ tag, time, record = emits[0]
52
+ assert_equal(1, record['i'])
53
+ assert_equal('foo', record['s'])
54
+ assert_equal(Time.gm(2013, 2, 12, 22, 4, 14), record['t'])
55
+ assert_equal(true, record['b'])
56
+ assert_equal(['a', 'b', 'c'], record['a'])
57
+ assert_equal('other', record['o'])
58
+ end
59
+
60
+ def test_prefix
61
+ d = create_driver(DEFAULT_CONFIG + %[
62
+ item_types i:integer,s:string,t:time,b:bool,a:array
63
+ prefix prefix
64
+ ])
65
+ d.run do
66
+ d.emit({}, Time.now)
67
+ end
68
+ emits = d.emits
69
+ assert_equal 1, emits.length
70
+ tag, time, record = emits[0]
71
+ assert_equal('prefix.test', tag)
72
+ end
73
+
74
+ def create_driver(conf = DEFAULT_CONFIG, tag = 'test')
75
+ Fluent::Test::OutputTestDriver.new(Fluent::TypecastOutput, tag).configure(conf)
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-typecast
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - MORIYA Taro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2013-03-25 00:00:00 +09:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: fluentd
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.10.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: "3.12"
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: jeweler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.4
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ description: typecast output plugin for fluentd
50
+ email: taro.toys@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE.txt
57
+ - README.rdoc
58
+ files:
59
+ - .document
60
+ - Gemfile
61
+ - Gemfile.lock
62
+ - LICENSE.txt
63
+ - README.rdoc
64
+ - Rakefile
65
+ - VERSION
66
+ - fluent-plugin-typecast.gemspec
67
+ - lib/fluent/plugin/out_typecast.rb
68
+ - test/helper.rb
69
+ - test/plugin/test_out_typecast.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/tarom/fluent-plugin-typecast
72
+ licenses:
73
+ - Apache License 2.0
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: -1267792702769587784
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.6.0
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: typecast output plugin for fluentd
101
+ test_files: []
102
+