[Groonga-commit] groonga/groonga-query-log at 1559941 [master] Add groonga-query-log-check-command-version-compatibility

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Sep 9 18:06:20 JST 2014


Kouhei Sutou	2014-09-09 18:06:20 +0900 (Tue, 09 Sep 2014)

  New Revision: 1559941549c3e037a7266a0666d5bf1670072429
  https://github.com/groonga/groonga-query-log/commit/1559941549c3e037a7266a0666d5bf1670072429

  Message:
    Add groonga-query-log-check-command-version-compatibility
    
    It parses command in passed query logs and reports incompatible items in
    target command version.

  Added files:
    lib/groonga/query-log/command-version-compatibility-checker.rb
    lib/groonga/query-log/command/check-command-version-compatibility.rb
  Copied files:
    bin/groonga-query-log-check-command-version-compatibility
      (from lib/groonga/query-log.rb)
  Modified files:
    lib/groonga/query-log.rb
    lib/groonga/query-log/incompatibility-detector.rb
    test/test-incompatibility-detector.rb

  Copied: bin/groonga-query-log-check-command-version-compatibility (+6 -8) 70%
  Mode: 100644 -> 100755
===================================================================
--- lib/groonga/query-log.rb    2014-09-09 17:37:52 +0900 (8af3ad4)
+++ bin/groonga-query-log-check-command-version-compatibility    2014-09-09 18:06:20 +0900 (5f71fa6)
@@ -1,6 +1,6 @@
-# -*- coding: utf-8 -*-
+#!/usr/bin/env ruby
 #
-# Copyright (C) 2012  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2013-2014  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -16,9 +16,7 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "groonga/query-log/version"
-require "groonga/query-log/analyzer"
-require "groonga/query-log/extractor"
-require "groonga/query-log/parser"
-require "groonga/query-log/replayer"
-require "groonga/query-log/server-verifier"
+require "groonga/query-log/command/check-command-version-compatibility"
+
+command = Groonga::QueryLog::Command::CheckCommandVersionCompatibility.new
+exit(command.run(ARGV))

  Modified: lib/groonga/query-log.rb (+1 -0)
===================================================================
--- lib/groonga/query-log.rb    2014-09-09 17:37:52 +0900 (8af3ad4)
+++ lib/groonga/query-log.rb    2014-09-09 18:06:20 +0900 (7d67110)
@@ -22,3 +22,4 @@ require "groonga/query-log/extractor"
 require "groonga/query-log/parser"
 require "groonga/query-log/replayer"
 require "groonga/query-log/server-verifier"
