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 +4 -4
- data/.travis.yml +2 -0
- data/ChangeLog +5 -0
- data/README.rdoc +18 -3
- data/VERSION +1 -1
- data/lib/fluent/plugin/in_mongo_tail.rb +45 -20
- data/test/plugin/in_mongo_tail.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 306a5a645b491a0c8edb197064336662588aab89
|
4
|
+
data.tar.gz: a80cc84c0e68319cd68a891678a08d4def516d22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15dc38b80bca19d1c7d52914d46f4d7688bdcfe2e5355ed0fdbe2b835d802bba2ed8436b9ed0b4565cdb51cc4cbbf9295daedff78a9fb115fe650da37d58e5e4
|
7
|
+
data.tar.gz: 23047da16921b3f30a3bc16e6f1881255010952f2542b921b92608aef6ecc7f73ff85c15ff2a27ab3bf05ad04b41f6cadec006eccb3436ee58c4e4c0057c0c4f
|
data/.travis.yml
CHANGED
data/ChangeLog
CHANGED
data/README.rdoc
CHANGED
@@ -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.
|
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 =
|
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
|
-
|
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
|
-
|
68
|
-
|
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
|
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
|
175
|
-
|
176
|
-
def
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
184
|
-
|
185
|
-
|
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
|
-
@
|
192
|
-
|
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.
|
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:
|
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.
|
152
|
+
rubygems_version: 2.2.2
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: MongoDB plugin for Fluentd
|