fluent-plugin-mongo 0.7.11 → 0.7.12

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: db2edd199b7056e1a35d3b791ac6a393d7cba246
4
- data.tar.gz: 13d1f6785aa437885ffb5f38cbfb85aa58e222ba
3
+ metadata.gz: 306a5a645b491a0c8edb197064336662588aab89
4
+ data.tar.gz: a80cc84c0e68319cd68a891678a08d4def516d22
5
5
  SHA512:
6
- metadata.gz: cb7afa69474f59e1c47b173ef7d34bb0b9af922731887039b9180cec9ff5aca5d90294e02dde44b2bfdc5af83f7799e99a0e59ae364570338afa2bcf7e07167f
7
- data.tar.gz: 1c09da93b1179ee4dd55a5c7cefcf718e7a04309eab2049ad91bba3aec81570d2edd97cbf30962e9b066d0d58135350e9031730fc0f19fa50eae3a33a12cd1f7
6
+ metadata.gz: 15dc38b80bca19d1c7d52914d46f4d7688bdcfe2e5355ed0fdbe2b835d802bba2ed8436b9ed0b4565cdb51cc4cbbf9295daedff78a9fb115fe650da37d58e5e4
7
+ data.tar.gz: 23047da16921b3f30a3bc16e6f1881255010952f2542b921b92608aef6ecc7f73ff85c15ff2a27ab3bf05ad04b41f6cadec006eccb3436ee58c4e4c0057c0c4f
@@ -5,6 +5,8 @@ rvm:
5
5
  - 2.2
6
6
  - rbx
7
7
 
8
+ before_install:
9
+ - gem update bundler
8
10
  before_script:
9
11
  - git submodule update -i
10
12
 
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ Release 0.7.12 - 2016/02/09
2
+
3
+ * Support saving last_id to mongod instead of local file
4
+
5
+
1
6
  Release 0.7.11 - 2015/11/26
2
7
 
3
8
  * Add secret option to related parameters
@@ -138,9 +138,6 @@ Use _mongo_tail_ type in source.
138
138
 
139
139
  # Convert 'time'(BSON's time) to fluent time(Unix time).
140
140
  time_key time
141
-
142
- # You can store last ObjectId to tail over server's shutdown
143
- id_store_file /Users/repeatedly/devel/fluent-plugin-mongo/last_id
144
141
  </source>
145
142
 
146
143
  You can also use _url_ to specify the database to connect.
@@ -154,6 +151,24 @@ You can also use _url_ to specify the database to connect.
154
151
 
155
152
  This allows the plugin to read data from a replica set.
156
153
 
154
+ You can save last ObjectId to tail over server's shutdown to file.
155
+
156
+ <source>
157
+ ...
158
+
159
+ id_store_file /Users/repeatedly/devel/fluent-plugin-mongo/last_id
160
+ </source>
161
+
162
+ Or Mongo collection can be used to keep last ObjectID.
163
+
164
+ <source>
165
+ ...
166
+
167
+ id_store_collection last_id
168
+ </source>
169
+
170
+ Make sure the collection is capped. The plugin inserts records but does not remove at all.
171
+
157
172
  = NOTE
158
173
 
159
174
  == Broken data as a BSON
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.11
1
+ 0.7.12
@@ -19,6 +19,7 @@ module Fluent
19
19
 
20
20
  # To store last ObjectID
21
21
  config_param :id_store_file, :string, :default => nil
22
+ config_param :id_store_collection, :string, :default => nil
22
23
 
23
24
  # SSL connection
24
25
  config_param :ssl, :bool, :default => false
@@ -50,24 +51,22 @@ module Fluent
50
51
  raise ConfigError, "One of 'database' or 'url' must be specified"
51
52
  end
52
53
 
53
- @last_id = @id_store_file ? get_last_id : nil
54
+ @last_id = get_last_id
54
55
  @connection_options[:ssl] = @ssl
55
56
 
