[Groonga-commit] groonga/fluent-plugin-groonga-query-log at d69e587 [master] Add timezone option

Zurück zum Archiv-Index
Yasuhiro Horimoto null+****@clear*****
Tue Feb 5 22:29:41 JST 2019


Yasuhiro Horimoto	2019-02-05 22:29:41 +0900 (Tue, 05 Feb 2019)

  Revision: d69e587f758441ce02c85761469bdbd9de2e31f9
  https://github.com/groonga/fluent-plugin-groonga-query-log/commit/d69e587f758441ce02c85761469bdbd9de2e31f9

  Merged 72b3278: Add timezone option (#4)

  Message:
    Add timezone option

  Modified files:
    lib/fluent/plugin/filter_groonga_query_log.rb
    test/test_filter_groonga_query_log.rb

  Modified: lib/fluent/plugin/filter_groonga_query_log.rb (+8 -1)
===================================================================
--- lib/fluent/plugin/filter_groonga_query_log.rb    2019-02-04 15:25:29 +0900 (b42398a)
+++ lib/fluent/plugin/filter_groonga_query_log.rb    2019-02-05 22:29:41 +0900 (f99793e)
@@ -26,6 +26,7 @@ module Fluent
     config_param :slow_response_threshold,  :float,  :default => 0.2
     config_param :flatten,                  :bool,   :default => false
     config_param :flatten_separator,        :string, :default => nil
+    config_param :timezone,                 :string, :default => "utc"
 
     def configure(conf)
       super
@@ -33,6 +34,7 @@ module Fluent
       options = {
         :slow_operation_threshold => @slow_operation_threshold,
         :slow_response_threshold => @slow_response_threshold,
+        :timezone => @timezone,
       }
       @parser = GroongaQueryLog::Parser.new(options)
     end
@@ -62,7 +64,12 @@ module Fluent
     end
 
     def format_time(time)
-      time.utc.localtime.iso8601(6)
+      case @timezone
+      when "localtime"
+        time.iso8601(6)
+      else
+        time.utc.iso8601(6)
+      end
     end
 
     def flatten_record!(record)

  Modified: test/test_filter_groonga_query_log.rb (+66 -10)
===================================================================
--- test/test_filter_groonga_query_log.rb    2019-02-04 15:25:29 +0900 (d6b68fc)
+++ test/test_filter_groonga_query_log.rb    2019-02-05 22:29:41 +0900 (f96d029)
@@ -40,6 +40,7 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
                      :slow_response_threshold  => 0.2,
                      :flatten                  => false,
                      :flatten_separator        => nil,
+                     :timezone                 => "utc",
                    },
                    {
                      :raw_data_column_name     => filter.raw_data_column_name,
@@ -47,6 +48,7 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
                      :slow_response_threshold  => filter.slow_response_threshold,
                      :flatten                  => filter.flatten,
                      :flatten_separator        => filter.flatten_separator,
+                     :timezone                 => filter.timezone,
                    })
     end
 
@@ -79,6 +81,12 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
       filter = driver.instance
       assert_equal("_", filter.flatten_separator)
     end
+
+    test "timezone" do
+      driver = create_driver("timezone localtime")
+      filter = driver.instance
+      assert_equal("localtime", filter.timezone)
+    end
   end
 
   sub_test_case "filter_stream" do