+require "groonga/query-log/command-version-compatibility-checker"

  Added: lib/groonga/query-log/command-version-compatibility-checker.rb (+100 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/query-log/command-version-compatibility-checker.rb    2014-09-09 18:06:20 +0900 (887f1aa)
@@ -0,0 +1,100 @@
+# Copyright (C) 2014  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "groonga/query-log/incompatibility-detector"
+
+module Groonga
+  module QueryLog
+    class CommandVersionCompatibilityChecker
+      def initialize(options)
+        @options = options
+        @incompatibility_detector =****@optio*****_incompatibility_detector
+        @output = $stdout
+        @nth_item = 1
+      end
+
+      def start
+        original_output = @output
+        result = nil
+        @options.create_output do |output|
+          @output = output
+          result = yield
+        end
+        result
+      ensure
+        @output = original_output
+      end
+
+      def check(input)
+        compatible = true
+        parser = Parser.new
+        parser.parse(input) do |statistic|
+          incompatibles = @incompatibility_detector.detect(statistic)
+          next if incompatibles.empty?
+          compatible = false
+          incompatibles.each do |incompatible|
+            report_incompatible(statistic, incompatible)
+          end
+        end
+        compatible
+      end
+
+      private
+      def report_incompatible(statistic, incompatible)
+        nth_item = @nth_item
+        @nth_item += 1
+        version = @incompatibility_detector.version
+        start_time = statistic.start_time.strftime("%Y-%m-%d %H:%M:%S.%6N")
+        @output.puts("#{nth_item}: version#{version}: #{incompatible}")
+        @output.puts("  %s" % start_time)
+        @output.puts("  #{statistic.raw_command}")
+        @output.puts("  Parameters:")
+        statistic.command.arguments.each do |key, value|
+          @output.puts("    <#{key}>: <#{value}>")
+        end
+      end
+
+      class Options
+        attr_accessor :target_version
+        attr_accessor :output_path
+        def initialize
+          @target_version = 2
+          @output_path = nil
+        end
+
+        def create_incompatibility_detector
+          case @target_version
+          when 1
+            IncompatibilityDetector::Version1.new
+          when 2
+            IncompatibilityDetector::Version2.new
+          else
+            raise ArgumentError, "Unsupported version: #{@target_version}"
+          end
+        end
+
+        def create_output(&block)
+          if @output_path
+            FileUtils.mkdir_p(File.dirname(@output_path))
+            File.open(@output_path, "w", &block)
+          else
+            yield($stdout)
+          end
+        end
+      end
+    end
+  end
+end

  Added: lib/groonga/query-log/command/check-command-version-compatibility.rb (+71 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/query-log/command/check-command-version-compatibility.rb    2014-09-09 18:06:20 +0900 (4b2d6e3)
@@ -0,0 +1,71 @@
+# Copyright (C) 2014  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "optparse"
+
+require "groonga/query-log"
+
+module Groonga
+  module QueryLog
+    module Command
+      class CheckCommandVersionCompatibility
+        def initialize
+          @options = CommandVersionCompatibilityChecker::Options.new
+        end
+
+        def run(command_line)
+          input_paths = create_parser.parse(command_line)
+          checker = CommandVersionCompatibilityChecker.new(@options)
+          checker.start do
+            compatible = true
+            if input_paths.empty?
+              compatible = false unless checker.check($stdin)
+            else
+              input_paths.each do |input_path|
+                File.open(input_path) do |input|
+                  compatible = false unless checker.check(input)
+                end
+              end
+            end
+            compatible
+          end
+        end
+
+        private
+        def create_parser
+          parser = OptionParser.new
+          parser.version = VERSION
+          parser.banner += " QUERY_LOG1 QUERY_LOG2 ..."
+
+          parser.separator("")
+          parser.separator("Options:")
+
+          parser.on("--target-version=VERSION", Integer,
+                    "Check incompatibility against command version VERSION",
+                    "[#{@options.target_version}]") do |version|
+            @options.target_version = version
+          end
+
+          parser.on("--output=PATH",
+                    "Output results to PATH",
+                    "[stdout]") do |path|
+            @options.output_path = path
+          end
+        end
+      end
+    end
+  end
+end

  Modified: lib/groonga/query-log/incompatibility-detector.rb (+2 -0)
===================================================================
--- lib/groonga/query-log/incompatibility-detector.rb    2014-09-09 17:37:52 +0900 (9c2048d)
+++ lib/groonga/query-log/incompatibility-detector.rb    2014-09-09 18:06:20 +0900 (2b2fd0e)
@@ -14,6 +14,8 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
+require "fileutils"
+
 require "groonga/query-log/parser"
 
 module Groonga

  Modified: test/test-incompatibility-detector.rb (+0 -2)
===================================================================
--- test/test-incompatibility-detector.rb    2014-09-09 17:37:52 +0900 (66ea8aa)
+++ test/test-incompatibility-detector.rb    2014-09-09 18:06:20 +0900 (eb5e1da)
@@ -14,8 +14,6 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "groonga/query-log/incompatibility-detector"
-
 class IncompatibilityDetectorTest < Test::Unit::TestCase
   def detect(command)
     query_log = <<-LOG
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index