fluent-plugin-proxysql-query-log 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/fluent-plugin-proxysql-query-log.gemspec +1 -1
- data/lib/fluent/plugin/in_proxysql_query_log.rb +1 -0
- data/lib/fluent/plugin/in_proxysql_query_log/watcher.rb +9 -1
- data/test/helper.rb +2 -1
- data/test/plugin/test_in_proxysql_query_log.rb +52 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d836beefa6469c2f7a65fc75cc41b13c818efaf046ded993934e498a10f50e6
|
4
|
+
data.tar.gz: bf976b24cbdf7e70c0ebbac8d875eb13c8b496358df21ab4a01194d5f8b54b02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcea999d33046f2fe258f3c71a3bd811c544a45980c47c6dd70a7cbde8bcac5589fc3995bf32f717f060f33eeb50db437476a4c07a5a1e465e8edb11b0031a87
|
7
|
+
data.tar.gz: 5ba73945f431bfcf4d48c58781f4f1d48647052105098a05a30ba7f0784806b805c41d82435749130677fbfd1a7f1da4b58e3209b1797674350c1922436c0524
|
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.4.0"
|
7
7
|
spec.authors = ["r_takaishi"]
|
8
8
|
spec.email = ["ryo.takaishi.0@gmail.com"]
|
9
9
|
|
@@ -33,6 +33,7 @@ module Fluent
|
|
33
33
|
seek(@path)
|
34
34
|
|
35
35
|
while true
|
36
|
+
@pos = @io.pos
|
36
37
|
raw_total_bytes = @io.read(8)
|
37
38
|
return unless raw_total_bytes
|
38
39
|
|
@@ -57,7 +58,10 @@ module Fluent
|
|
57
58
|
'end_time' => convert_time(query.end_time),
|
58
59
|
'duration' => query.end_time - query.start_time,
|
59
60
|
'digest' => query.digest,
|
60
|
-
'query' => query.query
|
61
|
+
'query' => query.query,
|
62
|
+
'hostname' => hostname,
|
63
|
+
'filename' => @path,
|
64
|
+
'pos' => @pos
|
61
65
|
}
|
62
66
|
end
|
63
67
|
|
@@ -78,6 +82,10 @@ module Fluent
|
|
78
82
|
def attached?
|
79
83
|
@attached
|
80
84
|
end
|
85
|
+
|
86
|
+
def hostname
|
87
|
+
@hostname ||= Socket.gethostname
|
88
|
+
end
|
81
89
|
end
|
82
90
|
end
|
83
91
|
end
|
data/test/helper.rb
CHANGED
@@ -7,6 +7,7 @@ class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
|
7
7
|
Pathname.glob("#{TMP_DIR}/*").each{|p| File.delete(p)}
|
8
8
|
end
|
9
9
|
|
10
|
+
HOSTNAME = Socket.gethostname
|
10
11
|
TMP_DIR = File.dirname(__FILE__) + '/../tmp/proxysql_query_log'
|
11
12
|
CONFIG = config_element('ROOT', '', {
|
12
13
|
'path' => "#{TMP_DIR}/query_log.00000001",
|
@@ -47,14 +48,16 @@ class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
|
47
48
|
}
|
48
49
|
|
49
50
|
test 'singlefile' do
|
50
|
-
|
51
|
+
query_log_path_00000001 = "#{TMP_DIR}/query_log.00000001"
|
52
|
+
|
53
|
+
File.open(query_log_path_00000001, 'wb') {|f|
|
51
54
|
write_record(f, QUERY_1)
|
52
55
|
}
|
53
56
|
config = CONFIG
|
54
57
|
d = create_driver(config)
|
55
|
-
d.run(expect_emits:
|
56
|
-
File.open(
|
57
|
-
write_record(f,
|
58
|
+
d.run(expect_emits: 2) do
|
59
|
+
File.open(query_log_path_00000001, "ab") {|f|
|
60
|
+
write_record(f, QUERY_2)
|
58
61
|
}
|
59
62
|
end
|
60
63
|
|
@@ -72,23 +75,46 @@ class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
|
72
75
|
assert_equal('2018-05-10 09:24:16', events[0][2]['end_time'])
|
73
76
|
assert_equal('0xD69C6B36F32D2EAE', events[0][2]['digest'])
|
74
77
|
assert_equal('SELECT * FROM test', events[0][2]['query'])
|
78
|
+
assert_equal(0, events[0][2]['pos'])
|
79
|
+
assert_equal(HOSTNAME, events[0][2]['hostname'])
|
80
|
+
assert_equal(query_log_path_00000001, events[0][2]['filename'])
|
81
|
+
|
82
|
+
assert_equal(1, d.instance.instance_variable_get('@watchers').size)
|
83
|
+
assert_equal(true, events.length > 0)
|
84
|
+
assert_equal(1, 1)
|
85
|
+
assert_equal(9, events[1][2]['thread_id'])
|
86
|
+
assert_equal('root', events[1][2]['username'])
|
87
|
+
assert_equal('alpaca', events[1][2]['schema_name'])
|
88
|
+
assert_equal('127.0.0.1:34612', events[1][2]['client'])
|
89
|
+
assert_equal(0, events[1][2]['HID'])
|
90
|
+
assert_equal('127.0.0.1:3306', events[1][2]['server'])
|
91
|
+
assert_equal('2018-05-10 09:24:16', events[1][2]['start_time'])
|
92
|
+
assert_equal('2018-05-10 09:24:16', events[1][2]['end_time'])
|
93
|
+
assert_equal('0xD69C6B36F32D2EAE', events[1][2]['digest'])
|
94
|
+
assert_equal('show databases', events[1][2]['query'])
|
95
|
+
assert_equal(100, events[1][2]['pos'])
|
96
|
+
assert_equal(HOSTNAME, events[1][2]['hostname'])
|
97
|
+
assert_equal(query_log_path_00000001, events[1][2]['filename'])
|
75
98
|
end
|
76
99
|
|
77
100
|
test 'multifile' do
|
78
|
-
|
101
|
+
query_log_path_00000001 = "#{TMP_DIR}/query_log.00000001"
|
102
|
+
query_log_path_00000002 = "#{TMP_DIR}/query_log.00000002"
|
103
|
+
|
104
|
+
File.open(query_log_path_00000001, 'wb') {|f|
|
79
105
|
write_record(f, QUERY_1)
|
80
106
|
}
|
81
|
-
File.open(
|
107
|
+
File.open(query_log_path_00000002, 'wb') {|f|
|
82
108
|
write_record(f, QUERY_2)
|
83
109
|
}
|
84
110
|
|
85
111
|
config = MULTI_FILE_CONFIG
|
86
112
|
d = create_driver(config)
|
87
113
|
d.run(expect_emits: 2) do
|
88
|
-
File.open(
|
114
|
+
File.open(query_log_path_00000001, "ab") {|f|
|
89
115
|
write_record(f, QUERY_1)
|
90
116
|
}
|
91
|
-
File.open(
|
117
|
+
File.open(query_log_path_00000002, "ab") {|f|
|
92
118
|
write_record(f, QUERY_2)
|
93
119
|
}
|
94
120
|
end
|
@@ -107,6 +133,9 @@ class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
|
107
133
|
assert_equal('2018-05-10 09:24:16', events[0][2]['end_time'])
|
108
134
|
assert_equal('0xD69C6B36F32D2EAE', events[0][2]['digest'])
|
109
135
|
assert_equal('SELECT * FROM test', events[0][2]['query'])
|
136
|
+
assert_equal(0, events[0][2]['pos'])
|
137
|
+
assert_equal(HOSTNAME, events[0][2]['hostname'])
|
138
|
+
assert_equal(query_log_path_00000001, events[0][2]['filename'])
|
110
139
|
|
111
140
|
assert_equal(2, d.instance.instance_variable_get('@watchers').size)
|
112
141
|
assert_equal(true, events.length > 0)
|
@@ -121,22 +150,28 @@ class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
|
121
150
|
assert_equal('2018-05-10 09:24:16', events[1][2]['end_time'])
|
122
151
|
assert_equal('0xD69C6B36F32D2EAE', events[1][2]['digest'])
|
123
152
|
assert_equal('show databases', events[1][2]['query'])
|
153
|
+
assert_equal(0, events[1][2]['pos'])
|
154
|
+
assert_equal(HOSTNAME, events[1][2]['hostname'])
|
155
|
+
assert_equal(query_log_path_00000002, events[1][2]['filename'])
|
124
156
|
end
|
125
157
|
|
126
158
|
test 'rotate_file' do
|
127
|
-
|
159
|
+
query_log_path_00000001 = "#{TMP_DIR}/query_log.00000001"
|
160
|
+
query_log_path_00000002 = "#{TMP_DIR}/query_log.00000002"
|
161
|
+
|
162
|
+
File.open(query_log_path_00000001, 'wb') {|f|
|
128
163
|
write_record(f, QUERY_1)
|
129
164
|
}
|
130
165
|
|
131
166
|
config = MULTI_FILE_CONFIG
|
132
167
|
d = create_driver(config)
|
133
168
|
d.run(expect_emits: 2) do
|
134
|
-
File.open(
|
169
|
+
File.open(query_log_path_00000002, "ab") {|f|
|
135
170
|
write_record(f, QUERY_2)
|
136
171
|
}
|
137
172
|
sleep 5
|
138
173
|
|
139
|
-
File.open(
|
174
|
+
File.open(query_log_path_00000002, "ab") {|f|
|
140
175
|
write_record(f, QUERY_2)
|
141
176
|
}
|
142
177
|
end
|
@@ -156,6 +191,9 @@ class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
|
156
191
|
assert_equal('2018-05-10 09:24:16', events[0][2]['end_time'])
|
157
192
|
assert_equal('0xD69C6B36F32D2EAE', events[0][2]['digest'])
|
158
193
|
assert_equal('SELECT * FROM test', events[0][2]['query'])
|
194
|
+
assert_equal(0, events[1][2]['pos'])
|
195
|
+
assert_equal(HOSTNAME, events[1][2]['hostname'])
|
196
|
+
assert_equal(query_log_path_00000002, events[1][2]['filename'])
|
159
197
|
|
160
198
|
assert_equal(9, events[1][2]['thread_id'])
|
161
199
|
assert_equal('root', events[1][2]['username'])
|
@@ -167,6 +205,9 @@ class ProxysqlQueryLogInputTest < Test::Unit::TestCase
|
|
167
205
|
assert_equal('2018-05-10 09:24:16', events[1][2]['end_time'])
|
168
206
|
assert_equal('0xD69C6B36F32D2EAE', events[1][2]['digest'])
|
169
207
|
assert_equal('show databases', events[1][2]['query'])
|
208
|
+
assert_equal(0, events[1][2]['pos'])
|
209
|
+
assert_equal(HOSTNAME, events[1][2]['hostname'])
|
210
|
+
assert_equal(query_log_path_00000002, events[1][2]['filename'])
|
170
211
|
|
171
212
|
end
|
172
213
|
|