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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36a178ba29b69f740d07e635907516dca37a02f9112814c0634db97e077dbd4e
4
- data.tar.gz: cb3a073e86d59a10c13ea7a3dd802f43183bba41f84abd96222c0e74f8f3c917
3
+ metadata.gz: 5d836beefa6469c2f7a65fc75cc41b13c818efaf046ded993934e498a10f50e6
4
+ data.tar.gz: bf976b24cbdf7e70c0ebbac8d875eb13c8b496358df21ab4a01194d5f8b54b02
5
5
  SHA512:
6
- metadata.gz: f4fe508b526a5cc977bea07bdfdb15bacee3635afdf69d8da35cadbb8737fefbc3750e5f04ab439928e57f3e548687a012d7a794e09573f76ac30b3b47ffaf64
7
- data.tar.gz: e72b977809bc2dccbec52eea077383e528f4d39a5d8fb7ff89a45aa33639f62eedac38930b1677549db07eaf9b010acdf36aab340fe98734ab4ddd6a5db82ce0
6
+ metadata.gz: dcea999d33046f2fe258f3c71a3bd811c544a45980c47c6dd70a7cbde8bcac5589fc3995bf32f717f060f33eeb50db437476a4c07a5a1e465e8edb11b0031a87
7
+ data.tar.gz: 5ba73945f431bfcf4d48c58781f4f1d48647052105098a05a30ba7f0784806b805c41d82435749130677fbfd1a7f1da4b58e3209b1797674350c1922436c0524
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-proxysql-query-log (0.3.3)
4
+ fluent-plugin-proxysql-query-log (0.4.0)
5
5
  cool.io
6
6
  fluentd (>= 0.14.2, < 2)
7
7
  proxysql_query_log-parser
@@ -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.3.3"
6
+ spec.version = "0.4.0"
7
7
  spec.authors = ["r_takaishi"]
8
8
  spec.email = ["ryo.takaishi.0@gmail.com"]
9
9
 
@@ -13,6 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ require 'socket'
16
17
  require 'cool.io'
17
18
  require 'proxysql_query_log/parser'
18
19
 
@@ -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
@@ -1,4 +1,5 @@
1
1
  $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
+ require 'socket'
2
3
  require "test-unit"
3
4
  require "fluent/test"
4
5
  require "fluent/test/driver/input"
@@ -77,4 +78,4 @@ def total_length(q)
77
78
  len += (1 + q.query.size)
78
79
 
79
80
  len
80
- end
81
+ end
@@ -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
- File.open("#{TMP_DIR}/query_log.00000001", 'wb') {|f|
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: 1) do
56
- File.open("#{TMP_DIR}/query_log.00000001", "ab") {|f|
57
- write_record(f, QUERY_1)
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
- File.open("#{TMP_DIR}/query_log.00000001", 'wb') {|f|
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("#{TMP_DIR}/query_log.00000002", 'wb') {|f|
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("#{TMP_DIR}/query_log.00000001", "ab") {|f|
114
+ File.open(query_log_path_00000001, "ab") {|f|
89
115
  write_record(f, QUERY_1)
90
116
  }
91
- File.open("#{TMP_DIR}/query_log.00000002", "ab") {|f|
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
- File.open("#{TMP_DIR}/query_log.00000001", 'wb') {|f|
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("#{TMP_DIR}/query_log.00000002", "ab") {|f|
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("#{TMP_DIR}/query_log.00000002", "ab") {|f|
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-proxysql-query-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - r_takaishi