fluent-plugin-pghstore 0.2.6 → 0.2.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/fluent-plugin-pghstore.gemspec +3 -2
- data/lib/fluent/plugin/out_pghstore.rb +17 -10
- data/test/plugin/test_out_pghstore.rb +81 -13
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3e04d208d0f647303315742d3a6b682334d143d
|
4
|
+
data.tar.gz: 6b0891e377cb9d1289479c4f4c247ebc7bad4438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dca3130b73a82f1f2c23583641735af81bac2a4f3079a6f3c568062148a0d796d0732f1497f81694b2142f0c11cfdd0fc9aedd2deb56436602de2dd7417c2203
|
7
|
+
data.tar.gz: da3be89d0beff7901de981ac2983afe4134c34fc38f90cf48df4edbe9788c2d7737797614a901a191cd7e396a6367267984c18f4a696f964c2fc76dd1f11e076
|
@@ -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.2.
|
6
|
+
s.version = "0.2.7"
|
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"
|
@@ -21,8 +21,9 @@ Gem::Specification.new do |s|
|
|
21
21
|
# specify any dependencies here; for example:
|
22
22
|
s.add_development_dependency "rspec", "~> 3.2.0"
|
23
23
|
# s.add_runtime_dependency "rest-client"
|
24
|
-
s.add_development_dependency "fluentd", "
|
24
|
+
s.add_development_dependency "fluentd", [">= 0.12.5", "< 2"]
|
25
25
|
s.add_development_dependency "pg", "~> 0.18.1"
|
26
|
+
s.add_development_dependency "rake", ">= 11.0"
|
26
27
|
s.add_development_dependency "test-unit", "~> 3.1.0"
|
27
28
|
# s.add_runtime_dependency "fluentd", "~> 0.12.5"
|
28
29
|
# s.add_runtime_dependency "pg", "~> 0.18.1"
|
@@ -13,6 +13,7 @@ class Fluent::PgHStoreOutput < Fluent::BufferedOutput
|
|
13
13
|
def initialize
|
14
14
|
super
|
15
15
|
require 'pg'
|
16
|
+
@conn = nil
|
16
17
|
end
|
17
18
|
|
18
19
|
def start
|
@@ -28,7 +29,7 @@ class Fluent::PgHStoreOutput < Fluent::BufferedOutput
|
|
28
29
|
conn.close()
|
29
30
|
end
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
def format(tag, time, record)
|
33
34
|
[tag, time, record].to_msgpack
|
34
35
|
end
|
@@ -41,7 +42,7 @@ class Fluent::PgHStoreOutput < Fluent::BufferedOutput
|
|
41
42
|
sql = generate_sql(conn, tag, time_str, record)
|
42
43
|
begin
|
43
44
|
conn.exec(sql)
|
44
|
-
rescue PGError => e
|
45
|
+
rescue PGError => e
|
45
46
|
$log.error "PGError: " + e.message # dropped if error
|
46
47
|
end
|
47
48
|
}
|
@@ -49,6 +50,18 @@ class Fluent::PgHStoreOutput < Fluent::BufferedOutput
|
|
49
50
|
conn.close()
|
50
51
|
end
|
51
52
|
|
53
|
+
# for tests.
|
54
|
+
def table_schema(tablename)
|
55
|
+
sql =<<"SQL"
|
56
|
+
CREATE TABLE #{tablename} (
|
57
|
+
tag TEXT[],
|
58
|
+
time TIMESTAMP WITH TIME ZONE,
|
59
|
+
record HSTORE
|
60
|
+
);
|
61
|
+
SQL
|
62
|
+
sql
|
63
|
+
end
|
64
|
+
|
52
65
|
private
|
53
66
|
|
54
67
|
def generate_sql(conn, tag, time, record)
|
@@ -105,13 +118,7 @@ SQL
|
|
105
118
|
end
|
106
119
|
|
107
120
|
def create_table(tablename)
|
108
|
-
sql
|
109
|
-
CREATE TABLE #{tablename} (
|
110
|
-
tag TEXT[],
|
111
|
-
time TIMESTAMP WITH TIME ZONE,
|
112
|
-
record HSTORE
|
113
|
-
);
|
114
|
-
SQL
|
121
|
+
sql = table_schema(tablename)
|
115
122
|
|
116
123
|
sql += @table_option if @table_option
|
117
124
|
|
@@ -119,7 +126,7 @@ SQL
|
|
119
126
|
raise "Could not connect the database at create_table. abort." if conn == nil
|
120
127
|
|
121
128
|
begin
|
122
|
-
conn.exec(sql)
|
129
|
+
conn.exec(sql)
|
123
130
|
rescue PGError => e
|
124
131
|
$log.error "Error at create_table:" + e.message
|
125
132
|
$log.error "SQL:" + sql
|
@@ -5,11 +5,17 @@ class PGHStoreOutputTest < Test::Unit::TestCase
|
|
5
5
|
Fluent::Test.setup
|
6
6
|
end
|
7
7
|
|
8
|
+
HOST = "localhost"
|
9
|
+
PORT = 5432
|
10
|
+
DATABASE = "postgres"
|
11
|
+
TABLE = "testtable"
|
12
|
+
USER = ENV["PSQL_USER"] || "testuser"
|
13
|
+
PASSWORD = ENV["PSQL_PASSWORD"] || "testpassword"
|
8
14
|
CONFIG = %[
|
9
|
-
database
|
10
|
-
table
|
11
|
-
user
|
12
|
-
password
|
15
|
+
database #{DATABASE}
|
16
|
+
table #{TABLE}
|
17
|
+
user #{USER}
|
18
|
+
password #{PASSWORD}
|
13
19
|
]
|
14
20
|
|
15
21
|
def create_driver(conf = CONFIG, tag='test.input')
|
@@ -17,28 +23,90 @@ class PGHStoreOutputTest < Test::Unit::TestCase
|
|
17
23
|
end
|
18
24
|
|
19
25
|
def test_configure
|
26
|
+
d = create_driver
|
27
|
+
|
28
|
+
assert_equal DATABASE, d.instance.database
|
29
|
+
assert_equal HOST, d.instance.host
|
30
|
+
assert_equal PORT, d.instance.port
|
31
|
+
assert_equal USER, d.instance.user
|
32
|
+
assert_equal PASSWORD, d.instance.password
|
20
33
|
end
|
21
34
|
|
22
35
|
def test_format
|
23
36
|
d = create_driver
|
37
|
+
with_connection(d) do |_conn|
|
24
38
|
|
25
|
-
|
26
|
-
|
27
|
-
|
39
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
40
|
+
d.emit({"a"=>1}, time)
|
41
|
+
d.emit({"a"=>2}, time)
|
28
42
|
|
29
|
-
|
30
|
-
|
43
|
+
d.expect_format ['test.input', time, {"a"=>1}].to_msgpack
|
44
|
+
d.expect_format ['test.input', time, {"a"=>2}].to_msgpack
|
31
45
|
|
32
|
-
|
46
|
+
d.run
|
47
|
+
end
|
33
48
|
end
|
34
49
|
|
35
50
|
def test_write
|
36
51
|
d = create_driver
|
52
|
+
with_connection(d) do |conn|
|
53
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
54
|
+
d.emit({"a"=>1}, time)
|
55
|
+
d.emit({"a"=>2}, time)
|
56
|
+
d.run
|
57
|
+
|
58
|
+
wait_data(conn)
|
59
|
+
|
60
|
+
res = conn.exec("select * from #{TABLE}")[0]
|
61
|
+
assert_equal "{test,input}", res["tag"]
|
62
|
+
assert_equal Time.at(time), Time.parse(res["time"])
|
63
|
+
assert_equal "\"a\"=>\"1\"", res["record"]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def ensure_connection
|
68
|
+
conn = nil
|
69
|
+
assert_nothing_raised do
|
70
|
+
conn = PGconn.new(:dbname => DATABASE, :host => HOST, :port => PORT, :user => USER, :password => PASSWORD)
|
71
|
+
end
|
72
|
+
conn
|
73
|
+
end
|
37
74
|
|
38
|
-
|
39
|
-
|
40
|
-
#
|
75
|
+
def with_connection(driver, &block)
|
76
|
+
conn = ensure_connection
|
77
|
+
register_hstore(conn) rescue nil # suppress Exception
|
78
|
+
create_test_table(driver, conn)
|
79
|
+
begin
|
80
|
+
block.call(conn)
|
81
|
+
ensure
|
82
|
+
drop_test_table(conn)
|
83
|
+
unregister_hstore(conn)
|
84
|
+
conn.close
|
85
|
+
end
|
86
|
+
end
|
41
87
|
|
88
|
+
def register_hstore(conn)
|
89
|
+
conn.exec("CREATE EXTENSION hstore;")
|
42
90
|
end
|
43
91
|
|
92
|
+
def unregister_hstore(conn)
|
93
|
+
conn.exec("DROP EXTENSION hstore;")
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_test_table(driver, conn)
|
97
|
+
conn.exec(driver.instance.table_schema("#{TABLE}"))
|
98
|
+
end
|
99
|
+
|
100
|
+
def drop_test_table(conn)
|
101
|
+
conn.exec("DROP TABLE #{TABLE}")
|
102
|
+
end
|
103
|
+
|
104
|
+
def wait_data(conn)
|
105
|
+
10.times do
|
106
|
+
res = conn.exec "select count(*) from #{TABLE}"
|
107
|
+
return if res.getvalue(0,0).to_i > 0
|
108
|
+
sleep 0.2
|
109
|
+
end
|
110
|
+
raise "Inserting records have not been finished correctly"
|
111
|
+
end
|
44
112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-pghstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WAKAYAMA Shirou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: fluentd
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.12.5
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2'
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: 0.12.5
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: pg
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +58,20 @@ dependencies:
|
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: 0.18.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '11.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '11.0'
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: test-unit
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|