fluent-plugin-mongo 0.8.0 → 0.8.1

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: db6ce0ecfb108767fa775ac7b26ec98f714bd128
4
- data.tar.gz: 23cb8dc9efb1b0d123f88ad431b3e08e708b4b76
3
+ metadata.gz: 2bf1813aa5586654b52813282aa11f01c7dba05f
4
+ data.tar.gz: 240c7befe5e653491b962753b250134ab48d2ee6
5
5
  SHA512:
6
- metadata.gz: c48b18b636b28e5aa32120b332f9354a7f435e6d8d5b4c97f98b01e2ca778fc8945393bd2584a7f1b41bb34309857630a40c57435109d2b3b259a70e8b9a9ef9
7
- data.tar.gz: 7a64cf7eff3494fdff2b8dea874839ca21921cc0a74da2645bcd36ac5eec5bc208de2ca1b09956b532166b6b735c5a2b7ede7506dfab5974f01781d6778120d9
6
+ metadata.gz: 9ab2a0129a3bd0b2fa56d520d58a67d1bf545981d3b68ed45b577453a9f29d942b65fb3a126b07e004619b239b643653866e7b31a47b0a8b88e7a625b7644721
7
+ data.tar.gz: 1e2387e3218da98c9afae121da65f1dd70fff92addef623f2c0d23d4d0054061f51c4c8635d8c1668638abdfad10f78932f49544fb02ccb27c34c97b3c66778e
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ Release 0.8.1 - 2017/03/23
2
+
3
+ * Add connection_string parameter for MongDB URI
4
+ * out_mongo_replset: Add nodes parameter
5
+
6
+
1
7
  Release 0.8.0 - 2017/02/10
2
8
 
3
9
  * Update mongo gem dependency to v2.0 or upper
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.1
@@ -20,8 +20,10 @@ module Fluent
20
20
  include SetTimeKeyMixin
21
21
  config_set_default :include_time_key, true
22
22
 
23
+ desc "MongoDB connection string"
24
+ config_param :connection_string, :default => nil
23
25
  desc "MongoDB database"
24
- config_param :database, :string
26
+ config_param :database, :string, :default => nil
25
27
  desc "MongoDB collection"
26
28
  config_param :collection, :string, default: 'untagged'
27
29
  desc "MongoDB host"
@@ -59,6 +61,7 @@ module Fluent
59
61
  require 'mongo'
60
62
  require 'msgpack'
61
63
 
64
+ @nodes = nil
62
65
  @client_options = {}
63
66
  @collection_options = {capped: false}
64
67
  end
@@ -90,6 +93,10 @@ module Fluent
90
93
 
91
94
  super
92
95
 
96
+ if @connection_string.nil? && @database.nil?
97
+ raise Fluent::ConfigError, "connection_string or database parameter is required"
98
+ end
99
+
93
100
  unless @ignore_invalid_record
94
101
  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"
95
102
  end
@@ -121,6 +128,7 @@ module Fluent
121
128
  @client_options[:ssl_verify] = @ssl_verify
122
129
  @client_options[:ssl_ca_cert] = @ssl_ca_cert
123
130
  end
131
+ @nodes = ["#{@host}:#{@port}"] if @nodes.nil?
124
132
 
125
133
  # MongoDB uses BSON's Date for time.
126
134
  def @timef.format_nocache(time)
@@ -163,10 +171,14 @@ module Fluent
163
171
  private
164
172
 
165
173
  def client
166
- @client_options[:database] = @database
167
- @client_options[:user] = @user if @user
168
- @client_options[:password] = @password if @password
169
- Mongo::Client.new(["#{@host}:#{@port}"], @client_options)
174
+ if @connection_string
175
+ Mongo::Client.new(@connection_string)
176
+ else
177
+ @client_options[:database] = @database
178
+ @client_options[:user] = @user if @user
179
+ @client_options[:password] = @password if @password
180
+ Mongo::Client.new(@nodes, @client_options)
181
+ end
170
182
  end
171
183
 
172
184
  def collect_records(chunk)
@@ -11,6 +11,8 @@ module Fluent
11
11
  config_set_default :include_tag_key, false
12
12
  config_set_default :include_time_key, true
13
13
 
14
+ desc "Nodes of replica set"
15
+ config_param :nodes, :array, value_type: :string, :default => nil
14
16
  desc "Replica set name"
15
17
  config_param :replica_set, :string
16
18
  desc "Read from specified role"
@@ -43,12 +43,12 @@ class MongoOutputTest < ::Test::Unit::TestCase
43
43
  end
