fluent-plugin-mongo 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -4,7 +4,11 @@
4
4
 
5
5
  === MongoOutput
6
6
 
7
- Output to MongoDB database.
7
+ Store fluent-event as MongoDB Document to MongoDB database.
8
+
9
+ === MongoBackup
10
+
11
+ Store fluent-event to capped collection for backup.
8
12
 
9
13
  == Configuratin
10
14
 
@@ -19,21 +23,25 @@ Output to MongoDB database.
19
23
  host fluenter
20
24
  port 10000
21
25
 
26
+ # You can use 'capped' if you want to use capped collection
27
+ capped
28
+ capped_size 100m
29
+
22
30
  # Other buffer configurations here
23
31
  </match>
24
32
 
25
33
  === Backup to local capped collection
26
34
 
27
- Use <store> section.
35
+ Use mongo_backup type. mongo_backup alwalys use capped collection.
28
36
 
29
- <match mongo.**>
30
- type mongo
31
- database fluent
32
- collection test
37
+ <match ...>
38
+ type mongo_backup
39
+ capped_size 100m
33
40
 
34
41
  <store>
35
- size 100000
36
- max 1000
42
+ type tcp
43
+ host 192.168.0.13
44
+ ...
37
45
  </store>
38
46
  </match>
39
47
 
@@ -41,8 +49,8 @@ Use <store> section.
41
49
 
42
50
  === More configuration
43
51
 
44
- - Create Capped Collection
45
52
  - Create Index
53
+ - Select insert or update
46
54
  - etc
47
55
 
48
56
  === Infer collection name
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -8,40 +8,38 @@ class MongoOutput < BufferedOutput
8
8
  super
9
9
  require 'mongo'
10
10
  require 'msgpack'
11
+
12
+ # Sub-class can overwrite following parameters
13
+ @database_name = nil
14
+ @collection_name = nil
11
15
  end
12
16
 
13
17
  def configure(conf)
14
18
  super
15
19
 
16
- raise ConfigError, "'database' parameter is required on Mongo output" unless @database_name = conf['database']
17
- raise ConfigError, "'collection' parameter is required on Mongo output" unless @collection_name = conf['collection']
20
+ @database_name = conf['database'] if conf.has_key?('database')
21
+ @collection_name = conf['collection'] if conf.has_key?('collection')
22
+ raise ConfigError, "'database' and 'collection' parameter is required on mongo output" if @database_name.nil? || @collection_name.nil?
18
23
  @host, @port = host_and_port(conf)
19
24
 
20
25
  # capped configuration
21
- if capped_conf = conf.elements.first
22
- raise ConfigError, "'size' parameter is required on <store> of Mongo output" unless capped_conf.has_key?('size')
23
- @capped_argument = {:capped => true}
24
- @capped_argument[:size] = Integer(capped_conf['size'])
25
- @capped_argument[:max] = Integer(capped_conf['max']) if capped_conf.has_key?('max')
26
-
27
- @capped_database_name = capped_conf['database'] || 'fluent'
28
- @capped_collection_name = capped_conf['collection'] || '__backup'
29
- @capped_host, @capped_port = host_and_port(capped_conf)
26
+ @argument = {:capped => false}
27
+ if conf['capped']
28
+ raise ConfigError, "'capped_size' parameter is required on <store> of Mongo output" unless conf.has_key?('capped_size')
29
+ @argument[:capped] = true
30
+ @argument[:size] = Config.size_value(conf['capped_size'])
31
+ @argument[:max] = Config.size_value(conf['capped_max']) if conf.has_key?('capped_max')
30
32
  end
31
-
32
- @backuped = false
33
33
  end
34
34
 
35
35
  def start
36
36
  super
37
- @collection = Mongo::Connection.new(@host, @port).db(@database_name).collection(@collection_name)
38
- @capped = capped_collection unless @capped_argument.nil?
37
+ @collection = get_or_create_collection #Mongo::Connection.new(@host, @port).db(@database_name).collection(@collection_name)
39
38
  end
40
39
 
41
40
  def shutdown
42
41
  # Mongo::Connection checks alive or closed myself
43
42
  @collection.db.connection.close
44
- @capped.db.connection.close unless @capped.nil?
45
43
  super
46
44
  end
47
45
 
@@ -59,13 +57,7 @@ class MongoOutput < BufferedOutput
59
57
  end
60
58
  }
61
59
 
62
- unless @backuped or @capped.nil?
63
- @capped.insert(records)
64
- @backuped = true
65
- end
66
-
67
60
  @collection.insert(records)
68
- @backuped = false
69
61
  end
70
62
 
71
63
  private
@@ -76,14 +68,17 @@ class MongoOutput < BufferedOutput
76
68
  [host, Integer(port)]
77
69
  end
78
70
 
79
- def capped_collection
80
- db = Mongo::Connection.new(@capped_host, @capped_port).db(@capped_database_name)
81
- if db.collection_names.include?(@capped_collection_name)
82
- # TODO: Verify capped configuraton
83
- db.collection(@capped_collection_name)
84
- else
85
- db.create_collection(@capped_collection_name, @capped_argument)
71
+ def get_or_create_collection
72
+ db = Mongo::Connection.new(@host, @port).db(@database_name)
73
+ if db.collection_names.include?(@collection_name)
74
+ collection = db.collection(@collection_name)
75
+ return collection if @argument[:capped] == collection.capped? # TODO: Verify capped configuration
76
+
77
+ # raise Exception if old collection does not match lastest configuration
78
+ raise ConfigError, "New configuration is different from existing collection"
86
79
  end
80
+
81
+ db.create_collection(@collection_name, @argument)
87
82
  end
88
83
  end
89
84
 
@@ -0,0 +1,31 @@
1
+ require 'fluent/plugin/out_copy'
2
+ require 'fluent/plugin/out_mongo'
3
+
4
+
5
+ module Fluent
6
+
7
+
8
+ class MongoBackupOutput < CopyOutput
9
+ Fluent::Plugin.register_output('mongo_backup', self)
10
+
11
+ class MongoOutputForBackup < MongoOutput
12
+ def initialize
13
+ super
14
+
15
+ # default parameters
16
+ @database_name = 'fluent'
17
+ @collection_name = 'out_mongo_backup'
18
+ end
19
+ end
20
+
21
+ def configure(conf)
22
+ super
23
+
24
+ backup = MongoOutputForBackup.new
25
+ backup.configure(conf.merge({'capped' => true}))
26
+ @outputs.unshift(backup)
27
+ end
28
+ end
29
+
30
+
31
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Masahiro Nakagawa
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-10-02 00:00:00 +09:00
17
+ date: 2011-10-03 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -60,6 +60,7 @@ files:
60
60
  - Rakefile
61
61
  - VERSION
62
62
  - lib/fluent/plugin/out_mongo.rb
63
+ - lib/fluent/plugin/out_mongo_backup.rb
63
64
  - README.rdoc
64
65
  has_rdoc: true
65
66
  homepage: http://github.com/fluent