fluent-plugin-pghstore 0.1.1 → 0.1.2
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/fluent-plugin-pghstore.gemspec +1 -1
- data/lib/fluent/plugin/out_pghstore.rb +27 -12
- metadata +2 -2
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-pghstore"
|
6
|
-
s.version = "0.1.
|
6
|
+
s.version = "0.1.2"
|
7
7
|
s.authors = ["WAKAYAMA Shirou"]
|
8
8
|
s.email = ["shirou.faw@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/shirou/fluent-plugin-pghstore"
|
@@ -24,6 +24,9 @@ class Fluent::PgHStoreOutput < Fluent::BufferedOutput
|
|
24
24
|
def shutdown
|
25
25
|
super
|
26
26
|
|
27
|
+
if @conn != nil and @conn.finished?() == false
|
28
|
+
conn.close()
|
29
|
+
end
|
27
30
|
end
|
28
31
|
|
29
32
|
def format(tag, time, record)
|
@@ -32,20 +35,18 @@ class Fluent::PgHStoreOutput < Fluent::BufferedOutput
|
|
32
35
|
|
33
36
|
def write(chunk)
|
34
37
|
conn = get_connection()
|
35
|
-
if conn == nil
|
36
|
-
return
|
37
|
-
end
|
38
|
+
return if conn == nil # TODO: chunk will be dropped. should retry?
|
38
39
|
|
39
40
|
chunk.msgpack_each {|(tag, time_str, record)|
|
40
41
|
sql = generate_sql(tag, time_str, record)
|
41
42
|
begin
|
42
43
|
conn.exec(sql)
|
43
44
|
rescue PGError => e
|
44
|
-
$log.error "PGError: " + e.message #
|
45
|
+
$log.error "PGError: " + e.message # dropped if error
|
45
46
|
end
|
46
|
-
|
47
47
|
}
|
48
|
-
|
48
|
+
|
49
|
+
conn.close()
|
49
50
|
end
|
50
51
|
|
51
52
|
private
|
@@ -68,17 +69,23 @@ SQL
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def get_connection()
|
72
|
+
if @conn != nil and @conn.finished?() == false
|
73
|
+
return @conn # connection is alived
|
74
|
+
end
|
75
|
+
|
71
76
|
begin
|
72
77
|
if @user
|
73
|
-
|
74
|
-
|
78
|
+
@conn = PG.connect(:dbname => @database, :host => @host, :port => @port,
|
79
|
+
:user => @user, :password => @password)
|
75
80
|
else
|
76
|
-
|
81
|
+
@conn = PG.connect(:dbname => @database, :host => @host, :port => @port)
|
77
82
|
end
|
78
83
|
rescue PGError => e
|
79
84
|
$log.error "Error: could not connect database:" + @database
|
80
85
|
return nil
|
81
86
|
end
|
87
|
+
return @conn
|
88
|
+
|
82
89
|
end
|
83
90
|
|
84
91
|
def table_exists?(table)
|
@@ -86,8 +93,9 @@ SQL
|
|
86
93
|
SELECT COUNT(*) FROM pg_tables WHERE tablename = '#{table}';
|
87
94
|
SQL
|
88
95
|
conn = get_connection()
|
96
|
+
raise "Could not connect the database at startup. abort." if conn == nil
|
89
97
|
res = conn.exec(sql)
|
90
|
-
|
98
|
+
conn.close
|
91
99
|
if res[0]["count"] == "1"
|
92
100
|
return true
|
93
101
|
else
|
@@ -107,10 +115,17 @@ SQL
|
|
107
115
|
sql += @table_option if @table_option
|
108
116
|
|
109
117
|
conn = get_connection()
|
110
|
-
conn
|
118
|
+
raise "Could not connect the database at create_table. abort." if conn == nil
|
119
|
+
|
120
|
+
begin
|
121
|
+
conn.exec(sql)
|
122
|
+
rescue PGError => e
|
123
|
+
$log.error "Error at create_table:" + e.message
|
124
|
+
$log.error "SQL:" + sql
|
125
|
+
end
|
111
126
|
conn.close
|
112
127
|
|
113
|
-
$log.warn "#{tablename}
|
128
|
+
$log.warn "table #{tablename} was not exist. created it."
|
114
129
|
end
|
115
130
|
|
116
131
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-pghstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|