From bdafe33ef17b7947466cdc6e0464aef64b8e875c Mon Sep 17 00:00:00 2001 From: TAGOMORI Satoshi Date: Tue, 8 Nov 2016 18:14:05 +0900 Subject: [PATCH 1/2] fix to set values into conf instead of instance variables because instance variables are initialized with default value in "super" --- lib/fluent/compat/output.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/fluent/compat/output.rb b/lib/fluent/compat/output.rb index bbad075a02..d621a06b95 100644 --- a/lib/fluent/compat/output.rb +++ b/lib/fluent/compat/output.rb @@ -617,17 +617,16 @@ def configure(conf) end if conf['timezone'] - @timezone = conf['timezone'] - Fluent::Timezone.validate!(@timezone) + Fluent::Timezone.validate!(conf['timezone']) elsif conf['utc'] - @timezone = "+0000" - @localtime = false + conf['timezone'] = "+0000" + conf['localtime'] = "false" elsif conf['localtime'] - @timezone = Time.now.strftime('%z') - @localtime = true + conf['timezone'] = Time.now.strftime('%z') + conf['localtime'] = "true" else - @timezone = "+0000" # v0.12 assumes UTC without any configuration - @localtime = false + conf['timezone'] = "+0000" # v0.12 assumes UTC without any configuration + conf['localtime'] = "false" end @_timekey = case conf['time_slice_format'] From 3849563b07015ac3e4febf746ca8fa15ea0f3d1a Mon Sep 17 00:00:00 2001 From: TAGOMORI Satoshi Date: Tue, 8 Nov 2016 18:15:20 +0900 Subject: [PATCH 2/2] add test to get chunk.key in TimeSlicedOutput via compat layer --- test/test_output.rb | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/test_output.rb b/test/test_output.rb index 40dee4e0c1..06c6614d7f 100644 --- a/test/test_output.rb +++ b/test/test_output.rb @@ -178,12 +178,24 @@ def setup CONFIG = %[ buffer_path #{TMP_DIR}/foo - time_slice_format %Y%m%d + time_slice_format %Y%m%d%H ] class TimeSlicedOutputTestPlugin < Fluent::TimeSlicedOutput + attr_reader :written_chunk_keys, :errors_in_write + def initialize + super + @written_chunk_keys = [] + @errors_in_write = [] + end def format(tag, time, record) - '' + [tag, time, record].to_json + "\n" + end + def write(chunk) + @written_chunk_keys << chunk.key + true + rescue => e + @errors_in_write << e end end @@ -209,6 +221,16 @@ def create_driver(conf=CONFIG) d.instance.emit_events('test', OneEventStream.new('string', 10)) end end + + test "plugin can get key of chunk in #write" do + d = create_driver + d.instance.start + d.instance.after_start + d.instance.emit_events('test', OneEventStream.new(event_time("2016-11-08 17:44:30 +0900"), {"message" => "yay"})) + d.instance.force_flush + assert_equal [], d.instance.errors_in_write + assert_equal ["2016110808"], d.instance.written_chunk_keys # default timezone is UTC + end end end end