groonga-query-log 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/bin/groonga-query-log-analyze +3 -4
  3. data/bin/groonga-query-log-analyze-load +22 -0
  4. data/bin/groonga-query-log-check-command-version-compatibility +2 -2
  5. data/bin/groonga-query-log-check-crash +22 -0
  6. data/bin/groonga-query-log-detect-memory-leak +2 -2
  7. data/bin/groonga-query-log-extract +2 -2
  8. data/bin/groonga-query-log-format-regression-test-logs +2 -2
  9. data/bin/groonga-query-log-replay +3 -5
  10. data/bin/groonga-query-log-run-regression-test +2 -2
  11. data/bin/groonga-query-log-show-running-queries +2 -2
  12. data/bin/groonga-query-log-verify-server +2 -2
  13. data/doc/text/news.md +31 -0
  14. data/groonga-query-log.gemspec +5 -4
  15. data/lib/groonga-query-log.rb +42 -0
  16. data/lib/{groonga/query-log/command-line-utils.rb → groonga-query-log/command-line.rb} +25 -13
  17. data/lib/{groonga/query-log → groonga-query-log}/command-version-compatibility-checker.rb +3 -5
  18. data/lib/groonga-query-log/command/analyze-load.rb +188 -0
  19. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer.rb +60 -44
  20. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter.rb +15 -20
  21. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter/console.rb +19 -18
  22. data/lib/groonga-query-log/command/analyzer/reporter/csv.rb +77 -0
  23. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter/html.rb +32 -16
  24. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter/json-stream.rb +4 -6
  25. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/reporter/json.rb +7 -7
  26. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/sized-grouped-operations.rb +3 -5
  27. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/sized-statistics.rb +4 -6
  28. data/lib/{groonga/query-log → groonga-query-log/command}/analyzer/streamer.rb +4 -6
  29. data/lib/groonga-query-log/command/check-command-version-compatibility.rb +69 -0
  30. data/lib/groonga-query-log/command/check-crash.rb +169 -0
  31. data/lib/groonga-query-log/command/detect-memory-leak.rb +89 -0
  32. data/lib/groonga-query-log/command/extract.rb +171 -0
  33. data/lib/groonga-query-log/command/format-regression-test-logs.rb +143 -0
  34. data/lib/groonga-query-log/command/replay.rb +117 -0
  35. data/lib/groonga-query-log/command/run-regression-test.rb +432 -0
  36. data/lib/groonga-query-log/command/show-running-queries.rb +78 -0
  37. data/lib/{groonga/query-log/command/replay.rb → groonga-query-log/command/verify-server.rb} +68 -37
  38. data/lib/{groonga/query-log → groonga-query-log}/incompatibility-detector.rb +3 -5
  39. data/lib/{groonga/query-log → groonga-query-log}/memory-leak-detector.rb +3 -7
  40. data/lib/groonga-query-log/parser.rb +173 -0
  41. data/lib/{groonga/query-log → groonga-query-log}/replayer.rb +7 -8
  42. data/lib/{groonga/query-log → groonga-query-log}/response-comparer.rb +3 -5
  43. data/lib/{groonga/query-log → groonga-query-log}/server-verifier.rb +3 -5
  44. data/lib/groonga-query-log/statistic.rb +192 -0
  45. data/lib/{groonga/query-log → groonga-query-log}/version.rb +2 -4
  46. data/lib/groonga/query-log.rb +21 -9
  47. data/lib/groonga/query-log/command/analyzer.rb +18 -0
  48. data/lib/groonga/query-log/command/check-command-version-compatibility.rb +2 -55
  49. data/lib/groonga/query-log/command/detect-memory-leak.rb +3 -78
  50. data/lib/groonga/query-log/command/extract.rb +5 -179
  51. data/lib/groonga/query-log/command/format-regression-test-logs.rb +3 -130
  52. data/lib/groonga/query-log/command/reply.rb +18 -0
  53. data/lib/groonga/query-log/command/run-regression-test.rb +2 -418
  54. data/lib/groonga/query-log/command/show-running-queries.rb +3 -65
  55. data/lib/groonga/query-log/command/verify-server.rb +2 -137
  56. data/test/{test-analyzer.rb → command/test-analyzer.rb} +17 -11
  57. data/test/command/test-extract.rb +9 -18
  58. data/test/command/test-format-regression-test-logs.rb +3 -3
  59. data/test/fixtures/reporter/html.expected +55 -20
  60. data/test/helper.rb +22 -7
  61. data/test/test-incompatibility-detector.rb +3 -3
  62. data/test/test-parser.rb +19 -4
  63. data/test/test-replayer.rb +4 -4
  64. data/test/test-response-comparer.rb +2 -2
  65. metadata +86 -97
  66. data/lib/groonga/query-log/analyzer/statistic.rb +0 -194
  67. data/lib/groonga/query-log/parser.rb +0 -125
  68. data/test/fixtures/run-regression-test/db.new/db +0 -0
  69. data/test/fixtures/run-regression-test/db.new/db.0000000 +0 -0
  70. data/test/fixtures/run-regression-test/db.new/db.0000100 +0 -0
  71. data/test/fixtures/run-regression-test/db.new/db.0000101 +0 -0
  72. data/test/fixtures/run-regression-test/db.new/db.0000102 +0 -0
  73. data/test/fixtures/run-regression-test/db.new/db.0000103 +0 -0
  74. data/test/fixtures/run-regression-test/db.new/db.0000103.c +0 -0
  75. data/test/fixtures/run-regression-test/db.new/db.001 +0 -0
  76. data/test/fixtures/run-regression-test/db.new/db.conf +0 -0
  77. data/test/fixtures/run-regression-test/db.new/groonga.log +0 -165
  78. data/test/fixtures/run-regression-test/db.old/db +0 -0
  79. data/test/fixtures/run-regression-test/db.old/db.0000000 +0 -0
  80. data/test/fixtures/run-regression-test/db.old/db.0000100 +0 -0
  81. data/test/fixtures/run-regression-test/db.old/db.0000101 +0 -0
  82. data/test/fixtures/run-regression-test/db.old/db.0000102 +0 -0
  83. data/test/fixtures/run-regression-test/db.old/db.0000103 +0 -0
  84. data/test/fixtures/run-regression-test/db.old/db.0000103.c +0 -0
  85. data/test/fixtures/run-regression-test/db.old/db.001 +0 -0
  86. data/test/fixtures/run-regression-test/db.old/db.conf +0 -0
  87. data/test/fixtures/run-regression-test/db.old/groonga.log +0 -79
  88. data/test/fixtures/run-regression-test/results/query.log +0 -0
