fluent-plugin-pgjson 0.0.6 → 0.0.7

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
  SHA1:
3
- metadata.gz: 4dfa8ba1bbd21e1ffa84476064f2cb0eced7e5c8
4
- data.tar.gz: 7522f3e3b4639c1022f58f41ee9b568fea58827a
3
+ metadata.gz: 0e7286deb5f6a025925e67fff494cc474102a1ac
4
+ data.tar.gz: 19ce53e0b1bbddb272fda7a8c84d9154325c2d8f
5
5
  SHA512:
6
- metadata.gz: d3ff0bb506bac3398d9f02e5c3023babc3a7534261de3e05cb0c06738c6cc586f1f94578c3fa9e4fba91468682d1cb7aca129fefff2fed23dea84543003862ab
7
- data.tar.gz: d9acbeca7d5d942ec7f1454716e3b69750b25bdc83416253f86ca1c04e921774b58f968c0cedadee06ad82a2be11cb7951551d95523dd27f830e373f21b73490
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
- <table>
69
- <tr><td>Copyright</td><td>Copyright (c) 2012,2013 OKUNO Akihiro</td></tr>
70
- <tr><td>License</td><td>Apache License, Version 4.0</td></tr>
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"
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
- rescue
49
- if ! @conn.nil?
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()
@@ -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.6
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: []