fluent-plugin-sql 2.2.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/linux-ruby-head.yml +45 -0
- data/.github/workflows/linux.yml +10 -33
- data/.gitignore +4 -0
- data/ChangeLog +8 -0
- data/README.md +3 -0
- data/VERSION +1 -1
- data/lib/fluent/plugin/in_sql.rb +6 -3
- data/test/helper.rb +1 -1
- data/test/plugin/test_in_sql_with_state_file.rb +96 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faedf22555693658bbb43e81ed55ec147f00196e883b2f53fe42cb3617860440
|
4
|
+
data.tar.gz: df4fa7f20a2bc8e779b6ed1fc80f42b70bc2be1e2e990c0ac9c9916a2ec02570
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5176135b712ac70afb866fe5f5139ddbc49f76c0180e28ed8a5cb37be5b109d0639a2b62963c0586119f6b0f55c78eb59501cb459af2afae9c1ee9a57edba15
|
7
|
+
data.tar.gz: e6644d47e0115f3030d42e089dbce1e70e964dc6b3c549e6f69a8aad18962ad4592685224de28554a4be1e1e6bb4da6917e06f496ab981eea735983755c39464
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: Test with Ruby head
|
2
|
+
on:
|
3
|
+
schedule:
|
4
|
+
- cron: '11 23 * * 0'
|
5
|
+
workflow_dispatch:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ${{ matrix.os }}
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby: [ 'head' ]
|
14
|
+
postgres: [ '16', '15', '14', '13', '12' ]
|
15
|
+
os:
|
16
|
+
- ubuntu-latest
|
17
|
+
services:
|
18
|
+
postgres:
|
19
|
+
image: postgres:${{ matrix.postgres }}
|
20
|
+
ports:
|
21
|
+
- 5432:5432
|
22
|
+
env:
|
23
|
+
POSTGRES_USER: postgres
|
24
|
+
POSTGRES_PASSWORD: password
|
25
|
+
POSTGRES_DB: test
|
26
|
+
options: >-
|
27
|
+
--health-cmd pg_isready
|
28
|
+
--health-interval 10s
|
29
|
+
--health-timeout 5s
|
30
|
+
--health-retries 5
|
31
|
+
name: Ruby ${{ matrix.ruby }} with PostgreSQL ${{ matrix.postgres }} unit testing on ${{ matrix.os }}
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v4
|
34
|
+
- uses: ruby/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: ${{ matrix.ruby }}
|
37
|
+
bundler-cache: true
|
38
|
+
- name: prepare database
|
39
|
+
env:
|
40
|
+
PGPASSWORD: password
|
41
|
+
run: |
|
42
|
+
psql -h localhost -p 5432 -U postgres -c "CREATE ROLE fluentd WITH LOGIN ENCRYPTED PASSWORD 'fluentd';"
|
43
|
+
psql -h localhost -p 5432 -U postgres -c "CREATE DATABASE fluentd_test OWNER fluentd;"
|
44
|
+
- name: unit testing
|
45
|
+
run: bundle exec rake test
|
data/.github/workflows/linux.yml
CHANGED
@@ -1,41 +1,20 @@
|
|
1
|
-
name:
|
1
|
+
name: Test
|
2
2
|
on:
|
3
|
-
|
4
|
-
|
3
|
+
push:
|
4
|
+
branches: [master]
|
5
|
+
pull_request:
|
6
|
+
branches: [master]
|
5
7
|
|
6
8
|
jobs:
|
7
9
|
build:
|
8
10
|
runs-on: ${{ matrix.os }}
|
9
|
-
continue-on-error: ${{ matrix.experimental }}
|
10
11
|
strategy:
|
11
12
|
fail-fast: false
|
12
13
|
matrix:
|
13
|
-
ruby: [ '
|
14
|
-
postgres: [ '
|
14
|
+
ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7' ]
|
15
|
+
postgres: [ '16', '15', '14', '13', '12' ]
|
15
16
|
os:
|
16
17
|
- ubuntu-latest
|
17
|
-
experimental: [false]
|
18
|
-
include:
|
19
|
-
- ruby: head
|
20
|
-
postgres: '9'
|
21
|
-
os: ubuntu-latest
|
22
|
-
experimental: true
|
23
|
-
- ruby: head
|
24
|
-
postgres: '10'
|
25
|
-
os: ubuntu-latest
|
26
|
-
experimental: true
|
27
|
-
- ruby: head
|
28
|
-
postgres: '11'
|
29
|
-
os: ubuntu-latest
|
30
|
-
experimental: true
|
31
|
-
- ruby: head
|
32
|
-
postgres: '12'
|
33
|
-
os: ubuntu-latest
|
34
|
-
experimental: true
|
35
|
-
- ruby: head
|
36
|
-
postgres: '13'
|
37
|
-
os: ubuntu-latest
|
38
|
-
experimental: true
|
39
18
|
services:
|
40
19
|
postgres:
|
41
20
|
image: postgres:${{ matrix.postgres }}
|
@@ -52,10 +31,11 @@ jobs:
|
|
52
31
|
--health-retries 5
|
53
32
|
name: Ruby ${{ matrix.ruby }} with PostgreSQL ${{ matrix.postgres }} unit testing on ${{ matrix.os }}
|
54
33
|
steps:
|
55
|
-
- uses: actions/checkout@
|
34
|
+
- uses: actions/checkout@v4
|
56
35
|
- uses: ruby/setup-ruby@v1
|
57
36
|
with:
|
58
37
|
ruby-version: ${{ matrix.ruby }}
|
38
|
+
bundler-cache: true
|
59
39
|
- name: prepare database
|
60
40
|
env:
|
61
41
|
PGPASSWORD: password
|
@@ -63,7 +43,4 @@ jobs:
|
|
63
43
|
psql -h localhost -p 5432 -U postgres -c "CREATE ROLE fluentd WITH LOGIN ENCRYPTED PASSWORD 'fluentd';"
|
64
44
|
psql -h localhost -p 5432 -U postgres -c "CREATE DATABASE fluentd_test OWNER fluentd;"
|
65
45
|
- name: unit testing
|
66
|
-
run:
|
67
|
-
gem install bundler rake
|
68
|
-
bundle install --jobs 4 --retry 3
|
69
|
-
bundle exec rake test
|
46
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -44,6 +44,7 @@ It stores last selected rows to a file (named *state\_file*) to not forget the l
|
|
44
44
|
@type sql
|
45
45
|
|
46
46
|
host rdb_host
|
47
|
+
port rdb_port
|
47
48
|
database rdb_database
|
48
49
|
adapter mysql2_or_postgresql_or_etc
|
49
50
|
username myusername
|
@@ -68,6 +69,7 @@ It stores last selected rows to a file (named *state\_file*) to not forget the l
|
|
68
69
|
tag table2 # optional
|
69
70
|
update_column updated_at
|
70
71
|
time_column updated_at # optional
|
72
|
+
time_format %Y-%m-%d %H:%M:%S.%6N # optional
|
71
73
|
</table>
|
72
74
|
|
73
75
|
# detects all tables instead of <table> sections
|
@@ -93,6 +95,7 @@ It stores last selected rows to a file (named *state\_file*) to not forget the l
|
|
93
95
|
* **update_column**: see above description
|
94
96
|
* **time_column** (optional): if this option is set, this plugin uses this column's value as the the event's time. Otherwise it uses current time.
|
95
97
|
* **primary_key** (optional): if you want to get data from the table which doesn't have primary key like PostgreSQL's View, set this parameter.
|
98
|
+
* **time_format** (optional): if you want to specify the format of the date used in the query, useful when using alternative adapters which have restrictions on format
|
96
99
|
|
97
100
|
## Input: Limitation
|
98
101
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.1
|
data/lib/fluent/plugin/in_sql.rb
CHANGED
@@ -59,7 +59,7 @@ module Fluent::Plugin
|
|
59
59
|
config_param :update_column, :string, default: nil
|
60
60
|
config_param :time_column, :string, default: nil
|
61
61
|
config_param :primary_key, :string, default: nil
|
62
|
-
|
62
|
+
config_param :time_format, :string, default: '%Y-%m-%d %H:%M:%S.%6N%z'
|
63
63
|
attr_reader :log
|
64
64
|
|
65
65
|
def configure(conf)
|
@@ -74,10 +74,13 @@ module Fluent::Plugin
|
|
74
74
|
# creates a model for this table
|
75
75
|
table_name = @table
|
76
76
|
primary_key = @primary_key
|
77
|
+
time_format = @time_format
|
78
|
+
|
77
79
|
@model = Class.new(base_model) do
|
78
80
|
self.table_name = table_name
|
79
81
|
self.inheritance_column = '_never_use_'
|
80
82
|
self.primary_key = primary_key if primary_key
|
83
|
+
self.const_set(:TIME_FORMAT, time_format)
|
81
84
|
|
82
85
|
#self.include_root_in_json = false
|
83
86
|
|
@@ -86,7 +89,7 @@ module Fluent::Plugin
|
|
86
89
|
if v.respond_to?(:to_msgpack)
|
87
90
|
v
|
88
91
|
elsif v.is_a? Time
|
89
|
-
v.strftime(
|
92
|
+
v.strftime(self.class::TIME_FORMAT)
|
90
93
|
else
|
91
94
|
v.to_s
|
92
95
|
end
|
@@ -279,7 +282,7 @@ module Fluent::Plugin
|
|
279
282
|
require 'yaml'
|
280
283
|
|
281
284
|
@path = path
|
282
|
-
if File.
|
285
|
+
if File.exist?(@path)
|
283
286
|
@data = YAML.load_file(@path)
|
284
287
|
if @data == false || @data == []
|
285
288
|
# this happens if an users created an empty file accidentally
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,96 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/test/driver/input"
|
3
|
+
|
4
|
+
class SqlInputStateFileTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
CONFIG = %[
|
13
|
+
adapter postgresql
|
14
|
+
host localhost
|
15
|
+
port 5432
|
16
|
+
database fluentd_test
|
17
|
+
|
18
|
+
username fluentd
|
19
|
+
password fluentd
|
20
|
+
|
21
|
+
state_file /tmp/sql_state
|
22
|
+
|
23
|
+
schema_search_path public
|
24
|
+
|
25
|
+
tag_prefix db
|
26
|
+
|
27
|
+
<table>
|
28
|
+
table messages
|
29
|
+
tag logs
|
30
|
+
update_column updated_at
|
31
|
+
time_column updated_at
|
32
|
+
</table>
|
33
|
+
]
|
34
|
+
|
35
|
+
def create_driver(conf = CONFIG)
|
36
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::SQLInput).configure(conf)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_configure
|
40
|
+
d = create_driver
|
41
|
+
expected = {
|
42
|
+
host: "localhost",
|
43
|
+
port: 5432,
|
44
|
+
adapter: "postgresql",
|
45
|
+
database: "fluentd_test",
|
46
|
+
username: "fluentd",
|
47
|
+
password: "fluentd",
|
48
|
+
schema_search_path: "public",
|
49
|
+
tag_prefix: "db"
|
50
|
+
}
|
51
|
+
actual = {
|
52
|
+
host: d.instance.host,
|
53
|
+
port: d.instance.port,
|
54
|
+
adapter: d.instance.adapter,
|
55
|
+
database: d.instance.database,
|
56
|
+
username: d.instance.username,
|
57
|
+
password: d.instance.password,
|
58
|
+
schema_search_path: d.instance.schema_search_path,
|
59
|
+
tag_prefix: d.instance.tag_prefix
|
60
|
+
}
|
61
|
+
assert_equal(expected, actual)
|
62
|
+
tables = d.instance.instance_variable_get(:@tables)
|
63
|
+
assert_equal(1, tables.size)
|
64
|
+
messages = tables.first
|
65
|
+
assert_equal("messages", messages.table)
|
66
|
+
assert_equal("logs", messages.tag)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_message
|
70
|
+
d = create_driver(CONFIG + "select_interval 1")
|
71
|
+
Message.create!(message: "message 1")
|
72
|
+
Message.create!(message: "message 2")
|
73
|
+
Message.create!(message: "message 3")
|
74
|
+
|
75
|
+
d.end_if do
|
76
|
+
d.record_count >= 3
|
77
|
+
end
|
78
|
+
d.run
|
79
|
+
|
80
|
+
assert_equal("db.logs", d.events[0][0])
|
81
|
+
expected = [
|
82
|
+
[d.events[0][1], "message 1"],
|
83
|
+
[d.events[1][1], "message 2"],
|
84
|
+
[d.events[2][1], "message 3"],
|
85
|
+
]
|
86
|
+
actual = [
|
87
|
+
[Fluent::EventTime.parse(d.events[0][2]["updated_at"]), d.events[0][2]["message"]],
|
88
|
+
[Fluent::EventTime.parse(d.events[1][2]["updated_at"]), d.events[1][2]["message"]],
|
89
|
+
[Fluent::EventTime.parse(d.events[2][2]["updated_at"]), d.events[2][2]["message"]],
|
90
|
+
]
|
91
|
+
assert_equal(expected, actual)
|
92
|
+
end
|
93
|
+
|
94
|
+
class Message < ActiveRecord::Base
|
95
|
+
end
|
96
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -134,7 +134,10 @@ executables: []
|
|
134
134
|
extensions: []
|
135
135
|
extra_rdoc_files: []
|
136
136
|
files:
|
137
|
+
- ".github/dependabot.yml"
|
138
|
+
- ".github/workflows/linux-ruby-head.yml"
|
137
139
|
- ".github/workflows/linux.yml"
|
140
|
+
- ".gitignore"
|
138
141
|
- ChangeLog
|
139
142
|
- Gemfile
|
140
143
|
- Gemfile.v0.12
|
@@ -148,6 +151,7 @@ files:
|
|
148
151
|
- test/helper.rb
|
149
152
|
- test/plugin/test_in_sql.rb
|
150
153
|
- test/plugin/test_in_sql_with_custom_time.rb
|
154
|
+
- test/plugin/test_in_sql_with_state_file.rb
|
151
155
|
- test/plugin/test_out_sql.rb
|
152
156
|
homepage: https://github.com/fluent/fluent-plugin-sql
|
153
157
|
licenses:
|