@@ -0,0 +1,78 @@
1
+ # Copyright (C) 2014-2017 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
+ require "time"
19
+
20
+ require "groonga-query-log/version"
21
+ require "groonga-query-log/parser"
22
+
23
+ module GroongaQueryLog
24
+ module Command
25
+ class ShowRunningQueries
26
+ def initialize
27
+ @base_time = nil
28
+ end
29
+
30
+ def run(command_line)
31
+ input_paths = create_parser.parse(command_line)
32
+ each_parsing_statistic(input_paths) do |statistic|
33
+ timestamp = statistic.start_time.strftime("%Y-%m-%d %H:%M:%S.%6N")
34
+ puts("#{timestamp}:#{statistic.raw_command}")
35
+ end
36
+ true
37
+ end
38
+
39
+ private
40
+ def create_parser
41
+ parser = OptionParser.new
42
+ parser.version = VERSION
43
+ parser.banner += " QUERY_LOG"
44
+
45
+ parser.separator("")
46
+ parser.separator("Options:")
47
+
48
+ parser.on("--base-time=TIME",
49
+ "Show running queries at TIME",
50
+ "You can use popular time format for TIME such as W3C-DTF",
51
+ "(now)") do |base_time|
52
+ @base_time = Time.parse(base_time)
53
+ end
54
+ end
55
+
56
+ def each_parsing_statistic(input_paths)
57
+ parser = Parser.new
58
+ catch do |tag|
59
+ input_paths.each do |input_path|
60
+ File.open(input_path) do |input|
61
+ parser.parse(input) do |statistic|
62
+ next if @base_time.nil?
63
+ next if statistic.start_time < @base_time
64
+ if statistic.start_time == @base_time
65
+ yield(statistic)
66
+ end
67
+ throw(tag)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ parser.parsing_statistics.each do |statistic|
73
+ yield(statistic)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
4
2
  #
