fluent-plugin-proxysql-query-log 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/fluent-plugin-proxysql-query-log.gemspec +1 -1
- data/lib/fluent/plugin/in_proxysql_query_log.rb +15 -4
- data/lib/fluent/plugin/in_proxysql_query_log/watcher.rb +14 -0
- data/test/plugin/test_in_proxysql_query_log.rb +147 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93568be0e3dbf36c2d55d5413d72a6583854043f8c3f0c9eab69a75891d04fdc
|
4
|
+
data.tar.gz: 33971a068177dc8532636d36ada3b4cc906ed512115970c32c715cf14d71911f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e856303f5d1c291e1c44ea303bb81f6cc74b8bc056419fbe088386df0ec18a0df92c6bff7a93f4f21a62c83adf701e89213b1a80d9d9e27c90a7aa280010fb0b
|
7
|
+
data.tar.gz: 41f8339b5a393c328c504db9c8c6548f23760d3be9f6d73ab9135e50cc39d7827528406495615659b880296f4383387bc9be002d8d0f9c30d044a1e64dbb33f4
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "fluent-plugin-proxysql-query-log"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "0.2.0"
|
7
7
|
spec.authors = ["r_takaishi"]
|
8
8
|
spec.email = ["ryo.takaishi.0@gmail.com"]
|
9
9
|
|
@@ -25,7 +25,7 @@ module Fluent
|
|
25
25
|
class ProxysqlQueryLogInput < Fluent::Plugin::Input
|
26
26
|
Fluent::Plugin.register_input("proxysql_query_log", self)
|
27
27
|
|
28
|
-
helpers :event_loop, :storage
|
28
|
+
helpers :event_loop, :storage, :timer
|
29
29
|
|
30
30
|
DEFAULT_STORAGE_TYPE = 'local'
|
31
31
|
|
@@ -33,6 +33,7 @@ module Fluent
|
|
33
33
|
config_param :read_from_head, :bool, default: false
|
34
34
|
desc 'The paths to exclude the files from watcher list.'
|
35
35
|
config_param :exclude_path, :array, default: []
|
36
|
+
config_param :refresh_interval, :time, default: 60
|
36
37
|
config_param :tag, :string
|
37
38
|
|
38
39
|
config_section :storage do
|
@@ -56,7 +57,13 @@ module Fluent
|
|
56
57
|
def start
|
57
58
|
super
|
58
59
|
|
60
|
+
refresh_watchers
|
61
|
+
timer_execute(:in_proxysql_query_log_refresh_watchers, @refresh_interval, &method(:refresh_watchers))
|
62
|
+
end
|
63
|
+
|
64
|
+
def refresh_watchers
|
59
65
|
target_paths = expand_paths
|
66
|
+
stop_watchers(target_paths)
|
60
67
|
start_watchers(target_paths)
|
61
68
|
end
|
62
69
|
|
@@ -64,10 +71,14 @@ module Fluent
|
|
64
71
|
|
65
72
|
paths.each do |path|
|
66
73
|
log.debug("start watch: #{path}")
|
67
|
-
|
68
|
-
|
74
|
+
@watchers[path] = Watcher.new(path, 0, @pos_storage, router, @tag, log)
|
75
|
+
end
|
76
|
+
end
|
69
77
|
|
70
|
-
|
78
|
+
def stop_watchers(paths)
|
79
|
+
paths.each do |path|
|
80
|
+
w = @watchers.delete(path) if w
|
81
|
+
w.detach if w
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
@@ -10,6 +10,7 @@ module Fluent
|
|
10
10
|
@router = router
|
11
11
|
@tag = tag
|
12
12
|
@log = log
|
13
|
+
@attached = false
|
13
14
|
read
|
14
15
|
end
|
15
16
|
|
@@ -60,6 +61,19 @@ module Fluent
|
|
60
61
|
def convert_time(t)
|
61
62
|
Time.at(t/1000/1000).utc.strftime('%Y-%m-%d %H:%M:%S')
|
62
63
|
end
|
64
|
+
|
65
|
+
def attach(loop)
|
66
|
+
@attached = true
|
67
|
+
super
|
68
|
+
end
|
69
|
+
|
70
|
+
def detach
|
71
|
+
@attached = false
|
72
|
+
super
|
73
|
+
end
|
74
|
+
def attached?
|
75
|
+
@attached
|
76
|
+
end
|
63
77
|
end
|
64
78
|
end
|
65
79
|
end
|
@@ -4,27 +4,62 @@ require "fluent/plugin/in_proxysql_query_log.rb"
|
|
4
4
|
class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
5
5
|
setup do
|
6
6
|
Fluent::Test.setup
|
7
|
+
Pathname.glob("#{TMP_DIR}/*").each{|p| File.delete(p)}
|
7
8
|
end
|
8
9
|
|
9
10
|
TMP_DIR = File.dirname(__FILE__) + '/../tmp/proxysql_query_log'
|
10
11
|
CONFIG = config_element('ROOT', '', {
|
11
|
-
'path' => "#{TMP_DIR}/query_log",
|
12
|
+
'path' => "#{TMP_DIR}/query_log.00000001",
|
12
13
|
'tag' => 't1',
|
14
|
+
'refresh_interval' => 2
|
13
15
|
})
|
14
16
|
|
17
|
+
MULTI_FILE_CONFIG = config_element('ROOT', '', {
|
18
|
+
'path' => "#{TMP_DIR}/query_log*",
|
19
|
+
'tag' => 't1',
|
20
|
+
'refresh_interval' => 2
|
21
|
+
})
|
22
|
+
|
23
|
+
QUERY_1 = {
|
24
|
+
thread_id: 9,
|
25
|
+
username: 'root',
|
26
|
+
schema_name: 'alpaca',
|
27
|
+
client: '127.0.0.1:34612',
|
28
|
+
hid: 0,
|
29
|
+
server: '127.0.0.1:3306',
|
30
|
+
start_time: 1525944256367381,
|
31
|
+
end_time: 1525944256367837,
|
32
|
+
digest: '0xD69C6B36F32D2EAE',
|
33
|
+
query: 'SELECT * FROM test'
|
34
|
+
}
|
35
|
+
|
36
|
+
QUERY_2 = {
|
37
|
+
thread_id: 9,
|
38
|
+
username: 'root',
|
39
|
+
schema_name: 'alpaca',
|
40
|
+
client: '127.0.0.1:34612',
|
41
|
+
hid: 0,
|
42
|
+
server: '127.0.0.1:3306',
|
43
|
+
start_time: 1525944256367381,
|
44
|
+
end_time: 1525944256367837,
|
45
|
+
digest: '0xD69C6B36F32D2EAE',
|
46
|
+
query: 'show databases'
|
47
|
+
}
|
48
|
+
|
15
49
|
test 'singlefile' do
|
16
|
-
File.open("#{TMP_DIR}/query_log", 'wb') {|f|
|
17
|
-
write_record(f)
|
50
|
+
File.open("#{TMP_DIR}/query_log.00000001", 'wb') {|f|
|
51
|
+
write_record(f, QUERY_1)
|
18
52
|
}
|
19
53
|
config = CONFIG
|
20
54
|
d = create_driver(config)
|
21
55
|
d.run(expect_emits: 1) do
|
22
|
-
File.open("#{TMP_DIR}/query_log", "ab") {|f|
|
23
|
-
write_record(f)
|
56
|
+
File.open("#{TMP_DIR}/query_log.00000001", "ab") {|f|
|
57
|
+
write_record(f, QUERY_1)
|
24
58
|
}
|
25
59
|
end
|
26
60
|
|
27
61
|
events = d.events
|
62
|
+
assert_equal(1, d.instance.instance_variable_get('@watchers').size)
|
28
63
|
assert_equal(true, events.length > 0)
|
29
64
|
assert_equal(1, 1)
|
30
65
|
assert_equal(9, events[0][2]['thread_id'])
|
@@ -39,20 +74,116 @@ class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
|
39
74
|
assert_equal('SELECT * FROM test', events[0][2]['query'])
|
40
75
|
end
|
41
76
|
|
77
|
+
test 'multifile' do
|
78
|
+
File.open("#{TMP_DIR}/query_log.00000001", 'wb') {|f|
|
79
|
+
write_record(f, QUERY_1)
|
80
|
+
}
|
81
|
+
File.open("#{TMP_DIR}/query_log.00000002", 'wb') {|f|
|
82
|
+
write_record(f, QUERY_2)
|
83
|
+
}
|
84
|
+
|
85
|
+
config = MULTI_FILE_CONFIG
|
86
|
+
d = create_driver(config)
|
87
|
+
d.run(expect_emits: 2) do
|
88
|
+
File.open("#{TMP_DIR}/query_log.00000001", "ab") {|f|
|
89
|
+
write_record(f, QUERY_1)
|
90
|
+
}
|
91
|
+
File.open("#{TMP_DIR}/query_log.00000002", "ab") {|f|
|
92
|
+
write_record(f, QUERY_2)
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
events = d.events
|
97
|
+
assert_equal(2, d.instance.instance_variable_get('@watchers').size)
|
98
|
+
assert_equal(true, events.length > 0)
|
99
|
+
assert_equal(1, 1)
|
100
|
+
assert_equal(9, events[0][2]['thread_id'])
|
101
|
+
assert_equal('root', events[0][2]['username'])
|
102
|
+
assert_equal('alpaca', events[0][2]['schema_name'])
|
103
|
+
assert_equal('127.0.0.1:34612', events[0][2]['client'])
|
104
|
+
assert_equal(0, events[0][2]['HID'])
|
105
|
+
assert_equal('127.0.0.1:3306', events[0][2]['server'])
|
106
|
+
assert_equal('2018-05-10 09:24:16', events[0][2]['start_time'])
|
107
|
+
assert_equal('2018-05-10 09:24:16', events[0][2]['end_time'])
|
108
|
+
assert_equal('0xD69C6B36F32D2EAE', events[0][2]['digest'])
|
109
|
+
assert_equal('SELECT * FROM test', events[0][2]['query'])
|
110
|
+
|
111
|
+
assert_equal(2, d.instance.instance_variable_get('@watchers').size)
|
112
|
+
assert_equal(true, events.length > 0)
|
113
|
+
assert_equal(1, 1)
|
114
|
+
assert_equal(9, events[1][2]['thread_id'])
|
115
|
+
assert_equal('root', events[1][2]['username'])
|
116
|
+
assert_equal('alpaca', events[1][2]['schema_name'])
|
117
|
+
assert_equal('127.0.0.1:34612', events[1][2]['client'])
|
118
|
+
assert_equal(0, events[1][2]['HID'])
|
119
|
+
assert_equal('127.0.0.1:3306', events[1][2]['server'])
|
120
|
+
assert_equal('2018-05-10 09:24:16', events[1][2]['start_time'])
|
121
|
+
assert_equal('2018-05-10 09:24:16', events[1][2]['end_time'])
|
122
|
+
assert_equal('0xD69C6B36F32D2EAE', events[1][2]['digest'])
|
123
|
+
assert_equal('show databases', events[1][2]['query'])
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'rotate_file' do
|
127
|
+
File.open("#{TMP_DIR}/query_log.00000001", 'wb') {|f|
|
128
|
+
write_record(f, QUERY_1)
|
129
|
+
}
|
130
|
+
|
131
|
+
config = MULTI_FILE_CONFIG
|
132
|
+
d = create_driver(config)
|
133
|
+
d.run(expect_emits: 2) do
|
134
|
+
File.open("#{TMP_DIR}/query_log.00000002", "ab") {|f|
|
135
|
+
write_record(f, QUERY_2)
|
136
|
+
}
|
137
|
+
sleep 5
|
138
|
+
|
139
|
+
File.open("#{TMP_DIR}/query_log.00000002", "ab") {|f|
|
140
|
+
write_record(f, QUERY_2)
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
events = d.events
|
145
|
+
|
146
|
+
assert_equal(2, d.instance.instance_variable_get('@watchers').size)
|
147
|
+
assert_equal(true, events.length > 0)
|
148
|
+
|
149
|
+
assert_equal(9, events[0][2]['thread_id'])
|
150
|
+
assert_equal('root', events[0][2]['username'])
|
151
|
+
assert_equal('alpaca', events[0][2]['schema_name'])
|
152
|
+
assert_equal('127.0.0.1:34612', events[0][2]['client'])
|
153
|
+
assert_equal(0, events[0][2]['HID'])
|
154
|
+
assert_equal('127.0.0.1:3306', events[0][2]['server'])
|
155
|
+
assert_equal('2018-05-10 09:24:16', events[0][2]['start_time'])
|
156
|
+
assert_equal('2018-05-10 09:24:16', events[0][2]['end_time'])
|
157
|
+
assert_equal('0xD69C6B36F32D2EAE', events[0][2]['digest'])
|
158
|
+
assert_equal('SELECT * FROM test', events[0][2]['query'])
|
159
|
+
|
160
|
+
assert_equal(9, events[1][2]['thread_id'])
|
161
|
+
assert_equal('root', events[1][2]['username'])
|
162
|
+
assert_equal('alpaca', events[1][2]['schema_name'])
|
163
|
+
assert_equal('127.0.0.1:34612', events[1][2]['client'])
|
164
|
+
assert_equal(0, events[1][2]['HID'])
|
165
|
+
assert_equal('127.0.0.1:3306', events[1][2]['server'])
|
166
|
+
assert_equal('2018-05-10 09:24:16', events[1][2]['start_time'])
|
167
|
+
assert_equal('2018-05-10 09:24:16', events[1][2]['end_time'])
|
168
|
+
assert_equal('0xD69C6B36F32D2EAE', events[1][2]['digest'])
|
169
|
+
assert_equal('show databases', events[1][2]['query'])
|
170
|
+
|
171
|
+
end
|
172
|
+
|
42
173
|
private
|
43
174
|
|
44
|
-
def write_record(f)
|
175
|
+
def write_record(f, param)
|
45
176
|
q = ProxysqlQueryLog::Query.new
|
46
|
-
q.thread_id =
|
47
|
-
q.username =
|
48
|
-
q.schema_name =
|
49
|
-
q.client =
|
50
|
-
q.hid =
|
51
|
-
q.server =
|
52
|
-
q.start_time =
|
53
|
-
q.end_time =
|
54
|
-
q.digest =
|
55
|
-
q.query =
|
177
|
+
q.thread_id = param[:thread_id]
|
178
|
+
q.username = param[:username]
|
179
|
+
q.schema_name = param[:schema_name]
|
180
|
+
q.client = param[:client]
|
181
|
+
q.hid = param[:hid]
|
182
|
+
q.server = param[:server]
|
183
|
+
q.start_time = param[:start_time]
|
184
|
+
q.end_time = param[:end_time]
|
185
|
+
q.digest = param[:digest]
|
186
|
+
q.query = param[:query]
|
56
187
|
|
57
188
|
f.write([total_length(q), 0, 0, 0, 0, 0, 0, 0].pack('C*'))
|
58
189
|
f.write(to_binary(q))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-proxysql-query-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- r_takaishi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05
|
11
|
+
date: 2018-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|