56
- $log.debug "Setup mongo_tail configuration: mode = #{@id_store_file ? 'persistent' : 'non-persistent'}"
57
+ $log.debug "Setup mongo_tail configuration: mode = #{@id_store_file || @id_store_collection ? 'persistent' : 'non-persistent'}, last_id = #{@last_id}"
57
58
  end
58
59
 
59
60
  def start
60
61
  super
61
- @file = get_id_store_file if @id_store_file
62
+ open_id_storage
62
63
  @client = get_capped_collection
63
64
  @thread = Thread.new(&method(:run))
64
65
  end
65
66
 
66
67
  def shutdown
67
- if @id_store_file
68
- save_last_id
69
- @file.close
70
- end
68
+ save_last_id(@last_id) unless @last_id
69
+ close_id_storage
71
70
 
72
71
  @stop = true
73
72
  @thread.join
@@ -157,7 +156,7 @@ module Fluent
157
156
  if id = doc.delete('_id')
158
157
  @last_id = id.to_s
159
158
  doc['_id_str'] = @last_id
160
- save_last_id if @id_store_file
159
+ save_last_id(@last_id)
161
160
  end
162
161
 
163
162
  # Should use MultiEventStream?
@@ -171,25 +170,51 @@ module Fluent
171
170
  conf
172
171
  end
173
172
 
174
- # following methods are used when id_store_file is true
175
-
176
- def get_id_store_file
177
- file = File.open(@id_store_file, 'w')
178
- file.sync
179
- file
173
+ # following methods are used to read/write last_id
174
+
175
+ def open_id_storage
176
+ if @id_store_file
177
+ @id_storage = File.open(@id_store_file, 'w')
178
+ @id_storege.sync
179
+ end
180
+
181
+ if @id_store_collection
182
+ @id_storage = get_database.collection(@id_store_collection)
183
+ end
184
+ end
185
+
186
+ def close_id_storage
187
+ if @id_storage.is_a?(File)
188
+ @id_storage.close
189
+ end
180
190
  end
181
191
 
182
192
  def get_last_id
183
- if File.exist?(@id_store_file)
184
- BSON::ObjectId(File.read(@id_store_file)).to_s rescue nil
185
- else
193
+ begin
194
+ if @id_store_file && File.exist?(@id_store_file)
195
+ return BSON::ObjectId(File.read(@id_store_file)).to_s
196
+ end
197
+
198
+ if @id_store_collection
199
+ collection = get_database.collection(@id_store_collection)
200
+ count = collection.find.count
201
+ doc = collection.find.skip(count - 1).limit(1).first
202
+ return doc && doc["last_id"]
203
+ end
204
+ rescue
186
205
  nil
187
206
  end
188
207
  end
189
208
 
190
- def save_last_id
191
- @file.pos = 0
192
- @file.write(@last_id)
209
+ def save_last_id(last_id)
210
+ if @id_storage.is_a?(File)
211
+ @id_storage.pos = 0
212
+ @id_storage.write(last_id)
213
+ end
214
+
215
+ if @id_storage.is_a?(Mongo::Collection)
216
+ @id_storage.insert("last_id" => last_id)
217
+ end
193
218
  end
194
219
  end
195
220
  end
@@ -13,6 +13,7 @@ class MongoTailInputTest < Test::Unit::TestCase
13
13
  tag_key tag
14
14
  time_key time
15
15
  id_store_file /tmp/fluent_mongo_last_id
16
+ id_store_collection test_last_id
16
17
  ]
17
18
 
18
19
  def create_driver(conf = CONFIG)
@@ -28,6 +29,7 @@ class MongoTailInputTest < Test::Unit::TestCase
28
29
  assert_equal('tag', d.instance.tag_key)
29
30
  assert_equal('time', d.instance.time_key)
30
31
  assert_equal('/tmp/fluent_mongo_last_id', d.instance.id_store_file)
32
+ assert_equal('test_last_id', d.instance.id_store_collection)
31
33
  end
32
34
 
33
35
  def test_url_configration
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.7.11
4
+ version: 0.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Nakagawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 2.4.5.1
152
+ rubygems_version: 2.2.2
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: MongoDB plugin for Fluentd