fluent-plugin-mongo-typed 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "fluent-plugin-mongo", "~> 0.6.13", :require => false
4
+
5
+ group :test do
6
+ gem "rspec", "~> 2.8.0"
7
+ gem "simplecov", "~> 0.7.1", :require => false
8
+ end
9
+
10
+ group :development do
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.0.0"
13
+ gem "jeweler", "~> 1.8.4"
14
+ end
@@ -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.
@@ -0,0 +1,19 @@
1
+ = fluent-plugin-mongo-typed
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to fluent-plugin-mongo-typed
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 MORIYA Taro. See LICENSE.txt for
18
+ further details.
19
+
@@ -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-mongo-typed"
18
+ gem.homepage = "http://github.com/tarom/fluent-plugin-mongo-typed"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Typed mongo output plugin}
21
+ gem.description = %Q{Typed mongo output plugin}
22
+ gem.email = "taro.toys@gmail.com"
23
+ gem.authors = ["MORIYA Taro"]
24
+ # dependencies defined in Gemfile
25
+ gem.add_dependency "fluent-plugin-mongo", "~> 0.6.13"
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
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-mongo-typed #{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,64 @@
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-mongo-typed}
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-02-15}
13
+ s.description = %q{Typed mongo output plugin}
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
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "fluent-plugin-mongo-typed.gemspec",
27
+ "lib/fluent/mixin/mongo_typed_mixin.rb",
28
+ "lib/fluent/plugin/out_mongo_replset_typed.rb",
29
+ "lib/fluent/plugin/out_mongo_typed.rb",
30
+ "test/helper.rb",
31
+ "test/plugin/test_out_mongo_replset_typed.rb",
32
+ "test/plugin/test_out_mongo_typed.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/tarom/fluent-plugin-mongo-typed}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.6.0}
38
+ s.summary = %q{Typed mongo output plugin}
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<fluent-plugin-mongo>, ["~> 0.6.13"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
48
+ s.add_runtime_dependency(%q<fluent-plugin-mongo>, ["~> 0.6.13"])
49
+ else
50
+ s.add_dependency(%q<fluent-plugin-mongo>, ["~> 0.6.13"])
51
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
54
+ s.add_dependency(%q<fluent-plugin-mongo>, ["~> 0.6.13"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<fluent-plugin-mongo>, ["~> 0.6.13"])
58
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
61
+ s.add_dependency(%q<fluent-plugin-mongo>, ["~> 0.6.13"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,53 @@
1
+ module Fluent
2
+
3
+ module MongoTypedMixin
4
+
5
+ ITEM_TYPES = ['string', 'integer', 'bool', 'time', 'array']
6
+
7
+ attr_accessor :item_types, :time_format
8
+
9
+ def configure(conf)
10
+ super
11
+
12
+ map = conf['item_types'].split(',').map do |type|
13
+ key, type = type.split(/:/)
14
+ if ITEM_TYPES.include?(type)
15
+ [key, type]
16
+ else
17
+ raise ConfigError, "mongo_ex: 'item_types' parameter format is \"KEY:TYPE,...\"\nTYPE is #{ITEM_TYPES.join(', ')}"
18
+ end
19
+ end
20
+ @item_types = Hash[*map.flatten(1)]
21
+ @time_format = conf['time_format']
22
+ end
23
+
24
+ def collect_records(chunk)
25
+ records = []
26
+ chunk.msgpack_each { |time, record|
27
+ record = Hash[*record.map{|key, value|cast(key, value)}.flatten(1)]
28
+ record[@time_key] = Time.at(time || record[@time_key]) if @include_time_key
29
+ records << record
30
+ }
31
+ records
32
+ end
33
+
34
+ def cast(key, value)
35
+ value = case @item_types[key]
36
+ when 'string'
37
+ value.to_s
38
+ when 'integer'
39
+ value.to_i
40
+ when 'bool'
41
+ Config.bool_value(value)
42
+ when 'time'
43
+ Time.strptime(value, @time_format)
44
+ when 'array'
45
+ value.split(/\s*,\s*/)
46
+ else
47
+ value
48
+ end
49
+ [key, value]
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,11 @@
1
+ module Fluent
2
+
3
+ require 'fluent/plugin/out_mongo_replset'
4
+ require 'fluent/mixin/mongo_typed_mixin'
5
+
6
+ class MongoOutputReplsetTyped < MongoOutputReplset
7
+ Fluent::Plugin.register_output('mongo_replset_typed', self)
8
+ include MongoTypedMixin
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ module Fluent
2
+
3
+ require 'fluent/plugin/out_mongo'
4
+ require 'fluent/mixin/mongo_typed_mixin'
5
+
6
+ class MongoOutputTyped < MongoOutput
7
+ Fluent::Plugin.register_output('mongo_typed', self)
8
+ include MongoTypedMixin
9
+ end
10
+
11
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development, :test)
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
+
11
+ require 'test/unit'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'fluent/test'
16
+ require 'mongo'
17
+ require 'fluent/plugin/out_mongo_typed'
18
+
19
+ class Test::Unit::TestCase
20
+ end
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+ require 'plugin/test_out_mongo_typed'
3
+
4
+ class TestMongoOutputReplsetTyped < TestMongoOutputTyped
5
+ DEFAULT_CONFIG = %[
6
+ type mongo_replset_typed
7
+ database #{DB_NAME}
8
+ collection #{COLLECTION_NAME}
9
+ nodes localhost
10
+ ]
11
+ end
@@ -0,0 +1,64 @@
1
+ require 'helper'
2
+
3
+ class TestMongoOutputTyped < Test::Unit::TestCase
4
+
5
+ DB_NAME = '__fluent_test'
6
+ COLLECTION_NAME = 'test'
7
+ DEFAULT_CONFIG = %[
8
+ type mongo_typed
9
+ database #{DB_NAME}
10
+ collection #{COLLECTION_NAME}
11
+ ]
12
+
13
+ def setup
14
+ Fluent::Test.setup
15
+ @db = connect_db
16
+ end
17
+
18
+ def teardown
19
+ @db.collection(COLLECTION_NAME).drop
20
+ Mongo::Connection.new('localhost').drop_database(DB_NAME)
21
+ end
22
+
23
+ def connect_db
24
+ Mongo::Connection.new('localhost').db(DB_NAME)
25
+ end
26
+
27
+ def create_driver(conf = DEFAULT_CONFIG)
28
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::MongoOutputTyped).configure(conf)
29
+ end
30
+
31
+ def test_configure
32
+ time_format = "%d/%b/%Y:%H:%M:%S %z"
33
+ d = create_driver(DEFAULT_CONFIG + %[
34
+ item_types test1:integer,test2:string,test3:time,test4:bool
35
+ time_format #{time_format}
36
+ ]).instance
37
+
38
+ assert_equal('integer', d.item_types['test1'])
39
+ assert_equal('string', d.item_types['test2'])
40
+ assert_equal('time', d.item_types['test3'])
41
+ assert_equal('bool', d.item_types['test4'])
42
+
43
+ assert_equal(time_format, d.time_format)
44
+ end
45
+
46
+ def test_write
47
+ d = create_driver(DEFAULT_CONFIG + %[
48
+ item_types i:integer,s:string,t:time,b:bool,a:array
49
+ time_format %Y-%m-%d %H:%M:%S %z
50
+ ])
51
+ time = Time.parse('2013-02-12 22:01:15 UTC').to_i
52
+ t = '2013-02-12 22:04:14 UTC'
53
+ record = {'i' => '1', 's' => 'foo', 't' => t, 'b' => 'true', 'a' => 'a, b, c', 'o' => 'other'}
54
+ d.emit(record, time)
55
+ d.run
56
+ doc = @db.collection(COLLECTION_NAME).find_one()
57
+ assert_equal(1, doc['i'])
58
+ assert_equal('foo', doc['s'])
59
+ assert_equal(Time.gm(2013, 2, 12, 22, 4, 14), doc['t'])
60
+ assert_equal(true, doc['b'])
61
+ assert_equal(['a', 'b', 'c'], doc['a'])
62
+ assert_equal('other', doc['o'])
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-mongo-typed
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-02-15 00:00:00 +09:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: fluent-plugin-mongo
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.6.13
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: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.8.4
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: fluent-plugin-mongo
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 0.6.13
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ description: Typed mongo output plugin
72
+ email: taro.toys@gmail.com
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files:
78
+ - LICENSE.txt
79
+ - README.rdoc
80
+ files:
81
+ - .document
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ - Rakefile
86
+ - VERSION
87
+ - fluent-plugin-mongo-typed.gemspec
88
+ - lib/fluent/mixin/mongo_typed_mixin.rb
89
+ - lib/fluent/plugin/out_mongo_replset_typed.rb
90
+ - lib/fluent/plugin/out_mongo_typed.rb
91
+ - test/helper.rb
92
+ - test/plugin/test_out_mongo_replset_typed.rb
93
+ - test/plugin/test_out_mongo_typed.rb
94
+ has_rdoc: true
95
+ homepage: http://github.com/tarom/fluent-plugin-mongo-typed
96
+ licenses:
97
+ - MIT
98
+ post_install_message:
99
+ rdoc_options: []
100
+
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 2373908222451003347
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.6.0
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Typed mongo output plugin
125
+ test_files: []
126
+