@@ -112,8 +120,8 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
         "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
       ]
       statistic = {
-        "start_time"  => "2015-08-12T15:50:40.130990+09:00",
-        "last_time"   => "2015-08-12T15:50:41.228324+09:00",
+        "start_time"  => "2015-08-12T06:50:40.130990Z",
+        "last_time"   => "2015-08-12T06:50:41.228324Z",
         "elapsed"     => 1.0973349860000001,
         "return_code" => 0,
         "slow"        => true,
@@ -160,8 +168,8 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
         "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
       ]
       statistic = {
-        "start_time"                     => "2015-08-12T15:50:40.130990+09:00",
-        "last_time"                      => "2015-08-12T15:50:41.228324+09:00",
+        "start_time"                     => "2015-08-12T06:50:40.130990Z",
+        "last_time"                      => "2015-08-12T06:50:41.228324Z",
         "elapsed"                        => 1.0973349860000001,
         "return_code"                    => 0,
         "slow"                           => true,
@@ -199,8 +207,8 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
         "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
       ]
       statistic = {
-        "start_time"                     => "2015-08-12T15:50:40.130990+09:00",
-        "last_time"                      => "2015-08-12T15:50:41.228324+09:00",
+        "start_time"                     => "2015-08-12T06:50:40.130990Z",
+        "last_time"                      => "2015-08-12T06:50:41.228324Z",
         "elapsed"                        => 1.0973349860000001,
         "return_code"                    => 0,
         "slow"                           => true,
@@ -241,8 +249,8 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
         "2017-07-12 15:00:00.400000|0x7fb07d113da0|<000000040000000 rc=0",
       ]
       statistics = {
-        "start_time" => "2017-07-12T15:00:00.000000+09:00",
-        "last_time" => "2017-07-12T15:00:00.040000+09:00",
+        "start_time" => "2017-07-12T06:00:00.000000Z",
+        "last_time" => "2017-07-12T06:00:00.040000Z",
         "elapsed" => 0.04,
         "return_code" => 0,
         "slow" => false,
@@ -287,8 +295,8 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
         "2017-07-12 15:00:00.400000|0x7fb07d113da0|<000000040000000 rc=0",
       ]
       statistics = {
-        "start_time" => "2017-07-12T15:00:00.000000+09:00",
-        "last_time" => "2017-07-12T15:00:00.040000+09:00",
+        "start_time" => "2017-07-12T06:00:00.000000Z",
+        "last_time" => "2017-07-12T06:00:00.040000Z",
         "elapsed" => 0.04,
         "return_code" => 0,
         "slow" => true,
@@ -323,5 +331,53 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
       event_stream = emit("slow_response_threshold 0.01", messages)
       assert_equal([[@now, statistics]], event_stream.to_a)
     end
+
+    test "timezone" do
+      messages = [
+        "2015-08-12 15:50:40.130990|0x7fb07d113da0|>/d/select?table=Entries&match_columns=name&query=xml",
+        "2015-08-12 15:50:40.296165|0x7fb07d113da0|:000000165177838 filter(10)",
+        "2015-08-12 15:50:40.296172|0x7fb07d113da0|:000000165184723 select(10)",
+        "2015-08-12 15:50:41.228129|0x7fb07d113da0|:000001097153433 output(10)",
+        "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
+      ]
+      statistic = {
+        "start_time"  => "2015-08-12T15:50:40.130990+09:00",
+        "last_time"   => "2015-08-12T15:50:41.228324+09:00",
+        "elapsed"     => 1.0973349860000001,
+        "return_code" => 0,
+        "slow"        => true,
+        "command" => {
+          "raw" => "/d/select?table=Entries&match_columns=name&query=xml",
+          "name" => "select",
+          "parameters" => [
+            {"key" => :table,         "value" => "Entries"},
+            {"key" => :match_columns, "value" => "name"},
+            {"key" => :query,         "value" => "xml"},
+          ],
+        },
+        "operations" => [
+          {
+            "context"          => "query: xml",
+            "name"             => "filter",
+            "relative_elapsed" => 0.165177838,
+            "slow"             => true,
+          },
+          {
+            "context"          => nil,
+            "name"             => "select",
+            "relative_elapsed" => 6.884999999999999e-06,
+            "slow"             => false,
+          },
+          {
+            "context"          => nil,
+            "name"             => "output",
+            "relative_elapsed" => 0.93196871,
+            "slow"             => true,
+          },
+        ],
+      }
+      event_stream = emit("timezone localtime", messages)
+      assert_equal([[@now, statistic]], event_stream.to_a)
+    end
   end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190205/9c207f0e/attachment-0001.html>


More information about the Groonga-commit mailing list
Zurück zum Archiv-Index