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
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2014-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
@@ -16,10 +14,10 @@
16
14
  # License along with this library; if not, write to the Free Software
17
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
16
 
19
- require "groonga/query-log/analyzer/reporter"
17
+ require "groonga-query-log/command/analyzer/reporter"
20
18
 
21
- module Groonga
22
- module QueryLog
19
+ module GroongaQueryLog
20
+ module Command
23
21
  class Analyzer
24
22
  class JSONStreamReporter < Reporter
25
23
  def report_statistic(statistic)
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2011-2018 Kouhei Sutou <kou@clear-code.com>
4
2
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
5
3
  #
6
4
  # This library is free software; you can redistribute it and/or
@@ -17,10 +15,10 @@
17
15
  # License along with this library; if not, write to the Free Software
18
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
 
20
- require "groonga/query-log/analyzer/reporter"
18
+ require "groonga-query-log/command/analyzer/reporter"
21
19
 
22
- module Groonga
23
- module QueryLog
20
+ module GroongaQueryLog
21
+ module Command
24
22
  class Analyzer
25
23
  class JSONReporter < Reporter
26
24
  def report_statistic(statistic)
@@ -46,7 +44,9 @@ module Groonga
46
44
 
47
45
  private
48
46
  def format_statistic(statistic)
49
- JSON.generate(statistic.to_hash)
47
+ hash = statistic.to_hash
48
+ hash.delete("command") unless @report_command_line
49
+ JSON.generate(hash)
50
50
  end
51
51
  end
52
52
  end
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2011-2017 Kouhei Sutou <kou@clear-code.com>
4
2
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
5
3
  #
6
4
  # This library is free software; you can redistribute it and/or
@@ -17,8 +15,8 @@
17
15
  # License along with this library; if not, write to the Free Software
18
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
 
20
- module Groonga
21
- module QueryLog
18
+ module GroongaQueryLog
19
+ module Command
22
20
  class Analyzer
23
21
  class SizedGroupedOperations < Array
24
22
  def initialize
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2011-2017 Kouhei Sutou <kou@clear-code.com>
4
2
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
5
3
  #
6
4
  # This library is free software; you can redistribute it and/or
@@ -17,10 +15,10 @@
17
15
  # License along with this library; if not, write to the Free Software
18
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
 
20
- require "groonga/query-log/analyzer/sized-grouped-operations"
18
+ require "groonga-query-log/command/analyzer/sized-grouped-operations"
21
19
 
22
- module Groonga
23
- module QueryLog
20
+ module GroongaQueryLog
21
+ module Command
24
22
  class Analyzer
25
23
  class SizedStatistics < Array
26
24
  attr_reader :n_responses, :n_slow_responses, :n_slow_operations
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2011-2012 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2011-2017 Kouhei Sutou <kou@clear-code.com>
4
2
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
5
3
  #
6
4
  # This library is free software; you can redistribute it and/or
@@ -17,8 +15,8 @@
17
15
  # License along with this library; if not, write to the Free Software
18
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
 
20
- module Groonga
21
- module QueryLog
18
+ module GroongaQueryLog
19
+ module Command
22
20
  class Analyzer
23
21
  class Streamer
24
22
  def initialize(reporter)
@@ -30,7 +28,7 @@ module Groonga
30
28
  end
31
29
 
32
30
  def <<(statistic)
33
- @reporter.report_statistic(statistic) if statistic.slow?
31
+ @reporter.report_statistic(statistic)
34
32
  end
35
33
 
36
34
  def finish