5
3
  # This library is free software; you can redistribute it and/or
6
4
  # modify it under the terms of the GNU Lesser General Public
@@ -18,23 +16,25 @@
18
16
 
19
17
  require "optparse"
20
18
 
21
- require "groonga/query-log/version"
22
- require "groonga/query-log/replayer"
19
+ require "groonga-query-log"
23
20
 
24
- module Groonga
25
- module QueryLog
21
+ module GroongaQueryLog
26
22
  module Command
27
- class Replay
23
+ class VerifyServer
28
24
  def initialize
29
- @options = Replayer::Options.new
25
+ @options = ServerVerifier::Options.new
30
26
  end
31
27
 
32
- def run(command_line)
28
+ def run(command_line, &callback)
33
29
  input_paths = create_parser.parse(command_line)
34
- replayer = Replayer.new(@options)
35
- input_paths.each do |input_path|
36
- File.open(input_path) do |input|
37
- replayer.replay(input)
30
+ verifier = ServerVerifier.new(@options)
31
+ if input_paths.empty?
32
+ verifier.verify($stdin, &callback)
33
+ else
34
+ input_paths.each do |input_path|
35
+ File.open(input_path) do |input|
36
+ verifier.verify(input, &callback)
37
+ end
38
38
  end
39
39
  end
40
40
  true
@@ -44,29 +44,48 @@ module Groonga
44
44
  def create_parser
45
45
  parser = OptionParser.new
46
46
  parser.version = VERSION
47
- parser.banner += " QUERY_LOG"
47
+ parser.banner += " QUERY_LOG1 QUERY_LOG2 ..."
48
48
 
49
49
  parser.separator("")
50
50
  parser.separator("Options:")
51
51
 
52
- parser.on("--host=HOST",
53
- "Host name or IP address of groonga server",
54
- "[#{@options.host}]") do |host|
55
- @options.host = host
52
+ available_protocols = [:gqtp, :http]
53
+ available_protocols_label = "[#{available_protocols.join(', ')}]"
54
+
55
+ parser.on("--groonga1-host=HOST",
56
+ "Host name or IP address of Groonga server 1",
57
+ "[#{@options.groonga1.host}]") do |host|
58
+ @options.groonga1.host = host
56
59
  end
57
60
 
58
- parser.on("--port=PORT", Integer,
59
- "Port number of groonga server",
60
- "[#{@options.port}]") do |port|
61
- @options.port = port
61
+ parser.on("--groonga1-port=PORT", Integer,
62
+ "Port number of Groonga server 1",
63
+ "[#{@options.groonga1.port}]") do |port|
64
+ @options.groonga1.port = port
62
65
  end
63
66
 
