Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timezone for compat timesliced output plugins #1307

Merged
merged 2 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/fluent/compat/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
26 changes: 24 additions & 2 deletions test/test_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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