fluent-plugin-mongo 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 130e2e8712112dcda7b7d44b19448f5cd2177ccc
4
- data.tar.gz: 79e4d7512049f24a830ccfef2b973084f9847b21
3
+ metadata.gz: 0374d7478e773ffdeba70eba9f7ba7df050ee22a
4
+ data.tar.gz: a6c4e10042582db77666352673e1a7ee7a812f74
5
5
  SHA512:
6
- metadata.gz: 635611797a2fae046e0961801e8a7f1fee7d436fcc2356406f5227b78916c6e7feb954b2d1d4d129e4573dffdf9c2627fbada20b35af35663e6ca33237cfe1ff
7
- data.tar.gz: 642e6babffd923a6426d0bc4bb85d64608b45e372f8bb3d30de755488737d8c0d4d25eb0266a66ad226c2b9c506115b24d2d07bd08f4032f9c5d49ef33f9e200
6
+ metadata.gz: 8d0877102caad677c07d60a9df53585c8ce1693f6de16fc96764305fa47caad39bdfbefd6d56d40a183bf76bebcd9e771595347870f1de1e8dcda1e138be02fc
7
+ data.tar.gz: 29061649d0edf590b18ad8192141e14980517dc07a80fa5544504a1bff02d64a33a9feeb435791797142f79d47fe9f28befa3dd2f06766bf8e70aaa93d228471
data/README.rdoc CHANGED
@@ -7,7 +7,7 @@ fluent-plugin-mongo provides input and output plugins for {Fluentd}[http://fluen
7
7
  |fluent-plugin-mongo| fluentd | ruby |
8
8
  |-------------------|------------|--------|
9
9
  | >= 1.0.0 | >= 0.14.12 | >= 2.1 |
10
- | < 1.0.0 | ~> 0.12.0 | >= 1.9 |
10
+ | < 1.0.0 | >= 0.12.0 | >= 1.9 |
11
11
 
12
12
  = Installation
13
13
 
@@ -82,45 +82,47 @@ Replica Set version of mongo.
82
82
 
83
83
  ==== Configuration
84
84
 
85
- Use _mongo_replset_ type in match.
85
+ ===== v0.8 or later
86
86
 
87
87
  <match mongo.**>
88
88
  type mongo_replset
89
89
  database fluent
90
90
  collection logs
91
91
 
92
- # each node separated by ','
93
- nodes localhost:27017,localhost:27018,localhost:27019
92
+ host localhost
93
+ port 27017
94
+
95
+ # The replica set name
96
+ replica_set myapp
94
97
 
95
98
  # num_retries is threshold at failover, default is 60.
96
99
  # If retry count reached this threshold, mongo plugin raises an exception.
97
100
  num_retries 30
98
101
 
99
- # following optional parameters passed to ReplSetConnection of mongo-ruby-driver.
100
- # See mongo-ruby-driver docs for more detail.
101
- #name replset_name
102
+ # following optional parameters passed to mongo-ruby-driver.
103
+ # See mongo-ruby-driver docs for more detail: https://docs.mongodb.com/ruby-driver/master/tutorials/ruby-driver-create-client/
104
+ # Specifies the read preference mode
102
105
  #read secondary
103
- #refresh_mode sync
104
- #refresh_interval 60
105
106
  </match>
106
107
 
107
- === mongo_backup
108
-
109
- Store Fluentd event to local capped collection for backup.
108
+ ===== v0.7 or ealier
110
109
 
111
- ==== Configuration
110
+ Use _mongo_replset_ type in match.
112
111
 
113
- Use _mongo_backup_ type in match. _mongo_backup_ alwalys use capped collection.
112
+ <match mongo.**>
113
+ type mongo_replset
114
+ database fluent
115
+ collection logs
114
116
 
115
- <match ...>
116
- type mongo_backup
117
- capped_size 100m
117
+ # each node separated by ','
118
+ nodes localhost:27017,localhost:27018,localhost:27019
118
119
 
119
- <store>
120
- type tcp
121
- host 192.168.0.13
122
- ...
123
- </store>
120
+ # following optional parameters passed to mongo-ruby-driver.
121
+ #name replset_name
122
+ #read secondary
123
+ #refresh_mode sync
124
+ #refresh_interval 60
125
+ #num_retries 60
124
126
  </match>
125
127
 
126
128
  == Input plugin
@@ -181,6 +183,21 @@ Make sure the collection is capped. The plugin inserts records but does not remo
181
183
 
182
184
  = NOTE
183
185
 
186
+ == replace_dot_in_key_with and replace_dollar_in_key_with
187
+
188
+ BSON records which include '.' or start with '$' are invalid and they will be stored as broken data to MongoDB. If you want to sanitize keys, you can use _replace_dot_in_key_with_ and _replace_dollar_in_key_with_.
189
+
190
+ <match forward.*>
191
+ ...
192
+ # replace '.' in keys with '__dot__'
193
+ replace_dot_in_key_with __dot__
194
+
195
+ # replace '$' in keys with '__dollar__'
196
+ # Note: This replaces '$' only on first character
197
+ replace_dollar_in_key_with __dollar__
198
+ ...
199
+ </match>
200
+
184
201
  == Broken data as a BSON
185
202
 
186
203
  NOTE: This feature will be removed since v0.8
@@ -237,21 +254,6 @@ If you want to exclude some fields from broken data marshaling, use _exclude_bro
237
254
  Specified value is a comma separated keys(e.g. key1,key2,key3).
238
255
  This parameter is useful for excluding shard keys in shard environment.
239
256
 
240
- === replace_dot_in_key_with and replace_dollar_in_key_with
241
-
242
- BSON records which include '.' or start with '$' are invalid and they will be stored as broken data to MongoDB. If you want to sanitize keys, you can use _replace_dot_in_key_with_ and _replace_dollar_in_key_with_.
243
-
244
- <match forward.*>
245
- ...
246
- # replace '.' in keys with '__dot__'
247
- replace_dot_in_key_with __dot__
248
-
249
- # replace '$' in keys with '__dollar__'
250
- # Note: This replaces '$' only on first character
251
- replace_dollar_in_key_with __dollar__
252
- ...
253
- </match>
254
-
255
257
  == Buffer size limitation
256
258
 
257
259
  Mongo plugin has the limitation of buffer size.
@@ -263,21 +265,6 @@ So, Mongo plugin resets _buffer_chunk_limit_ if configurated value is larger tha
263
265
  - Before v1.8, max of _buffer_chunk_limit_ is 2MB
264
266
  - After v1.8, max of _buffer_chunk_limit_ is 8MB
265
267
 
266
- == Disable collection check
267
-
268
- Mongo plugin checks a collection's configuration to prevent unexpected insertion to existing collection.
269
- In tag mapped mode, Mongo plugin accesses many collections. In this case, collection checking is not usable
270
- because current configuration format cannot write multiple values in one parameter.
271
- So, if you disable this checking, put ```disable_collection_check true``` in match.
272
-
273
- <match forward.*>
274
- ...
275
-
276
- disable_collection_check true
277
-
278
- ...
279
- </match>
280
-
281
268
  = Tool
282
269
 
283
270
  You can tail mongo capped collection.
@@ -296,13 +283,6 @@ You can use 'mongod' environment variable for specified mongod:
296
283
 
297
284
  Note that source code in test/tools are from mongo-ruby-driver.
298
285
 
299
- = TODO
300
-
301
- == More configuration
302
-
303
- - Multi process
304
- - etc
305
-
306
286
  = Copyright
307
287
 
308
288
  Copyright:: Copyright (c) 2011- Masahiro Nakagawa
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.rc1
1
+ 1.0.0.rc2
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency "fluentd", [">= 0.10.58", "< 2"]
20
+ gem.add_dependency "fluentd", [">= 0.14.12", "< 2"]
21
21
  gem.add_runtime_dependency "mongo", "~> 2.2.0"
22
22
  gem.add_development_dependency "rake", ">= 0.9.2"
23
23
  gem.add_development_dependency "simplecov", ">= 0.5.4"
@@ -19,8 +19,10 @@ module Fluent::Plugin
19
19
  config_set_default :include_tag_key, false
20
20
  config_set_default :include_time_key, true
21
21
 
22
+ desc "MongoDB connection string"
23
+ config_param :connection_string, :default => nil
22
24
  desc "MongoDB database"
23
- config_param :database, :string
25
+ config_param :database, :string, :default => nil
24
26
  desc "MongoDB collection"
25
27
  config_param :collection, :string, default: 'untagged'
26
28
  desc "MongoDB host"
@@ -38,9 +40,11 @@ module Fluent::Plugin
38
40
 
39
41
  # tag mapping mode
40
42
  desc "Use tag_mapped mode"
41
- config_param :tag_mapped, :bool, default: false
43
+ config_param :tag_mapped, :bool, default: false,
44
+ deprecated: "use '${tag}' placeholder in collection parameter."
42
45
  desc "Remove tag prefix"
43
- config_param :remove_tag_prefix, :string, default: nil
46
+ config_param :remove_tag_prefix, :string, default: nil,
47
+ deprecated: "use @label instead for event routing."
44
48
 
45
49
  # SSL connection
46
50
  config_param :ssl, :bool, default: false
@@ -60,6 +64,7 @@ module Fluent::Plugin
60
64
  def initialize
61
65
  super
62
66
 
67
+ @nodes = nil
63
68
  @client_options = {}
64
69
  @collection_options = {capped: false}
65
70
  end
@@ -92,6 +97,10 @@ module Fluent::Plugin
92
97
 
93
98
  super
94
99
 
100
+ if @connection_string.nil? && @database.nil?
101
+ raise Fluent::ConfigError, "connection_string or database parameter is required"
102
+ end
103
+
95
104
  unless @ignore_invalid_record
96
105
  log.warn "Since v0.8, invalid record detection will be removed because mongo driver v2.x and API spec don't provide it. You may lose invalid records, so you should not send such records to mongo plugin"
97
106
  end
@@ -124,6 +133,7 @@ module Fluent::Plugin
124
133
  @client_options[:ssl_verify] = @ssl_verify
125
134
  @client_options[:ssl_ca_cert] = @ssl_ca_cert
126
135
  end
136
+ @nodes = ["#{@host}:#{@port}"] if @nodes.nil?
127
137
 
128
138
  configure_logger(@mongo_log_level)
129
139
 
@@ -169,10 +179,14 @@ module Fluent::Plugin
169
179
  private
170
180
 
171
181
  def client
172
- @client_options[:database] = @database
173
- @client_options[:user] = @user if @user
174
- @client_options[:password] = @password if @password
175
- Mongo::Client.new(["#{@host}:#{@port}"], @client_options)
182
+ if @connection_string
183
+ Mongo::Client.new(@connection_string)
184
+ else
185
+ @client_options[:database] = @database
186
+ @client_options[:user] = @user if @user
187
+ @client_options[:password] = @password if @password
188
+ Mongo::Client.new(@nodes, @client_options)
189
+ end
176
190
  end
177
191
 
178
192
  def collect_records(chunk)
@@ -7,6 +7,8 @@ module Fluent::Plugin
7
7
  config_set_default :include_tag_key, false
8
8
  config_set_default :include_time_key, true
9
9
 
10
+ desc "Nodes of replica set"
11
+ config_param :nodes, :array, value_type: :string, :default => nil
10
12
  desc "Replica set name"
11
13
  config_param :replica_set, :string
12
14
  desc "Read from specified role"
@@ -52,7 +52,7 @@ class MongoOutputTest < ::Test::Unit::TestCase
52
52
 
53
53
  def test_configure
54
54
  d = create_driver(%[
55
- type mongo
55
+ @type mongo
56
56
  database fluent_test
57
57
  collection test_collection
58
58
 
@@ -66,6 +66,30 @@ class MongoOutputTest < ::Test::Unit::TestCase
66
66
  assert_equal(port, d.instance.port)
67
67
  assert_equal({capped: true, size: 100}, d.instance.collection_options)
68
68
  assert_equal({ssl: false, write: {j: false}}, d.instance.client_options)
69
+ assert_nil d.instance.connection_string
70
+ end
71
+
72
+ def test_configure_with_connection_string
73
+ d = create_driver(%[
74
+ @type mongo
75
+ connection_string mongodb://localhost/fluent_test
76
+ collection test_collection
77
+ capped
78
+ capped_size 100
79
+ ])
80
+ assert_equal('mongodb://localhost/fluent_test', d.instance.connection_string)
81
+ assert_nil d.instance.database
82
+ end
83
+
84
+ def test_configure_without_connection_string_or_database
85
+ assert_raise Fluent::ConfigError do
86
+ d = create_driver(%[
87
+ @type mongo
88
+ collection test_collection
89
+ capped
90
+ capped_size 100
91
+ ])
92
+ end
69
93
  end
70
94
 
71
95
  def test_configure_with_ssl
@@ -184,11 +208,11 @@ class MongoOutputTest < ::Test::Unit::TestCase
184
208
 
185
209
  def test_write_with_collection_placeholder
186
210
  d = create_driver(%[
187
- type mongo
188
- database #{database_name}
189
- collection ${tag}
190
- include_time_key true
191
- ])
211
+ @type mongo
212
+ database #{database_name}
213
+ collection ${tag}
214
+ include_time_key true
215
+ ])
192
216
  d.run(default_tag: @tag) do
193
217
  emit_documents(d)
194
218
  end
@@ -21,14 +21,18 @@ class MongoReplsetOutputTest < ::Test::Unit::TestCase
21
21
  'fluent_test'
22
22
  end
23
23
 
24
+ def nodes
25
+ ["localhost:#{port}"]
26
+ end
27
+
24
28
  def port
25
29
  27018
26
30
  end
27
31
 
28
32
  def default_config
29
33
  %[
30
- type mongo
31
- port 27018
34
+ @type mongo_replset
35
+ nodes localhost:27018
32
36
  database #{database_name}
33
37
  collection #{collection_name}
34
38
  include_time_key true
@@ -42,18 +46,33 @@ class MongoReplsetOutputTest < ::Test::Unit::TestCase
42
46
 
43
47
  def test_configure
44
48
  d = create_driver(%[
45
- type mongo
49
+ @type mongo_replset
46
50
  port 27018
47
51
  database fluent_test
48
52
  collection test_collection
49
-
50
53
  replica_set rs0
51
54
  ])
52
55
 
53
56
  assert_equal('fluent_test', d.instance.database)
54
57
  assert_equal('test_collection', d.instance.collection)
55
58
  assert_equal('localhost', d.instance.host)
56
- assert_equal(port, d.instance.port)
59
+ assert_equal(27018, d.instance.port)
60
+ assert_equal({replica_set: 'rs0', :ssl=>false, :write=>{:j=>false}},
61
+ d.instance.client_options)
62
+ end
63
+
64
+ def test_configure_with_nodes
65
+ d = create_driver(%[
66
+ @type mongo_replset
67
+ nodes localhost:27018,localhost:27019
68
+ database fluent_test
69
+ collection test_collection
70
+ replica_set rs0
71
+ ])
72
+
73
+ assert_equal('fluent_test', d.instance.database)
74
+ assert_equal('test_collection', d.instance.collection)
75
+ assert_equal(['localhost:27018', 'localhost:27019'], d.instance.nodes)
57
76
  assert_equal({replica_set: 'rs0', :ssl=>false, :write=>{:j=>false}},
58
77
  d.instance.client_options)
59
78
  end
@@ -83,7 +102,7 @@ class MongoReplsetOutputTest < ::Test::Unit::TestCase
83
102
  def setup_mongod
84
103
  options = {}
85
104
  options[:database] = database_name
86
- @client = ::Mongo::Client.new(["localhost:#{port}"], options)
105
+ @client = ::Mongo::Client.new(nodes, options)
87
106
  end
88
107
 
89
108
  def teardown_mongod
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Nakagawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-09 00:00:00.000000000 Z
11
+ date: 2017-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.58
19
+ version: 0.14.12
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.10.58
29
+ version: 0.14.12
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'