groonga-query-log 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/groonga-query-log-check-command-version-compatibility +22 -0
- data/doc/text/news.md +8 -0
- data/lib/groonga/query-log.rb +1 -0
- data/lib/groonga/query-log/command-version-compatibility-checker.rb +100 -0
- data/lib/groonga/query-log/command/check-command-version-compatibility.rb +71 -0
- data/lib/groonga/query-log/incompatibility-detector.rb +98 -0
- data/lib/groonga/query-log/version.rb +1 -1
- data/test/test-incompatibility-detector.rb +63 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0419d5711633814c977ad580360a83a79452e0d6
|
4
|
+
data.tar.gz: eebf8ea3c3c40a6282c97a373cdc9f57069ad3f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50d316f1fc627b6fd6e7f0bd86e78800b591a9e36a7753a4b2fdd75a1e24f3ffd571b0110cface8befb1b584900241918f37915c99d51b2454d2da6b61a22338
|
7
|
+
data.tar.gz: 4a5a0545f91800ad90a3d82916c9eb18904105911352c8ea15ae52ddeda1272160543cf17c707b6c20a11a3c28eab68ce0122c708cb84077512eea607401b41c
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
require "groonga/query-log/command/check-command-version-compatibility"
|
20
|
+
|
21
|
+
command = Groonga::QueryLog::Command::CheckCommandVersionCompatibility.new
|
22
|
+
exit(command.run(ARGV))
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## 1.0.9: 2014-09-09
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* groonga-query-log-check-command-version-incompatibility: Added.
|
8
|
+
It parses commands in passed query logs and reports incompatible
|
9
|
+
items in target command version.
|
10
|
+
|
3
11
|
## 1.0.8: 2014-07-23
|
4
12
|
|
5
13
|
### Improvements
|
data/lib/groonga/query-log.rb
CHANGED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "groonga/query-log/incompatibility-detector"
|
18
|
+
|
19
|
+
module Groonga
|
20
|
+
module QueryLog
|
21
|
+
class CommandVersionCompatibilityChecker
|
22
|
+
def initialize(options)
|
23
|
+
@options = options
|
24
|
+
@incompatibility_detector = @options.create_incompatibility_detector
|
25
|
+
@output = $stdout
|
26
|
+
@nth_item = 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def start
|
30
|
+
original_output = @output
|
31
|
+
result = nil
|
32
|
+
@options.create_output do |output|
|
33
|
+
@output = output
|
34
|
+
result = yield
|
35
|
+
end
|
36
|
+
result
|
37
|
+
ensure
|
38
|
+
@output = original_output
|
39
|
+
end
|
40
|
+
|
41
|
+
def check(input)
|
42
|
+
compatible = true
|
43
|
+
parser = Parser.new
|
44
|
+
parser.parse(input) do |statistic|
|
45
|
+
incompatibles = @incompatibility_detector.detect(statistic)
|
46
|
+
next if incompatibles.empty?
|
47
|
+
compatible = false
|
48
|
+
incompatibles.each do |incompatible|
|
49
|
+
report_incompatible(statistic, incompatible)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
compatible
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def report_incompatible(statistic, incompatible)
|
57
|
+
nth_item = @nth_item
|
58
|
+
@nth_item += 1
|
59
|
+
version = @incompatibility_detector.version
|
60
|
+
start_time = statistic.start_time.strftime("%Y-%m-%d %H:%M:%S.%6N")
|
61
|
+
@output.puts("#{nth_item}: version#{version}: #{incompatible}")
|
62
|
+
@output.puts(" %s" % start_time)
|
63
|
+
@output.puts(" #{statistic.raw_command}")
|
64
|
+
@output.puts(" Parameters:")
|
65
|
+
statistic.command.arguments.each do |key, value|
|
66
|
+
@output.puts(" <#{key}>: <#{value}>")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Options
|
71
|
+
attr_accessor :target_version
|
72
|
+
attr_accessor :output_path
|
73
|
+
def initialize
|
74
|
+
@target_version = 2
|
75
|
+
@output_path = nil
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_incompatibility_detector
|
79
|
+
case @target_version
|
80
|
+
when 1
|
81
|
+
IncompatibilityDetector::Version1.new
|
82
|
+
when 2
|
83
|
+
IncompatibilityDetector::Version2.new
|
84
|
+
else
|
85
|
+
raise ArgumentError, "Unsupported version: #{@target_version}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def create_output(&block)
|
90
|
+
if @output_path
|
91
|
+
FileUtils.mkdir_p(File.dirname(@output_path))
|
92
|
+
File.open(@output_path, "w", &block)
|
93
|
+
else
|
94
|
+
yield($stdout)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "optparse"
|
18
|
+
|
19
|
+
require "groonga/query-log"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module QueryLog
|
23
|
+
module Command
|
24
|
+
class CheckCommandVersionCompatibility
|
25
|
+
def initialize
|
26
|
+
@options = CommandVersionCompatibilityChecker::Options.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def run(command_line)
|
30
|
+
input_paths = create_parser.parse(command_line)
|
31
|
+
checker = CommandVersionCompatibilityChecker.new(@options)
|
32
|
+
checker.start do
|
33
|
+
compatible = true
|
34
|
+
if input_paths.empty?
|
35
|
+
compatible = false unless checker.check($stdin)
|
36
|
+
else
|
37
|
+
input_paths.each do |input_path|
|
38
|
+
File.open(input_path) do |input|
|
39
|
+
compatible = false unless checker.check(input)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
compatible
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def create_parser
|
49
|
+
parser = OptionParser.new
|
50
|
+
parser.version = VERSION
|
51
|
+
parser.banner += " QUERY_LOG1 QUERY_LOG2 ..."
|
52
|
+
|
53
|
+
parser.separator("")
|
54
|
+
parser.separator("Options:")
|
55
|
+
|
56
|
+
parser.on("--target-version=VERSION", Integer,
|
57
|
+
"Check incompatibility against command version VERSION",
|
58
|
+
"[#{@options.target_version}]") do |version|
|
59
|
+
@options.target_version = version
|
60
|
+
end
|
61
|
+
|
62
|
+
parser.on("--output=PATH",
|
63
|
+
"Output results to PATH",
|
64
|
+
"[stdout]") do |path|
|
65
|
+
@options.output_path = path
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "fileutils"
|
18
|
+
|
19
|
+
require "groonga/query-log/parser"
|
20
|
+
|
21
|
+
module Groonga
|
22
|
+
module QueryLog
|
23
|
+
class IncompatibilityDetector
|
24
|
+
attr_reader :version
|
25
|
+
def initialize(version)
|
26
|
+
@version = version
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def build_message(command, parameter, description, value)
|
31
|
+
components = [
|
32
|
+
command,
|
33
|
+
parameter,
|
34
|
+
description,
|
35
|
+
"<#{value}>",
|
36
|
+
]
|
37
|
+
components.join(": ")
|
38
|
+
end
|
39
|
+
|
40
|
+
class Version1 < self
|
41
|
+
def initialize
|
42
|
+
super(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
def detect(statistic)
|
46
|
+
[]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Version2 < self
|
51
|
+
def initialize
|
52
|
+
super(2)
|
53
|
+
end
|
54
|
+
|
55
|
+
def detect(statistic)
|
56
|
+
case statistic.command.name
|
57
|
+
when "select"
|
58
|
+
detect_select(statistic)
|
59
|
+
else
|
60
|
+
[]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def detect_select(statistic)
|
66
|
+
command = statistic.command
|
67
|
+
incompatibles = []
|
68
|
+
space_delimiter_unacceptable_parameters = ["output_columns"]
|
69
|
+
space_delimiter_unacceptable_parameters.each do |parameter|
|
70
|
+
value = command[parameter]
|
71
|
+
if space_delimiter?(value)
|
72
|
+
description = "space is used as delimiter"
|
73
|
+
message = build_message("select", parameter, description, value)
|
74
|
+
incompatibles << message
|
75
|
+
end
|
76
|
+
end
|
77
|
+
incompatibles
|
78
|
+
end
|
79
|
+
|
80
|
+
def space_delimiter?(string)
|
81
|
+
return false if string.nil?
|
82
|
+
return false if have_function_call?(string)
|
83
|
+
return false if have_comma?(string)
|
84
|
+
|
85
|
+
string.strip.split(/\s+/).size > 1
|
86
|
+
end
|
87
|
+
|
88
|
+
def have_function_call?(string)
|
89
|
+
string.include?("(")
|
90
|
+
end
|
91
|
+
|
92
|
+
def have_comma?(string)
|
93
|
+
string.include?(",")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
class IncompatibilityDetectorTest < Test::Unit::TestCase
|
18
|
+
def detect(command)
|
19
|
+
query_log = <<-LOG
|
20
|
+
2012-12-12 17:39:17.628846|0x7fff786aa2b0|>#{command}
|
21
|
+
2012-12-12 17:39:17.630052|0x7fff786aa2b0|<000000001217140 rc=0
|
22
|
+
LOG
|
23
|
+
statistic = parse_query_log(query_log)
|
24
|
+
@detector.detect(statistic)
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_query_log(query_log)
|
28
|
+
parser = Groonga::QueryLog::Parser.new
|
29
|
+
parser.parse(query_log) do |statistic|
|
30
|
+
return statistic
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
sub_test_case("version1") do
|
35
|
+
def setup
|
36
|
+
@detector = Groonga::QueryLog::IncompatibilityDetector::Version1.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
sub_test_case("version2") do
|
41
|
+
def setup
|
42
|
+
@detector = Groonga::QueryLog::IncompatibilityDetector::Version2.new
|
43
|
+
end
|
44
|
+
|
45
|
+
sub_test_case("select") do
|
46
|
+
sub_test_case("output_columns") do
|
47
|
+
def test_space_delimiter
|
48
|
+
message =
|
49
|
+
"select: output_columns: space is used as delimiter: <_id _key>"
|
50
|
+
assert_equal([message], detect("select --output_columns '_id _key'"))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_comma_delimiter
|
54
|
+
assert_equal([], detect("select --output_columns '_id, _key'"))
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_one_element
|
58
|
+
assert_equal([], detect("select --output_columns '_id'"))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-query-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: groonga-command-parser
|
@@ -158,6 +158,7 @@ executables:
|
|
158
158
|
- groonga-query-log-verify-server
|
159
159
|
- groonga-query-log-extract
|
160
160
|
- groonga-query-log-run-regression-test
|
161
|
+
- groonga-query-log-check-command-version-compatibility
|
161
162
|
- groonga-query-log-replay
|
162
163
|
- groonga-query-log-show-running-queries
|
163
164
|
- groonga-query-log-detect-memory-leak
|
@@ -170,6 +171,7 @@ files:
|
|
170
171
|
- README.md
|
171
172
|
- Rakefile
|
172
173
|
- bin/groonga-query-log-analyze
|
174
|
+
- bin/groonga-query-log-check-command-version-compatibility
|
173
175
|
- bin/groonga-query-log-detect-memory-leak
|
174
176
|
- bin/groonga-query-log-extract
|
175
177
|
- bin/groonga-query-log-format-regression-test-logs
|
@@ -193,6 +195,8 @@ files:
|
|
193
195
|
- lib/groonga/query-log/analyzer/statistic.rb
|
194
196
|
- lib/groonga/query-log/analyzer/streamer.rb
|
195
197
|
- lib/groonga/query-log/command-line-utils.rb
|
198
|
+
- lib/groonga/query-log/command-version-compatibility-checker.rb
|
199
|
+
- lib/groonga/query-log/command/check-command-version-compatibility.rb
|
196
200
|
- lib/groonga/query-log/command/detect-memory-leak.rb
|
197
201
|
- lib/groonga/query-log/command/format-regression-test-logs.rb
|
198
202
|
- lib/groonga/query-log/command/replay.rb
|
@@ -200,6 +204,7 @@ files:
|
|
200
204
|
- lib/groonga/query-log/command/show-running-queries.rb
|
201
205
|
- lib/groonga/query-log/command/verify-server.rb
|
202
206
|
- lib/groonga/query-log/extractor.rb
|
207
|
+
- lib/groonga/query-log/incompatibility-detector.rb
|
203
208
|
- lib/groonga/query-log/memory-leak-detector.rb
|
204
209
|
- lib/groonga/query-log/parser.rb
|
205
210
|
- lib/groonga/query-log/replayer.rb
|
@@ -224,6 +229,7 @@ files:
|
|
224
229
|
- test/run-test.rb
|
225
230
|
- test/test-analyzer.rb
|
226
231
|
- test/test-extractor.rb
|
232
|
+
- test/test-incompatibility-detector.rb
|
227
233
|
- test/test-parser.rb
|
228
234
|
- test/test-replayer.rb
|
229
235
|
- test/test-response-comparer.rb
|
@@ -274,6 +280,7 @@ test_files:
|
|
274
280
|
- test/fixtures/order/start-time.expected
|
275
281
|
- test/fixtures/order/-elapsed.expected
|
276
282
|
- test/run-test.rb
|
283
|
+
- test/test-incompatibility-detector.rb
|
277
284
|
- test/test-extractor.rb
|
278
285
|
- test/test-replayer.rb
|
279
286
|
has_rdoc:
|