@@ -0,0 +1,69 @@
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
+
19
+ require "groonga-query-log"
20
+
21
+ module GroongaQueryLog
22
+ module Command
23
+ class CheckCommandVersionCompatibility
24
+ def initialize
25
+ @options = CommandVersionCompatibilityChecker::Options.new
26
+ end
27
+
28
+ def run(command_line)
29
+ input_paths = create_parser.parse(command_line)
30
+ checker = CommandVersionCompatibilityChecker.new(@options)
31
+ checker.start do
32
+ compatible = true
33
+ if input_paths.empty?
34
+ compatible = false unless checker.check($stdin)
35
+ else
36
+ input_paths.each do |input_path|
37
+ File.open(input_path) do |input|
38
+ compatible = false unless checker.check(input)
39
+ end
40
+ end
41
+ end
42
+ compatible
43
+ end
44
+ end
45
+
46
+ private
47
+ def create_parser
48
+ parser = OptionParser.new
49
+ parser.version = VERSION
50
+ parser.banner += " QUERY_LOG1 QUERY_LOG2 ..."
51
+
52
+ parser.separator("")
53
+ parser.separator("Options:")
54
+
55
+ parser.on("--target-version=VERSION", Integer,
56
+ "Check incompatibility against command version VERSION",
57
+ "[#{@options.target_version}]") do |version|
58
+ @options.target_version = version
59
+ end
60
+
61
+ parser.on("--output=PATH",
62
+ "Output results to PATH",
63
+ "[stdout]") do |path|
64
+ @options.output_path = path
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,169 @@
1
+ # Copyright (C) 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 "optparse"
18
+
19
+ require "groonga-query-log"
20
+ require "groonga-query-log/command-line"
21
+
22
+ module GroongaQueryLog
23
+ module Command
24
+ class CheckCrash < CommandLine
25
+ def initialize
26
+ setup_options
27
+ end
28
+
29
+ def run(arguments)
30
+ begin
31
+ log_paths = @option_parser.parse!(arguments)
32
+ rescue OptionParser::InvalidOption => error
33
+ $stderr.puts(error)
34
+ return false
35
+ end
36
+
37
+ begin
38
+ check(log_paths)
39
+ rescue Interrupt
40
+ rescue Error
41
+ $stderr.puts($!.message)
42
+ return false
43
+ end
44
+
45
+ true
46
+ end
47
+
48
+ private
49
+ def setup_options
50
+ @options = {}
51
+
52
+ @option_parser = OptionParser.new do |parser|
53
+ parser.version = VERSION
54
+ parser.banner += " LOG1 ..."
55
+ end
56
+ end
57
+
58
+ def open_output
59
+ if @options[:output] == "-"
60
+ yield($stdout)
61
+ else
62
+ File.open(@options[:output], "w") do |output|
63
+ yield(output)
64
+ end
65
+ end
66
+ end
67
+
68
+ def check(log_paths)
69
+ checker = Checker.new(log_paths)
70
+ checker.check
71
+ end
72
+
73
+ class Checker
74
+ def initialize(log_paths)
75
+ @general_log_parser = GroongaLog::Parser.new
76
+ @query_log_parser = Parser.new
77
+ split_log_paths(log_paths)
78
+
79
+ @running = nil
80
+ @crash_sessions = []
81
+ @session_start = nil
82
+ end
83
+
84
+ def check
85
+ @general_log_parser.parse_paths(@general_log_paths) do |entry|
86
+ check_general_log_entry(@general_log_parser.current_path,
87
+ entry)
88
+ end
89
+ @crash_sessions.each do |start, last|
90
+ @flushed = nil
91
+ @unflushed_statistics = []
92
+ @query_log_parser.parse_paths(@query_log_paths) do |statistic|
93
+ next if statistic.start_time < start
94
+ break if statistic.start_time > last
95
+ check_query_log_statistic(@query_log_parser.current_path,
96
+ statistic)
97
+ end
98
+ unless @unflushed_statistics.empty?
99
+ puts("Unflushed statistics in #{start.iso8601}/#{last.iso8601}")
100
+ @unflushed_statistics.each do |statistic|
101
+ puts("#{statistic.start_time.iso8601}: #{statistic.raw_command}")
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ private
108
+ def split_log_paths(log_paths)
109
+ @general_log_paths = []
110
+ @query_log_paths = []
111
+ log_paths.each do |log_path|
112
+ sample_lines = GroongaLog::Input.open(log_path) do |log_file|
113
+ log_file.each_line.take(10)
114
+ end
115
+ if sample_lines.any? {|line| Parser.target_line?(line)}
116
+ @query_log_paths << log_path
117
+ elsif sample_lines.any? {|line| GroongaLog::Parser.target_line?(line)}
118
+ @general_log_paths << log_path
119
+ end
120
+ end
121
+ end
122
+
123
+ def check_general_log_entry(path, entry)
124
+ # p [path, entry]
125
+ case entry.log_level
126
+ when :emergency, :alert, :critical, :error, :warning
127
+ # p [entry.log_level, entry.message, entry.timestamp.iso8601]
128
+ end
129
+
130
+ case entry.message
131
+ when /\Agrn_init:/
132
+ if @running
133
+ @crash_sessions << [@session_start, entry.timestamp]
134
+ p [:crashed, entry.timestamp.iso8601, path]
135
+ end
136
+ @running = true
137
+ @session_start = entry.timestamp
138
+ when /\Agrn_fin \(\d+\)\z/
139
+ n_leaks = $1.to_i
140
+ @running = false
141
+ @session_start = nil
142
+ p [:leak, n_leask, entry.timestamp.iso8601] unless n_leaks.zero?
143
+ end
144
+ end
145
+
146
+ def check_query_log_statistic(path, statistic)
147
+ case statistic.command.command_name
148
+ when "load"
149
+ @flushed = false
150
+ @unflushed_statistics << statistic
151
+ when "io_flush"
152
+ @flushed = true
153
+ @unflushed_statistics.clear
154
+ when "database_unmap"
155
+ @unflushed_statistics.reject! do |statistic|
156
+ statistic.command.name == "load"
157
+ end
158
+ when /\Atable_/
159
+ @flushed = false
160
+ @unflushed_statistics << statistic
161
+ when /\Acolumn_/
162
+ @flushed = false
163
+ @unflushed_statistics << statistic
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,89 @@
1
+ # Copyright (C) 2013-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
+
19
+ require "groonga-query-log/version"
20
+ require "groonga-query-log/memory-leak-detector"
21
+
22
+ module GroongaQueryLog
23
+ module Command
24
+ class DetectMemoryLeak
25
+ def initialize
26
+ @options = MemoryLeakDetector::Options.new
27
+ end
28
+
29
+ def run(command_line)
30
+ input_paths = create_parser.parse(command_line)
31
+ detector = MemoryLeakDetector.new(@options)
32
+ input_paths.each do |input_path|
33
+ File.open(input_path) do |input|
34
+ detector.detect(input)
35
+ end
36
+ end
37
+ true
38
+ end
39
+
40
+ private
41
+ def create_parser
42
+ parser = OptionParser.new
43
+ parser.version = VERSION
44
+ parser.banner += " QUERY_LOG"
45
+
46
+ parser.separator("")
47
+ parser.separator("Options:")
48
+
49
+ parser.on("--host=HOST",
50
+ "Host name or IP address of groonga server",
51
+ "[#{@options.host}]") do |host|
52
+ @options.host = host
53
+ end
54
+
55
+ parser.on("--port=PORT", Integer,
56
+ "Port number of groonga server",
57
+ "[#{@options.port}]") do |port|
58
+ @options.port = port
59
+ end
60
+
61
+ available_protocols = [:gqtp, :http]
62
+ available_protocols_label = "[#{available_protocols.join(', ')}]"
63
+ parser.on("--protocol=PROTOCOL", available_protocols,
64
+ "Protocol of groonga server",
65
+ available_protocols_label) do |protocol|
66
+ @options.protocol = protocol
67
+ end
68
+
69
+ parser.on("--pid=PID",
70
+ "The PID of groonga server",
71
+ "[#{@options.pid}]") do |pid|
72
+ @options.pid = pid
73
+ end
74
+
75
+ parser.on("--n-tries=N", Integer,
76
+ "The number of the same request tries",
77
+ "[#{@options.n_tries}]") do |n|
78
+ @options.n_tries = n
79
+ end
80
+
81
+ parser.on("--[no-]force-disable-cache",
82
+ "Force disable cache of select command by cache=no parameter",
83
+ "[#{@options.force_disable_cache?}]") do |boolean|
84
+ @options.force_disable_cache = boolean
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end