fluent-plugin-couch 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/fluent/plugin/out_couch.rb +43 -22
  3. metadata +6 -6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.4.0
@@ -2,23 +2,26 @@ module Fluent
2
2
  class CouchOutput < BufferedOutput
3
3
  include SetTagKeyMixin
4
4
  config_set_default :include_tag_key, false
5
-
5
+
6
6
  include SetTimeKeyMixin
7
7
  config_set_default :include_time_key, true
8
-
8
+
9
9
  Fluent::Plugin.register_output('couch', self)
10
-
10
+
11
11
  config_param :database, :string
12
-
12
+
13
13
  config_param :host, :string, :default => 'localhost'
14
14
  config_param :port, :string, :default => '5984'
15
15
  config_param :protocol, :string, :default => 'http'
16
-
16
+
17
17
  config_param :refresh_view_index , :string, :default => nil
18
18
 
19
19
  config_param :user, :string, :default => nil
20
20
  config_param :password, :string, :default => nil
21
-
21
+
22
+ config_param :update_docs, :bool, :default => false
23
+ config_param :doc_key_field, :string, :default => nil
24
+
22
25
  def initialize
23
26
  super
24
27
 
@@ -27,50 +30,68 @@ module Fluent
27
30
  require 'couchrest'
28
31
  Encoding.default_internal = 'ASCII-8BIT'
29
32
  end
30
-
33
+
31
34
  def configure(conf)
32
35
  super
33
36
  end
34
-
37
+
35
38
  def start
36
39
  super
37
- if @user && @password
38
- @db = CouchRest.database!("#{@protocol}://#{@user}:#{@password}@#{@host}:#{@port}/#{@database}")
39
- else
40
- @db = CouchRest.database!("#{@protocol}://#{@host}:#{@port}/#{@database}")
41
- end
40
+ account = "#{@user}:#{@password}@" if @user && @password
41
+ @db = CouchRest.database!("#{@protocol}://#{account}#{@host}:#{@port}/#{@database}")
42
42
  @views = []
43
43
  if @refresh_view_index
44
44
  begin
45
45
  @db.get("_design/#{@refresh_view_index}")['views'].each do |view_name,func|
46
46
  @views.push([@refresh_view_index,view_name])
47
47
  end
48
- rescue
48
+ rescue
49
49
  puts 'design document not found!'
50
50
  end
51
51
  end
52
52
  end
53
-
53
+
54
54
  def shutdown
55
55
  super
56
56
  end
57
-
57
+
58
58
  def format(tag, time, record)
59
59
  record.to_msgpack
60
60
  end
61
-
61
+
62
62
  def write(chunk)
63
63
  records = []
64
- chunk.msgpack_each {|record| records << record }
65
- @db.bulk_save(records)
66
- update_view_index()
64
+ chunk.msgpack_each {|record|
65
+ record['_id'] = record[@doc_key_field] unless @doc_key_field.nil?
66
+ records << record
67
+ }
68
+ unless @update_docs
69
+ @db.bulk_save(records)
70
+ else
71
+ update_docs(records)
72
+ end
73
+ update_view_index
67
74
  end
68
-
75
+
76
+ def update_docs(records)
77
+ if records.length > 0
78
+ records.each{|record|
79
+ doc = nil
80
+ begin
81
+ doc = @db.get(record['_id'])
82
+ rescue
83
+ end
84
+ record['_rev']=doc['_rev'] unless doc.nil?
85
+ puts record
86
+ @db.save_doc(record)
87
+ }
88
+ end
89
+ end
90
+
69
91
  def update_view_index()
70
92
  @views.each do |design,view|
71
93
  @db.view("#{design}/#{view}",{"limit"=>"0"})
72
94
  end
73
95
  end
74
-
75
96
  end
76
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-couch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-11 00:00:00.000000000Z
12
+ date: 2012-02-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
16
- requirement: &70198091437320 !ruby/object:Gem::Requirement
16
+ requirement: &70267577807740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.10.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70198091437320
24
+ version_requirements: *70267577807740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: couchrest
27
- requirement: &70198091436720 !ruby/object:Gem::Requirement
27
+ requirement: &70267577806360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.1.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70198091436720
35
+ version_requirements: *70267577806360
36
36
  description:
37
37
  email: ixixizko@gmail.com
38
38
  executables: []