44
44
 
45
45
  def create_driver(conf=default_config, tag='test')
46
- Fluent::Test::BufferedOutputTestDriver.new(Fluent::MongoOutput, tag).configure(conf)
46
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::MongoOutput, tag).configure(conf, true)
47
47
  end
48
48
 
49
49
  def test_configure
50
50
  d = create_driver(%[
51
- type mongo
51
+ @type mongo
52
52
  database fluent_test
53
53
  collection test_collection
54
54
 
@@ -62,6 +62,30 @@ class MongoOutputTest < ::Test::Unit::TestCase
62
62
  assert_equal(port, d.instance.port)
63
63
  assert_equal({capped: true, size: 100}, d.instance.collection_options)
64
64
  assert_equal({ssl: false, write: {j: false}}, d.instance.client_options)
65
+ assert_nil d.instance.connection_string
66
+ end
67
+
68
+ def test_configure_with_connection_string
69
+ d = create_driver(%[
70
+ @type mongo
71
+ connection_string mongodb://localhost/fluent_test
72
+ collection test_collection
73
+ capped
74
+ capped_size 100
75
+ ])
76
+ assert_equal('mongodb://localhost/fluent_test', d.instance.connection_string)
77
+ assert_nil d.instance.database
78
+ end
79
+
80
+ def test_configure_without_connection_string_or_database
81
+ assert_raise Fluent::ConfigError do
82
+ d = create_driver(%[
83
+ @type mongo
84
+ collection test_collection
85
+ capped
86
+ capped_size 100
87
+ ])
88
+ end
65
89
  end
66
90
 
67
91
  def test_configure_with_ssl
@@ -16,14 +16,18 @@ class MongoReplsetOutputTest < ::Test::Unit::TestCase
16
16
  'fluent_test'
17
17
  end
18
18
 
19
+ def nodes
20
+ ["localhost:#{port}"]
21
+ end
22
+
19
23
  def port
20
24
  27018
21
25
  end
22
26
 
23
27
  def default_config
24
28
  %[
25
- type mongo
26
- port 27018
29
+ @type mongo_replset
30
+ nodes localhost:27018
27
31
  database #{database_name}
28
32
  collection #{collection_name}
29
33
  include_time_key true
@@ -32,23 +36,38 @@ class MongoReplsetOutputTest < ::Test::Unit::TestCase
32
36
  end
33
37
 
34
38
  def create_driver(conf=default_config, tag='test')
35
- Fluent::Test::BufferedOutputTestDriver.new(Fluent::MongoOutputReplset, tag).configure(conf)
39
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::MongoOutputReplset, tag).configure(conf, true)
36
40
  end
37
41
 
38
42
  def test_configure
39
43
  d = create_driver(%[
40
- type mongo
44
+ @type mongo_replset
41
45
  port 27018
42
46
  database fluent_test
43
47
  collection test_collection
44
-
45
48
  replica_set rs0
46
49
  ])
47
50
 
48
51
  assert_equal('fluent_test', d.instance.database)
49
52
  assert_equal('test_collection', d.instance.collection)
50
53
  assert_equal('localhost', d.instance.host)
51
- assert_equal(port, d.instance.port)
54
+ assert_equal(27018, d.instance.port)
55
+ assert_equal({replica_set: 'rs0', :ssl=>false, :write=>{:j=>false}},
56
+ d.instance.client_options)
57
+ end
58
+
59
+ def test_configure_with_nodes
60
+ d = create_driver(%[
61
+ @type mongo_replset
62
+ nodes localhost:27018,localhost:27019
63
+ database fluent_test
64
+ collection test_collection
65
+ replica_set rs0
66
+ ])
67
+
68
+ assert_equal('fluent_test', d.instance.database)
69
+ assert_equal('test_collection', d.instance.collection)
70
+ assert_equal(['localhost:27018', 'localhost:27019'], d.instance.nodes)
52
71
  assert_equal({replica_set: 'rs0', :ssl=>false, :write=>{:j=>false}},
53
72
  d.instance.client_options)
54
73
  end
@@ -78,7 +97,7 @@ class MongoReplsetOutputTest < ::Test::Unit::TestCase
78
97
  def setup_mongod
79
98
  options = {}
80
99
  options[:database] = database_name
81
- @client = ::Mongo::Client.new(["localhost:#{port}"], options)
100
+ @client = ::Mongo::Client.new(nodes, options)
82
101
  end
83
102
 
84
103
  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: 0.8.0
4
+ version: 0.8.1
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