fluent-plugin-pgjson 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/README.md +14 -4
- data/fluent-plugin-pgjson.gemspec +2 -1
- data/lib/fluent/plugin/out_pgjson.rb +9 -8
- data/test/plugin/test_out.rb +18 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e7286deb5f6a025925e67fff494cc474102a1ac
|
4
|
+
data.tar.gz: 19ce53e0b1bbddb272fda7a8c84d9154325c2d8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f552ed8b2c11ca76b23f83b37790a34f517669ff068f999fd0be65d48ce031bde5df21461e5715f52cab1f07b6ae523347efd0b52ff751cbf40039aa11dcf037
|
7
|
+
data.tar.gz: 3c8c692582082cdc8440c74428faa0eb6057c7fa8779937722cf980393398784b64d6dbf4db97ae01099437b760461a38cc2c77dae2214f386f26115bb4b38b6
|
data/README.md
CHANGED
@@ -27,6 +27,17 @@ CREATE TABLE fluentd (
|
|
27
27
|
,record Json
|
28
28
|
);
|
29
29
|
```
|
30
|
+
### JSONB?
|
31
|
+
|
32
|
+
Yes! Just define a record column as JSONB type.
|
33
|
+
|
34
|
+
```
|
35
|
+
CREATE TABLE fluentd (
|
36
|
+
tag Text
|
37
|
+
,time Timestamptz
|
38
|
+
,record Jsonb
|
39
|
+
);
|
40
|
+
```
|
30
41
|
|
31
42
|
## Configuration
|
32
43
|
|
@@ -65,7 +76,6 @@ CREATE TABLE fluentd (
|
|
65
76
|
|
66
77
|
## Copyright
|
67
78
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
</table>
|
79
|
+
* Copyright (c) 2014- OKUNO Akihiro
|
80
|
+
* License
|
81
|
+
* Apache License, version 2.0
|
@@ -3,12 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-pgjson"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.7"
|
7
7
|
s.authors = ["OKUNO Akihiro"]
|
8
8
|
s.email = ["choplin.choplin@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/choplin/fluent-plugin-pgjson"
|
10
10
|
s.summary = %q{}
|
11
11
|
s.description = %q{}
|
12
|
+
s.license = "Apache-2.0"
|
12
13
|
|
13
14
|
s.files = `git ls-files`.split("\n")
|
14
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -39,18 +39,20 @@ class PgJsonOutput < Fluent::BufferedOutput
|
|
39
39
|
|
40
40
|
def write(chunk)
|
41
41
|
init_connection
|
42
|
+
@conn.exec("COPY #{@table} (#{@tag_col}, #{@time_col}, #{@record_col}) FROM STDIN WITH DELIMITER E'\\x01'")
|
42
43
|
begin
|
43
|
-
@conn.exec("COPY #{@table} (#{@tag_col}, #{@time_col}, #{@record_col}) FROM STDIN WITH DELIMITER E'\\x01'")
|
44
44
|
chunk.msgpack_each do |tag, time, record|
|
45
45
|
@conn.put_copy_data "#{tag}\x01#{Time.at(time).to_s}\x01#{record_value(record)}\n"
|
46
46
|
end
|
47
|
+
rescue => err
|
48
|
+
errmsg = "%s while copy data: %s" % [ err.class.name, err.message ]
|
49
|
+
@conn.put_copy_end( errmsg )
|
50
|
+
@conn.get_result
|
51
|
+
raise
|
52
|
+
else
|
47
53
|
@conn.put_copy_end
|
48
|
-
|
49
|
-
if
|
50
|
-
@conn.close()
|
51
|
-
@conn = nil
|
52
|
-
end
|
53
|
-
raise "failed to send data to postgres: #$!"
|
54
|
+
res = @conn.get_result
|
55
|
+
raise res.result_error_message if res.result_status!=PG::PGRES_COMMAND_OK
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
@@ -61,7 +63,6 @@ class PgJsonOutput < Fluent::BufferedOutput
|
|
61
63
|
|
62
64
|
begin
|
63
65
|
@conn = PGconn.new(:dbname => @database, :host => @host, :port => @port, :sslmode => @sslmode, :user => @user, :password => @password)
|
64
|
-
@conn.setnonblocking(true)
|
65
66
|
rescue
|
66
67
|
if ! @conn.nil?
|
67
68
|
@conn.close()
|
data/test/plugin/test_out.rb
CHANGED
@@ -85,6 +85,24 @@ class PgJsonOutputTest < Test::Unit::TestCase
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
+
def test_invalid_json
|
89
|
+
with_connection do |conn|
|
90
|
+
tag = 'test'
|
91
|
+
time = Time.parse("2014-12-26 07:58:37 UTC")
|
92
|
+
|
93
|
+
d = create_driver(CONFIG, tag)
|
94
|
+
instance = d.instance
|
95
|
+
def instance.record_value(record)
|
96
|
+
'invalid json'
|
97
|
+
end
|
98
|
+
d.emit('', time.to_i)
|
99
|
+
|
100
|
+
assert_raise RuntimeError do
|
101
|
+
d.run
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
88
106
|
|
89
107
|
def ensure_connection
|
90
108
|
conn = nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-pgjson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OKUNO Akihiro
|
@@ -56,7 +56,8 @@ files:
|
|
56
56
|
- test/helper.rb
|
57
57
|
- test/plugin/test_out.rb
|
58
58
|
homepage: https://github.com/choplin/fluent-plugin-pgjson
|
59
|
-
licenses:
|
59
|
+
licenses:
|
60
|
+
- Apache-2.0
|
60
61
|
metadata: {}
|
61
62
|
post_install_message:
|
62
63
|
rdoc_options: []
|