64
- available_protocols = [:gqtp, :http]
65
- available_protocols_label = "[#{available_protocols.join(', ')}]"
66
- parser.on("--protocol=PROTOCOL", available_protocols,
67
- "Protocol of groonga server",
67
+ parser.on("--groonga1-protocol=PROTOCOL", available_protocols,
68
+ "Protocol of Groonga server 1",
68
69
  available_protocols_label) do |protocol|
69
- @options.protocol = protocol
70
+ @options.groonga1.protocol = protocol
71
+ end
72
+
73
+ parser.on("--groonga2-host=HOST",
74
+ "Host name or IP address of Groonga server 2",
75
+ "[#{@options.groonga2.host}]") do |host|
76
+ @options.groonga2.host = host
77
+ end
78
+
79
+ parser.on("--groonga2-port=PORT", Integer,
80
+ "Port number of Groonga server 2",
81
+ "[#{@options.groonga2.port}]") do |port|
82
+ @options.groonga2.port = port
83
+ end
84
+
85
+ parser.on("--groonga2-protocol=PROTOCOL", available_protocols,
86
+ "Protocol of Groonga server 2",
87
+ available_protocols_label) do |protocol|
88
+ @options.groonga2.protocol = protocol
70
89
  end
71
90
 
72
91
  parser.on("--n-clients=N", Integer,
@@ -102,19 +121,31 @@ module Groonga
102
121
  @options.target_command_names = names
103
122
  end
104
123
 
105
- parser.on("--output-requests=PATH",
106
- "Output requests to PATH",
107
- "[not output]") do |path|
108
- @options.requests_path = path
124
+ parser.on("--no-care-order",
125
+ "Don't care order of select response records") do
126
+ @options.care_order = false
127
+ end
128
+
129
+ parser.on("--output=PATH",
130
+ "Output results to PATH",
131
+ "[stdout]") do |path|
132
+ @options.output_path = path
109
133
  end
110
134
 
111
- parser.on("--output-responses=PATH",
112
- "Output responses to PATH",
113
- "[not output]") do |path|
114
- @options.responses_path = path
135
+ parser.on("--[no-]verify-cache",
136
+ "Verify cache for each query.",
137
+ "[#{@options.verify_cache?}]") do |verify_cache|
138
+ @options.verify_cache = verify_cache
139
+ end
140
+
141
+ parser.separator("Debug options:")
142
+ parser.separator("")
143
+
144
+ parser.on("--abort-on-exception",
145
+ "Abort on exception in threads") do
146
+ Thread.abort_on_exception = true
115
147
  end
116
148
  end
117
149
  end
118
150
  end
119
- end
120
151
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2014-2017 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -16,10 +16,9 @@
16
16
 
17
17
  require "fileutils"
18
18
 
19
- require "groonga/query-log/parser"
19
+ require "groonga-query-log/parser"
20
20
 
21
- module Groonga
22
- module QueryLog
21
+ module GroongaQueryLog
23
22
  class IncompatibilityDetector
24
23
  attr_reader :version
25
24
  def initialize(version)
@@ -94,5 +93,4 @@ module Groonga
94
93
  end
95
94
  end
96
95
  end
97
- end
98
96
  end
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com>
4
2
  #
5
3
  # This library is free software; you can redistribute it and/or
6
4
  # modify it under the terms of the GNU Lesser General Public
@@ -20,10 +18,9 @@ require "time"
20
18
 
21
19
  require "groonga/client"
22
20
 
23
- require "groonga/query-log/parser"
21
+ require "groonga-query-log/parser"
24
22
 
25
- module Groonga
26
- module QueryLog
23
+ module GroongaQueryLog
27
24
  class MemoryLeakDetector
28
25
  def initialize(options)
29
26
  @options = options
@@ -122,5 +119,4 @@ module Groonga
122
119
  end
123
120
  end
124
121
  end
125
- end
126
122
  end
@@ -0,0 +1,173 @@
1
+ # Copyright (C) 2011-2018 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/statistic"
18
+
19
+ module GroongaQueryLog
20
+ class Parser
21
+ PATTERN =
22
+ /\A(?<year>\d{4})-(?<month>\d\d)-(?<day>\d\d)
23
+ \ (?<hour>\d\d):(?<minute>\d\d):(?<second>\d\d)\.(?<microsecond>\d+)
24
+ \|(?<context_id>.+?)
25
+ \|(?<type>[>:<])/x
26
+
27
+ class << self
28
+ def target_line?(line)
29
+ if line.respond_to?(:valid_encoding?)
30
+ return false unless line.valid_encoding?
31
+ end
32
+
33
+ return false unless PATTERN.match(line)
34
+
35
+ true
36
+ end
37
+ end
38
+
39
+ attr_reader :current_path
40
+ def initialize(options={})
41
+ @options = options
42
+ @slow_operation_threshold = options[:slow_operation_threshold]
43
+ @slow_response_threshold = options[:slow_response_threshold]
44
+ @target_commands = options[:target_commands]
45
+ @target_tables = options[:target_tables]
46
+ @parsing_statistics = {}
47
+
48
+ @current_path = nil
49
+ end
50
+
51
+ # Parses query-log file as stream to
52
+ # {GroongaQueryLog::Analyzer::Statistic}s including some
53
+ # informations for each query.
54
+ #
55
+ # @param [IO] input IO for input query log file.
56
+ # @yield [statistics] if a block is specified, it is called
57
+ # every time a query is finished parsing.
58
+ # @yieldparam [GroongaQueryLog::Statistic] statistic
59
+ # statistics of each query in log files.
60
+ def parse(input, &block)
61
+ return to_enum(__method__, input) unless block_given?
62
+
63
+ input.each_line do |line|
64
+ next unless line.valid_encoding?
65
+
66
+ match_data = PATTERN.match(line)
67
+ next if match_data.nil?
68
+
69
+ year = match_data[:year].to_i
70
+ month = match_data[:month].to_i
71
+ day = match_data[:day].to_i
72
+ hour = match_data[:hour].to_i
73
+ minute = match_data[:minute].to_i
74
+ second = match_data[:second].to_i
75
+ microsecond = match_data[:microsecond].to_i
76
+ context_id = match_data[:context_id]
77
+ type = match_data[:type]
78
+ rest = match_data.post_match.strip
79
+ time_stamp = Time.local(year,
80
+ month,
81
+ day,
82
+ hour,
83
+ minute,
84
+ second,
85
+ microsecond)
86
+ parse_line(time_stamp, context_id, type, rest, &block)
87
+ end
88
+ end
89
+
90
+ def parse_paths(paths, &block)
91
+ return to_enum(__method__, paths) unless block_given?
92
+
93
+ target_paths = GroongaLog::Parser.sort_paths(paths)
94
+ target_paths.each do |path|
95
+ GroongaLog::Input.open(path) do |log|
96
+ @current_path = path
97
+ begin
98
+ parse(log, &block)
99
+ ensure
100
+ @current_path = nil
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ def parsing_statistics
107
+ @parsing_statistics.values
108
+ end
109
+
110
+ private
111
+ def parse_line(time_stamp, context_id, type, rest, &block)
112
+ case type
113
+ when ">"
114
+ return if rest.empty?
115
+ statistic = create_statistic(context_id)
116
+ statistic.start(time_stamp, rest)
117
+ @parsing_statistics[context_id] = statistic
118
+ when ":"
119
+ return unless /\A(\d+) (.+)\((\d+)\)(\[.+\])?(?:: (.*))?/ =~ rest
120
+ elapsed = $1
121
+ name = $2
122
+ name += $4 if $4
123
+ n_records = $3.to_i
124
+ extra = $5
125
+ statistic = @parsing_statistics[context_id]
126
+ return if statistic.nil?
127
+ statistic.add_operation(:name => name,
128
+ :elapsed => elapsed.to_i,
129
+ :n_records => n_records,
130
+ :extra => extra)
131
+ when "<"
132
+ return unless /\A(\d+) rc=(-?\d+)/ =~ rest
133
+ elapsed = $1
134
+ return_code = $2
135
+ statistic = @parsing_statistics.delete(context_id)
136
+ return if statistic.nil?
137
+ statistic.finish(elapsed.to_i, return_code.to_i)
138
+ return unless target_statistic?(statistic)
139
+ block.call(statistic)
140
+ end
141
+ end
142
+
143
+ def create_statistic(context_id)
144
+ statistic = Statistic.new(context_id)
145
+ if @slow_operation_threshold
146
+ statistic.slow_operation_threshold = @slow_operation_threshold
147
+ end
148
+ if @slow_response_threshold
149
+ statistic.slow_response_threshold = @slow_response_threshold
150
+ end
151
+ statistic
152
+ end
153
+
154
+ def target_statistic?(statistic)
155
+ if @target_commands
156
+ unless @target_commands.include?(statistic.command.name)
157
+ return false
158
+ end
159
+ end
160
+
161
+ if @target_tables
162
+ table = statistic.command["table"]
163
+ return false if table.nil?
164
+
165
+ unless @target_tables.include?(table)
166
+ return false
167
+ end
168
+ end
169
+
170
+ true
171
+ end
172
+ end
173
+ end