[Groonga-commit] groonga/fluent-plugin-groonga at 1ea4548 [fluentd-v0.12] Add new command format

Back to archive index

Yasuhiro Horimoto null+****@clear*****
Mon Jan 15 18:46:19 JST 2018


Yasuhiro Horimoto	2018-01-15 18:46:19 +0900 (Mon, 15 Jan 2018)

  New Revision: 1ea4548325818e60c269ea416cbaf9d5679804cb
  https://github.com/groonga/fluent-plugin-groonga/commit/1ea4548325818e60c269ea416cbaf9d5679804cb

  Merged 638bad8: Merge pull request #26 from komainu8/fluentd-v0.12

  Message:
    Add new command format
    
    Add new config option "command_format".
    This config option change of output command format.
    value of command_format options be.
    
      tag(default) : dynamic tag
      record : fixed tag
    
    By setting tag fixedly, it prevents the order of commands from changing.

  Modified files:
    lib/fluent/plugin/in_groonga.rb
    test/test_input.rb

  Modified: lib/fluent/plugin/in_groonga.rb (+14 -2)
===================================================================
--- lib/fluent/plugin/in_groonga.rb    2018-01-15 17:04:42 +0900 (716c384)
+++ lib/fluent/plugin/in_groonga.rb    2018-01-15 18:46:19 +0900 (9424339)
@@ -34,6 +34,7 @@ module Fluent
     end
 
     config_param :protocol, :enum, :list => [:http, :gqtp], :default => :http
+    config_param :command_format, :enum, :list => [:tag, :record], :default => :tag
 
     def configure(conf)
       super
@@ -164,9 +165,20 @@ module Fluent
       def emit(command, params)
         normalized_command = command.split(".")[0]
         return unless emit_command?(normalized_command)
-        @input_plugin.router.emit("groonga.command.#{normalized_command}",
+        case @input_plugin.command_format
+        when :tag
+          tag = "groonga.command.#{normalized_command}"
+          record = params
+        else
+          tag = "groonga.command"
+          record = {
+            "name" => normalized_command,
+            "arguments" => params
+          }
+        end
+        @input_plugin.router.emit(tag,
                                   Engine.now,
-                                  params)
+                                  record)
       end
 
       private

  Modified: test/test_input.rb (+29 -2)
===================================================================
--- test/test_input.rb    2018-01-15 17:04:42 +0900 (a6b5f89)
+++ test/test_input.rb    2018-01-15 18:46:19 +0900 (0a21aaa)
@@ -35,9 +35,9 @@ class GroongaInputTest < Test::Unit::TestCase
   end
 
   private
-  def create_driver
+  def create_driver(conf = configuration)
     driver = Fluent::Test::InputTestDriver.new(Fluent::GroongaInput)
-    driver.configure(configuration)
+    driver.configure(conf)
     driver
   end
 
@@ -115,6 +115,33 @@ EOC
       end
     end
 
+    def test_target_command_with_command_format_record
+      @real_response["Content-Type"] = "application/json"
+      @real_response.body = JSON.generate([[0, 0.0, 0.0], true])
+      conf = <<EOC
+      protocol http
+      bind #{@host}
+      port #{@port}
+      real_host #{@real_host}
+      real_port #{@real_port}
+      command_format record
+EOC
+      driver = create_driver(conf)
+      driver.expect_emit("groonga.command",
+                          @now,
+                          {
+                            "name" => "table_create",
+                            "arguments" => {
+                              "name" => "Users",
+                              "flags" => "TABLE_NO_KEY",
+                            }
+                          })
+      driver.run do
+        get("/d/table_create", "name" => "Users", "flags" => "TABLE_NO_KEY")
+        assert_equal("200", @last_response.code)
+      end
+    end
+
     def test_not_target_command
       @driver.run do
         get("/d/status")
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180115/6ae08613/attachment-0003.htm 



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