Kouhei Sutou
null+****@clear*****
Wed Aug 12 17:21:56 JST 2015
Kouhei Sutou 2015-08-12 17:21:56 +0900 (Wed, 12 Aug 2015) New Revision: 887e0a9993a8f30452f77aa8f2701528a7981a07 https://github.com/groonga/fluent-plugin-groonga-query-log/commit/887e0a9993a8f30452f77aa8f2701528a7981a07 Message: Import Added files: .gitignore Gemfile README.md Rakefile doc/text/lgpl-3.txt doc/text/news.md fluent-plugin-groonga-query-log.gemspec lib/fluent/plugin/filter_groonga_query_log.rb sample/dump.conf sample/store.conf test/run-test.rb test/test_filter_groonga_query_log.rb Added: .gitignore (+8 -0) 100644 =================================================================== --- /dev/null +++ .gitignore 2015-08-12 17:21:56 +0900 (1afd70c) @@ -0,0 +1,8 @@ +/test/.test-result/ +/pkg/ +/.yardoc/ +/doc/reference/ +/doc/html/ +/doc/po/*.pot +/doc/po/*/ +/Gemfile.lock Added: Gemfile (+20 -0) 100644 =================================================================== --- /dev/null +++ Gemfile 2015-08-12 17:21:56 +0900 (86b1564) @@ -0,0 +1,20 @@ +# -*- mode: ruby -*- +# +# Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. + +source "https://rubygems.org/" + +gemspec Added: README.md (+47 -0) 100644 =================================================================== --- /dev/null +++ README.md 2015-08-12 17:21:56 +0900 (51029b8) @@ -0,0 +1,47 @@ +# README + +## Name + +fluent-plugin-groonga-query-log + +## Description + +Fluent-plugin-groonga-query-log is a Fluentd plugin to parse +[Groonga](http://groonga.org/)'s +[query log](http://groonga.org/docs/reference/log.html#query-log) with +Fluentd. + +You can detect slow query in real time by using this plugin. + +## Install + + % gem install fluent-plugin-groonga-query-log + +## Usage + +TODO + +## Authors + +* Kouhei Sutou `<kou �� clear-code.com>` + +## License + +LGPL 3. See doc/text/lgpl-3.txt for details. + +(Kouhei Sutou has a right to change the license including +contributed patches.) + +## Mailing list + +* English: [groonga-talk](https://lists.sourceforge.net/lists/listinfo/groonga-talk) +* Japanese: [groonga-dev](http://lists.sourceforge.jp/mailman/listinfo/groonga-dev) + +## Source + +The repository for fluent-plugin-groonga-query-log is on +[GitHub](https://github.com/groonga/fluent-plugin-groonga-query-log/). + +## Thanks + +* ... Added: Rakefile (+46 -0) 100644 =================================================================== --- /dev/null +++ Rakefile 2015-08-12 17:21:56 +0900 (9b8f041) @@ -0,0 +1,46 @@ +# -*- mode: ruby -*- +# +# Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. + +require "bundler/gem_helper" +require "packnga" + +base_dir = File.join(File.dirname(__FILE__)) + +helper = Bundler::GemHelper.new(base_dir) +def helper.version_tag + version +end + +helper.install +spec = helper.gemspec + +Packnga::DocumentTask.new(spec) do |task| + task.original_language = "en" + task.translate_language = "ja" +end + +groonga_org_dir = Dir.glob("{..,../../www}/groonga.org").first +Packnga::ReleaseTask.new(spec) do |task| + task.index_html_dir = groonga_org_dir +end + +desc "Run test" +task :test do + ruby("test/run-test.rb") +end + +task :default => :test Added: doc/text/lgpl-3.txt (+165 -0) 100644 =================================================================== --- /dev/null +++ doc/text/lgpl-3.txt 2015-08-12 17:21:56 +0900 (fc8a5de) @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. Added: doc/text/news.md (+5 -0) 100644 =================================================================== --- /dev/null +++ doc/text/news.md 2015-08-12 17:21:56 +0900 (57615a2) @@ -0,0 +1,5 @@ +# News + +## 1.0.0: 2015-08-12 + +The first release!!! Added: fluent-plugin-groonga-query-log.gemspec (+43 -0) 100644 =================================================================== --- /dev/null +++ fluent-plugin-groonga-query-log.gemspec 2015-08-12 17:21:56 +0900 (da62605) @@ -0,0 +1,43 @@ +# -*- mode: ruby -*- +# +# Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. + +Gem::Specification.new do |spec| + spec.name = "fluent-plugin-groonga-query-log" + spec.version = "1.0.0" + spec.authors = ["Kouhei Sutou"] + spec.email = ["kou �� clear-code.com"] + spec.summary = "Fluentd plugin to parse Groonga's query log." + spec.description = "You can detect slow query in real time by using this plugin." + spec.homepage = "https://github.com/groonga/fluent-plugin-groonga-query-log" + spec.license = "LGPLv3" + + spec.files = ["README.md", "Gemfile", "#{spec.name}.gemspec"] + spec.files += [".yardopts"] + spec.files += Dir.glob("lib/**/*.rb") + spec.files += Dir.glob("sample/**/*") + spec.files += Dir.glob("doc/text/**/*") + spec.test_files += Dir.glob("test/**/*") + spec.require_paths = ["lib"] + + spec.add_runtime_dependency("fluentd") + spec.add_runtime_dependency("groonga-query-log") + + spec.add_development_dependency("rake") + spec.add_development_dependency("bundler") + spec.add_development_dependency("packnga") + spec.add_development_dependency("test-unit") +end Added: lib/fluent/plugin/filter_groonga_query_log.rb (+111 -0) 100644 =================================================================== --- /dev/null +++ lib/fluent/plugin/filter_groonga_query_log.rb 2015-08-12 17:21:56 +0900 (e3eab2e) @@ -0,0 +1,111 @@ +# Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. + +require "time" + +require "groonga/query-log" + +module Fluent + class GroongaQueryLogFilter < Filter + Plugin.register_filter("groonga_query_log", self) + + config_param :raw_data_column_name, :string, :default => "message" + config_param :slow_operation_threshold, :float, :default => 0.1 + config_param :slow_response_threshold, :float, :default => 0.2 + config_param :flatten, :bool, :default => false + config_param :flatten_separator, :string, :default => nil + + def configure(conf) + super + + @parser = Groonga::QueryLog::Parser.new + end + + def filter_stream(tag, event_stream) + statistics_event_stream = MultiEventStream.new + event_stream.each do |time, record| + raw_data = record[@raw_data_column_name] + next if raw_data.nil? + @parser.parse(raw_data) do |statistic| + statistic_record = create_record(statistic) + statistics_event_stream.add(time, statistic_record) + end + end + statistics_event_stream + end + + private + def create_record(statistic) + record = statistic.to_hash + record["start_time"] = format_time(statistic.start_time) + record["last_time"] = format_time(statistic.last_time) + if @flatten + flatten_record!(record) + end + record + end + + def format_time(time) + time.utc.iso8601(6) + end + + def flatten_record!(record) + record.keys.each do |key| + value = record[key] + case value + when Hash + flatten_record_value_hash!(record, key, value) + when Array + flatten_record_value_array!(record, key, value) + end + end + end + + def flatten_record_value!(record, base_key, value) + case value + when Hash + flatten_record_value_hash!(record, base_key, value) + when Array + flatten_record_value_array!(record, base_key, value) + else + record[base_key] = value + end + end + + def flatten_record_value_hash!(record, base_key, hash) + record.delete(base_key) + hash.each do |key, value| + if @flatten_separator + flat_key = "#{base_key}#{@flatten_separator}#{key}" + else + flat_key = "#{base_key}.#{key}" + end + flatten_record_value!(record, flat_key, value) + end + end + + def flatten_record_value_array!(record, base_key, array) + record.delete(base_key) + array.each_with_index do |value, i| + if @flatten_separator + flat_key = "#{base_key}#{@flatten_separator}#{i}" + else + flat_key = "#{base_key}[#{i}]" + end + flatten_record_value!(record, flat_key, value) + end + end + end +end Added: sample/dump.conf (+15 -0) 100644 =================================================================== --- /dev/null +++ sample/dump.conf 2015-08-12 17:21:56 +0900 (d2fa778) @@ -0,0 +1,15 @@ +<source> + type tail + path "#{ENV['GROONGA_QUERY_LOG_PATH'] || '/var/log/groonga/query.log'}" + read_from_head true + tag groonga.query + format none +</source> + +<filter groonga.query> + type groonga_query_log +</filter> + +<match **> + type stdout +</match> Added: sample/store.conf (+26 -0) 100644 =================================================================== --- /dev/null +++ sample/store.conf 2015-08-12 17:21:56 +0900 (6c21219) @@ -0,0 +1,26 @@ +<source> + type tail + path "#{ENV['GROONGA_QUERY_LOG_PATH'] || '/var/log/groonga/query.log'}" + pos_file /var/log/td-agent/groonga-query-log.pos + read_from_head "#{ENV['GROONGA_QUERY_LOG_READ_FROM_HEAD'] || 'false'}" + tag groonga.query + format none +</source> + +<filter groonga.query> + type groonga_query_log + flatten true + flatten_separator _ +</filter> + +<match groonga.query> + type groonga + store_table QueyLogs + + protocol http + host 127.0.0.1 + + buffer_type file + buffer_path /tmp/buffer + flush_interval 1 +</match> Added: test/run-test.rb (+30 -0) 100755 =================================================================== --- /dev/null +++ test/run-test.rb 2015-08-12 17:21:56 +0900 (fbff0c4) @@ -0,0 +1,30 @@ +#!/usr/bin/env ruby +# +# Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. + +# $VERBOSE = true + +base_dir = File.expand_path(File.join(File.dirname(__FILE__), "..")) +lib_dir = File.join(base_dir, "lib") +test_dir = File.join(base_dir, "test") + +require "test-unit" + +$LOAD_PATH.unshift(lib_dir) + +ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "5000" + +exit(Test::Unit::AutoRunner.run(true, test_dir)) Added: test/test_filter_groonga_query_log.rb (+235 -0) 100644 =================================================================== --- /dev/null +++ test/test_filter_groonga_query_log.rb 2015-08-12 17:21:56 +0900 (42c71f6) @@ -0,0 +1,235 @@ +# Copyright (C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. + +require "fluent/test" +require "fluent/plugin/filter_groonga_query_log" + +class GroongaQueryLogFilterTest < Test::Unit::TestCase + setup do + Fluent::Test.setup + @now = Time.parse("2015-08-12T08:45:42Z").to_i + Fluent::Engine.now = @now + end + + private + def create_driver(configuration) + driver = Fluent::Test::FilterTestDriver.new(Fluent::GroongaQueryLogFilter) + driver.configure(configuration, true) + driver + end + + sub_test_case "configure" do + test "default" do + driver = create_driver("") + filter = driver.instance + assert_equal({ + :raw_data_column_name => "message", + :slow_operation_threshold => 0.1, + :slow_response_threshold => 0.2, + :flatten => false, + :flatten_separator => nil, + }, + { + :raw_data_column_name => filter.raw_data_column_name, + :slow_operation_threshold => filter.slow_operation_threshold, + :slow_response_threshold => filter.slow_response_threshold, + :flatten => filter.flatten, + :flatten_separator => filter.flatten_separator, + }) + end + + test "raw_data_column_name" do + driver = create_driver("raw_data_column_name data") + filter = driver.instance + assert_equal("data", filter.raw_data_column_name) + end + + test "slow_operation_threshold" do + driver = create_driver("slow_operation_threshold 1.1") + filter = driver.instance + assert_equal(1.1, filter.slow_operation_threshold) + end + + test "slow_response_threshold" do + driver = create_driver("slow_response_threshold 2.5") + filter = driver.instance + assert_equal(2.5, filter.slow_response_threshold) + end + + test "flatten" do + driver = create_driver("flatten true") + filter = driver.instance + assert_equal(true, filter.flatten) + end + + test "flatten_separator" do + driver = create_driver("flatten_separator _") + filter = driver.instance + assert_equal("_", filter.flatten_separator) + end + end + + sub_test_case "filter_stream" do + def emit(configuration, messages) + driver = create_driver(configuration) + driver.run do + messages.each do |message| + driver.emit({"message" => message}, @now) + end + end + driver.filtered + end + + test "partial" 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)", + ] + event_stream = emit("", messages) + assert_equal([], event_stream.to_a) + end + + test "one" 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-12T06:50:40.130990Z", + "last_time" => "2015-08-12T06:50:41.228324Z", + "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("", messages) + assert_equal([[@now, statistic]], event_stream.to_a) + end + + test "flatten" 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-12T06:50:40.130990Z", + "last_time" => "2015-08-12T06:50:41.228324Z", + "elapsed" => 1.0973349860000001, + "return_code" => 0, + "slow" => true, + "command.raw" => "/d/select?table=Entries&match_columns=name&query=xml", + "command.name" => "select", + "command.parameters[0].key" => :table, + "command.parameters[0].value" => "Entries", + "command.parameters[1].key" => :match_columns, + "command.parameters[1].value" => "name", + "command.parameters[2].key" => :query, + "command.parameters[2].value" => "xml", + "operations[0].context" => "query: xml", + "operations[0].name" => "filter", + "operations[0].relative_elapsed" => 0.165177838, + "operations[0].slow" => true, + "operations[1].context" => nil, + "operations[1].name" => "select", + "operations[1].relative_elapsed" => 6.884999999999999e-06, + "operations[1].slow" => false, + "operations[2].context" => nil, + "operations[2].name" => "output", + "operations[2].relative_elapsed" => 0.93196871, + "operations[2].slow" => true, + } + event_stream = emit("flatten true", messages) + assert_equal([[@now, statistic]], event_stream.to_a) + end + + test "flatten_separator" 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-12T06:50:40.130990Z", + "last_time" => "2015-08-12T06:50:41.228324Z", + "elapsed" => 1.0973349860000001, + "return_code" => 0, + "slow" => true, + "command_raw" => "/d/select?table=Entries&match_columns=name&query=xml", + "command_name" => "select", + "command_parameters_0_key" => :table, + "command_parameters_0_value" => "Entries", + "command_parameters_1_key" => :match_columns, + "command_parameters_1_value" => "name", + "command_parameters_2_key" => :query, + "command_parameters_2_value" => "xml", + "operations_0_context" => "query: xml", + "operations_0_name" => "filter", + "operations_0_relative_elapsed" => 0.165177838, + "operations_0_slow" => true, + "operations_1_context" => nil, + "operations_1_name" => "select", + "operations_1_relative_elapsed" => 6.884999999999999e-06, + "operations_1_slow" => false, + "operations_2_context" => nil, + "operations_2_name" => "output", + "operations_2_relative_elapsed" => 0.93196871, + "operations_2_slow" => true, + } + event_stream = emit(<<-CONFIGURATION, messages) + flatten true + flatten_separator _ + CONFIGURATION + assert_equal([[@now, statistic]], event_stream.to_a) + end + end +end -------------- next part -------------- HTML����������������������������... 다운로드