fluent-plugin-mongo 1.4.0 → 1.4.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
  SHA256:
3
- metadata.gz: 709f3068ce7f97bcad4737b3c7a9db60bdea998b184949afa7f3fa1794831474
4
- data.tar.gz: 53d8b989b2d30d8b0df0e37701af671713460dd46fe920435016ececcaef6c36
3
+ metadata.gz: baad354dcd89624e9e6ed224718d569de6a37329e7a0339d2b8f41011ba0b970
4
+ data.tar.gz: 15c2c50509c70a325fe6c053a09062e5701e61003e550d316ffa491e9cc99b75
5
5
  SHA512:
6
- metadata.gz: 6ce121ba68754c2d6687a7d1ed8cedf8c9fe94652f85476b03aacddf92bede132aa7f45444c8cb4153ff5509143bf00688cffc5c872c15e76c754e0cd6f5ff8f
7
- data.tar.gz: 4391ce8e22ca8173f38630a6f22024acdccae01d48a3bf5c86f255bbdbe057cdbbb9039b9f55b209bfaf377188124a5b1dd83fcaf8b58db80785e16348e8caa0
6
+ metadata.gz: 59aeae091430fae5bb089245f24d85e8e204a11f7d886f0b53b7cde6af054c0e5b9c2fc94f17f2b0dfdc7fb79c562be7112adfafae71583e8fcf8b18aa8766ab
7
+ data.tar.gz: 242c5d3d7a58f0be87514909749b066942118d90c24e9990f719eff5956919556a86ae24c427c8d21e55b70b39d03b8796d10c4493d00d7c41a7be635009f738
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Release 1.4.1 - 2020/08/21
2
+
3
+ * out_mongo: Add expire_after parameter
4
+
1
5
  Release 1.4.0 - 2020/04/28
2
6
 
3
7
  * out_mongo: Add date_keys parameter to support MongoDB Date object in record fields.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.4.1
@@ -49,6 +49,9 @@ module Fluent::Plugin
49
49
  desc "Remove tag prefix"
50
50
  config_param :remove_tag_prefix, :string, default: nil,
51
51
  deprecated: "use @label instead for event routing."
52
+ # expire indexes
53
+ desc "Specify expire after seconds"
54
+ config_param :expire_after, :time, default: 0
52
55
 
53
56
  # SSL connection
54
57
  config_param :ssl, :bool, default: false
@@ -121,10 +124,6 @@ module Fluent::Plugin
121
124
  raise Fluent::ConfigError, "connection_string or database parameter is required"
122
125
  end
123
126
 
124
- unless @ignore_invalid_record
125
- 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"
126
- end
127
-
128
127
  if conf.has_key?('tag_mapped')
129
128
  log.warn "'tag_mapped' feature is replaced with built-in config placeholder. Please consider to use 'collection ${tag}'."
130
129
  @collection = '${tag}'
@@ -274,6 +273,13 @@ module Fluent::Plugin
274
273
  unless collection_exists?(name)
275
274
  log.trace "Create collection #{name} with options #{options}"
276
275
  @client[name, options].create
276
+ if @expire_after > 0 && @inject_config
277
+ log.trace "Create expiring index with key: \"#{@inject_config.time_key}\" and seconds: \"#{@expire_after}\""
278
+ @client[name].indexes.create_one(
279
+ {"#{@inject_config.time_key}": 1},
280
+ expire_after: @expire_after
281
+ )
282
+ end
277
283
  end
278
284
  @collections[name] = true
279
285
  @client[name]
@@ -114,7 +114,7 @@ class MongoTailInputTest < Test::Unit::TestCase
114
114
  time_key time
115
115
  ])
116
116
  d.run(expect_records: 1, timeout: 5) do
117
- @client[collection_name].insert_one({message: "test", tag: "user.defined", time: Fluent::Engine.now})
117
+ @client[collection_name].insert_one({message: "test", tag: "user.defined", time: Time.at(Fluent::Engine.now)})
118
118
  end
119
119
  events = d.events
120
120
  assert_equal "user.defined", events[0][0]
@@ -180,6 +180,10 @@ class MongoOutputTest < ::Test::Unit::TestCase
180
180
  @client[collection].find.to_a.map {|e| e.delete('_id'); e}
181
181
  end
182
182
 
183
+ def get_indexes(collection = collection_name)
184
+ @client[collection].indexes
185
+ end
186
+
183
187
  def emit_documents(d)
184
188
  time = event_time("2011-01-02 13:14:15 UTC")
185
189
  d.feed(time, {'a' => 1})
@@ -220,6 +224,31 @@ class MongoOutputTest < ::Test::Unit::TestCase
220
224
  assert_equal(expected, actual_documents)
221
225
  end
222
226
 
227
+ def test_write_with_expire_index
228
+ d = create_driver(%[
229
+ @type mongo
230
+ connection_string mongodb://localhost:#{port}/#{database_name}
231
+ collection #{collection_name}
232
+ capped
233
+ capped_size 100
234
+ expire_after 120
235
+ ])
236
+ assert_equal("mongodb://localhost:#{port}/#{database_name}", d.instance.connection_string)
237
+ assert_nil d.instance.database
238
+ d.run(default_tag: 'test') do
239
+ emit_documents(d)
240
+ end
241
+ actual_documents = get_documents
242
+ time = event_time("2011-01-02 13:14:15 UTC")
243
+ expected = [{'a' => 1, d.instance.inject_config.time_key => Time.at(time).localtime},
244
+ {'a' => 2, d.instance.inject_config.time_key => Time.at(time).localtime}]
245
+ assert_equal(expected, actual_documents)
246
+
247
+ indexes = get_indexes()
248
+ expire_after_hash = indexes.map {|e| e.select{|k, v| k == "expireAfterSeconds"} }.reject{|e| e.empty?}.first
249
+ assert_equal({"expireAfterSeconds"=>120.0}, expire_after_hash)
250
+ end
251
+
223
252
  class WriteWithCollectionPlaceholder < self
224
253
  def setup
225
254
  @tag = 'custom'
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.4.0
4
+ version: 1.4.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: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd