fluent-plugin-mongo 0.6.1 → 0.6.2
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.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.2
|
data/fluent-plugin-mongo.gemspec
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
$:.push File.expand_path('../lib', __FILE__)
|
3
3
|
|
4
|
-
# Fixup the YAML engine mismatch problem
|
5
|
-
YAML::ENGINE.yamler = "syck"
|
6
|
-
|
7
4
|
Gem::Specification.new do |gem|
|
8
5
|
gem.name = "fluent-plugin-mongo"
|
9
6
|
gem.description = "MongoDB plugin for Fluent event collector"
|
@@ -20,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
20
17
|
gem.require_paths = ['lib']
|
21
18
|
|
22
19
|
gem.add_dependency "fluentd", ">= 0.10.7"
|
23
|
-
gem.add_dependency "mongo", "
|
20
|
+
gem.add_dependency "mongo", [">= 1.5.2", "<= 1.5.2"]
|
24
21
|
gem.add_development_dependency "rake", ">= 0.9.2"
|
25
22
|
gem.add_development_dependency "simplecov", ">= 0.5.4"
|
26
23
|
gem.add_development_dependency "rr", ">= 1.0.0"
|
@@ -15,12 +15,13 @@ class MongoOutput < BufferedOutput
|
|
15
15
|
config_param :host, :string, :default => 'localhost'
|
16
16
|
config_param :port, :integer, :default => 27017
|
17
17
|
config_param :ignore_invalid_record, :bool, :default => false
|
18
|
+
config_param :safe, :bool, :default => true
|
18
19
|
|
19
20
|
# tag mapping mode
|
20
21
|
config_param :tag_mapped, :bool, :default => false
|
21
22
|
config_param :remove_tag_prefix, :string, :default => nil
|
22
23
|
|
23
|
-
attr_reader :
|
24
|
+
attr_reader :collection_options
|
24
25
|
|
25
26
|
def initialize
|
26
27
|
super
|
@@ -29,7 +30,8 @@ class MongoOutput < BufferedOutput
|
|
29
30
|
require 'msgpack'
|
30
31
|
|
31
32
|
@clients = {}
|
32
|
-
@
|
33
|
+
@connection_options = {}
|
34
|
+
@collection_options = {:capped => false}
|
33
35
|
end
|
34
36
|
|
35
37
|
def configure(conf)
|
@@ -45,9 +47,9 @@ class MongoOutput < BufferedOutput
|
|
45
47
|
# capped configuration
|
46
48
|
if conf.has_key?('capped')
|
47
49
|
raise ConfigError, "'capped_size' parameter is required on <store> of Mongo output" unless conf.has_key?('capped_size')
|
48
|
-
@
|
49
|
-
@
|
50
|
-
@
|
50
|
+
@collection_options[:capped] = true
|
51
|
+
@collection_options[:size] = Config.size_value(conf['capped_size'])
|
52
|
+
@collection_options[:max] = Config.size_value(conf['capped_max']) if conf.has_key?('capped_max')
|
51
53
|
end
|
52
54
|
|
53
55
|
if @buffer.respond_to?(:buffer_chunk_limit)
|
@@ -56,6 +58,8 @@ class MongoOutput < BufferedOutput
|
|
56
58
|
$log.warn "#{Fluent::VERSION} does not have :buffer_chunk_limit. Be careful when insert large documents to MongoDB"
|
57
59
|
end
|
58
60
|
|
61
|
+
@connection_options[:safe] = @safe
|
62
|
+
|
59
63
|
# MongoDB uses BSON's Date for time.
|
60
64
|
def @timef.format_nocache(time)
|
61
65
|
time
|
@@ -90,7 +94,7 @@ class MongoOutput < BufferedOutput
|
|
90
94
|
def write(chunk)
|
91
95
|
# TODO: See emit comment
|
92
96
|
collection_name = @tag_mapped ? chunk.key : @collection
|
93
|
-
operate(collection_name, collect_records(chunk))
|
97
|
+
operate(get_or_create_collection(collection_name), collect_records(chunk))
|
94
98
|
end
|
95
99
|
|
96
100
|
private
|
@@ -98,27 +102,34 @@ class MongoOutput < BufferedOutput
|
|
98
102
|
INSERT_ARGUMENT = {:collect_on_error => true}
|
99
103
|
BROKEN_DATA_KEY = '__broken_data'
|
100
104
|
|
101
|
-
def operate(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
def operate(collection, records)
|
106
|
+
begin
|
107
|
+
record_ids, error_records = collection.insert(records, INSERT_ARGUMENT)
|
108
|
+
if !@ignore_invalid_record and error_records.size > 0
|
109
|
+
operate_invalid_records(collection, error_records)
|
110
|
+
end
|
111
|
+
rescue Mongo::OperationFailure => e
|
112
|
+
# Probably, all records of _records_ are broken...
|
113
|
+
if e.error_code == 13066 # 13066 means "Message contains no documents"
|
114
|
+
operate_invalid_records(collection, records) unless @ignore_invalid_record
|
107
115
|
else
|
108
|
-
|
109
|
-
converted_records = error_records.map { |record|
|
110
|
-
new_record = {}
|
111
|
-
new_record[@tag_key] = record.delete(@tag_key) if @include_tag_key
|
112
|
-
new_record[@time_key] = record.delete(@time_key)
|
113
|
-
new_record[BROKEN_DATA_KEY] = Marshal.dump(record) # Should use BSON::ByteBuffer
|
114
|
-
new_record
|
115
|
-
}
|
116
|
-
collection.insert(converted_records)
|
116
|
+
raise e
|
117
117
|
end
|
118
118
|
end
|
119
119
|
records
|
120
120
|
end
|
121
121
|
|
122
|
+
def operate_invalid_records(collection, records)
|
123
|
+
converted_records = records.map { |record|
|
124
|
+
new_record = {}
|
125
|
+
new_record[@tag_key] = record.delete(@tag_key) if @include_tag_key
|
126
|
+
new_record[@time_key] = record.delete(@time_key)
|
127
|
+
new_record[BROKEN_DATA_KEY] = Marshal.dump(record) # Should use BSON::ByteBuffer
|
128
|
+
new_record
|
129
|
+
}
|
130
|
+
collection.insert(converted_records) # Should create another collection like name_broken?
|
131
|
+
end
|
132
|
+
|
122
133
|
def collect_records(chunk)
|
123
134
|
records = []
|
124
135
|
chunk.msgpack_each { |time, record|
|
@@ -145,19 +156,19 @@ class MongoOutput < BufferedOutput
|
|
145
156
|
@db ||= get_connection
|
146
157
|
if @db.collection_names.include?(collection_name)
|
147
158
|
collection = @db.collection(collection_name)
|
148
|
-
unless @
|
159
|
+
unless @collection_options[:capped] == collection.capped? # TODO: Verify capped configuration
|
149
160
|
# raise Exception if old collection does not match lastest configuration
|
150
161
|
raise ConfigError, "New configuration is different from existing collection"
|
151
162
|
end
|
152
163
|
else
|
153
|
-
collection = @db.create_collection(collection_name, @
|
164
|
+
collection = @db.create_collection(collection_name, @collection_options)
|
154
165
|
end
|
155
166
|
|
156
167
|
@clients[collection_name] = collection
|
157
168
|
end
|
158
169
|
|
159
170
|
def get_connection
|
160
|
-
Mongo::Connection.new(@host, @port).db(@database)
|
171
|
+
Mongo::Connection.new(@host, @port, @connection_options).db(@database)
|
161
172
|
end
|
162
173
|
|
163
174
|
# Following limits are heuristic. BSON is sometimes bigger than MessagePack and JSON.
|
@@ -17,18 +17,17 @@ class MongoOutputReplset < MongoOutput
|
|
17
17
|
super
|
18
18
|
|
19
19
|
@nodes = parse_nodes(conf['nodes'])
|
20
|
-
@rs_argument = {}
|
21
20
|
if name = conf['name']
|
22
|
-
@
|
21
|
+
@connection_options[:name] = conf['name']
|
23
22
|
end
|
24
23
|
if read = conf['read']
|
25
|
-
@
|
24
|
+
@connection_options[:read] = read.to_sym
|
26
25
|
end
|
27
26
|
if refresh_mode = conf['refresh_mode']
|
28
|
-
@
|
27
|
+
@connection_options[:refresh_mode] = refresh_mode.to_sym
|
29
28
|
end
|
30
29
|
if refresh_interval = conf['refresh_interval']
|
31
|
-
@
|
30
|
+
@connection_options[:refresh_interval] = refresh_interval
|
32
31
|
end
|
33
32
|
|
34
33
|
$log.debug "Setup replica set configuration: nodes = #{conf['nodes']}"
|
@@ -36,10 +35,9 @@ class MongoOutputReplset < MongoOutput
|
|
36
35
|
|
37
36
|
private
|
38
37
|
|
39
|
-
def operate(
|
40
|
-
collection = get_or_create_collection(collection_name)
|
38
|
+
def operate(collection, records)
|
41
39
|
rescue_connection_failure do
|
42
|
-
collection
|
40
|
+
super(collection, records)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
@@ -51,7 +49,7 @@ class MongoOutputReplset < MongoOutput
|
|
51
49
|
end
|
52
50
|
|
53
51
|
def get_connection
|
54
|
-
Mongo::ReplSetConnection.new(*@nodes, @
|
52
|
+
Mongo::ReplSetConnection.new(*@nodes, @connection_options).db(@database)
|
55
53
|
end
|
56
54
|
|
57
55
|
def rescue_connection_failure
|
data/test/plugin/out_mongo.rb
CHANGED
@@ -22,8 +22,12 @@ class MongoOutputTest < Test::Unit::TestCase
|
|
22
22
|
super
|
23
23
|
end
|
24
24
|
|
25
|
-
def operate(
|
26
|
-
[format_collection_name(
|
25
|
+
def operate(collection, records)
|
26
|
+
[format_collection_name(collection), records]
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_or_create_collection(collection_name)
|
30
|
+
collection_name
|
27
31
|
end
|
28
32
|
|
29
33
|
def mongod_version
|
@@ -49,7 +53,7 @@ class MongoOutputTest < Test::Unit::TestCase
|
|
49
53
|
assert_equal('test_collection', d.instance.collection)
|
50
54
|
assert_equal('fluenter', d.instance.host)
|
51
55
|
assert_equal(27018, d.instance.port)
|
52
|
-
assert_equal({:capped => true, :size => 100}, d.instance.
|
56
|
+
assert_equal({:capped => true, :size => 100}, d.instance.collection_options)
|
53
57
|
assert_equal(Fluent::MongoOutput::LIMIT_BEFORE_v1_8, d.instance.instance_variable_get(:@buffer).buffer_chunk_limit)
|
54
58
|
end
|
55
59
|
|
@@ -23,8 +23,12 @@ class MongoTagCollectionTest < Test::Unit::TestCase
|
|
23
23
|
super
|
24
24
|
end
|
25
25
|
|
26
|
-
def operate(
|
27
|
-
[format_collection_name(
|
26
|
+
def operate(collection, records)
|
27
|
+
[format_collection_name(collection), records]
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_or_create_collection(collection_name)
|
31
|
+
collection_name
|
28
32
|
end
|
29
33
|
}.configure(conf)
|
30
34
|
end
|
metadata
CHANGED
@@ -1,81 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mongo
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.6.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Masahiro Nakagawa
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: fluentd
|
17
|
-
requirement: &
|
16
|
+
requirement: &2152067980 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
22
21
|
version: 0.10.7
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
26
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *2152067980
|
25
|
+
- !ruby/object:Gem::Dependency
|
27
26
|
name: mongo
|
28
|
-
requirement: &
|
27
|
+
requirement: &2152067040 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.5.2
|
33
|
+
- - <=
|
34
|
+
- !ruby/object:Gem::Version
|
33
35
|
version: 1.5.2
|
34
36
|
type: :runtime
|
35
37
|
prerelease: false
|
36
|
-
version_requirements: *
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: *2152067040
|
39
|
+
- !ruby/object:Gem::Dependency
|
38
40
|
name: rake
|
39
|
-
requirement: &
|
41
|
+
requirement: &2152065820 !ruby/object:Gem::Requirement
|
40
42
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
44
46
|
version: 0.9.2
|
45
47
|
type: :development
|
46
48
|
prerelease: false
|
47
|
-
version_requirements: *
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: *2152065820
|
50
|
+
- !ruby/object:Gem::Dependency
|
49
51
|
name: simplecov
|
50
|
-
requirement: &
|
52
|
+
requirement: &2152064740 !ruby/object:Gem::Requirement
|
51
53
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
55
57
|
version: 0.5.4
|
56
58
|
type: :development
|
57
59
|
prerelease: false
|
58
|
-
version_requirements: *
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
+
version_requirements: *2152064740
|
61
|
+
- !ruby/object:Gem::Dependency
|
60
62
|
name: rr
|
61
|
-
requirement: &
|
63
|
+
requirement: &2152042360 !ruby/object:Gem::Requirement
|
62
64
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
66
68
|
version: 1.0.0
|
67
69
|
type: :development
|
68
70
|
prerelease: false
|
69
|
-
version_requirements: *
|
71
|
+
version_requirements: *2152042360
|
70
72
|
description: MongoDB plugin for Fluent event collector
|
71
73
|
email: repeatedly@gmail.com
|
72
|
-
executables:
|
74
|
+
executables:
|
73
75
|
- mongo-tail
|
74
76
|
extensions: []
|
75
|
-
|
76
77
|
extra_rdoc_files: []
|
77
|
-
|
78
|
-
files:
|
78
|
+
files:
|
79
79
|
- .gitignore
|
80
80
|
- .gitmodules
|
81
81
|
- .travis.yml
|
@@ -94,43 +94,40 @@ files:
|
|
94
94
|
- lib/fluent/plugin/out_mongo_tag_collection.rb
|
95
95
|
- test/plugin/in_mongo_tail.rb
|
96
96
|
- test/plugin/out_mongo.rb
|
97
|
-
- test/plugin/
|
97
|
+
- test/plugin/out_mongo_tag_mapped.rb
|
98
98
|
- test/test_helper.rb
|
99
99
|
homepage: https://github.com/fluent/fluent-plugin-mongo
|
100
100
|
licenses: []
|
101
|
-
|
102
101
|
post_install_message:
|
103
102
|
rdoc_options: []
|
104
|
-
|
105
|
-
require_paths:
|
103
|
+
require_paths:
|
106
104
|
- lib
|
107
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
106
|
none: false
|
109
|
-
requirements:
|
110
|
-
- -
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
|
113
|
-
segments:
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
segments:
|
114
112
|
- 0
|
115
|
-
|
116
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
hash: 2968858870877082029
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
115
|
none: false
|
118
|
-
requirements:
|
119
|
-
- -
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
|
122
|
-
segments:
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
segments:
|
123
121
|
- 0
|
124
|
-
|
122
|
+
hash: 2968858870877082029
|
125
123
|
requirements: []
|
126
|
-
|
127
124
|
rubyforge_project:
|
128
125
|
rubygems_version: 1.8.10
|
129
126
|
signing_key:
|
130
127
|
specification_version: 3
|
131
128
|
summary: MongoDB plugin for Fluent event collector
|
132
|
-
test_files:
|
129
|
+
test_files:
|
133
130
|
- test/plugin/in_mongo_tail.rb
|
134
131
|
- test/plugin/out_mongo.rb
|
135
|
-
- test/plugin/
|
132
|
+
- test/plugin/out_mongo_tag_mapped.rb
|
136
133
|
- test/test_helper.rb
|