Skip to content

Commit

Permalink
Merge pull request #1319 from fluent/fix-utc-handling-compat-timeslic…
Browse files Browse the repository at this point in the history
…ed-output

Remove 'utc' field from TimeSlicedOutput conf to prevent ConfigError in plugin helpers
  • Loading branch information
tagomoris authored Nov 24, 2016
2 parents 18cb438 + 30cda80 commit eb839f9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/fluent/compat/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def timezone=(tz)
end

def assume_timekey!
@_formatter = Fluent::Timezone.formatter(@_timezone, @_time_slice_format)
@_formatter = Fluent::TimeFormatter.new(@_time_slice_format, nil, @_timezone)

return if self.metadata.timekey
if self.respond_to?(:path) && self.path =~ /\.(\d+)\.(?:b|q)(?:[a-z0-9]+)/
Expand Down Expand Up @@ -619,13 +619,16 @@ def configure(conf)
if conf['timezone']
Fluent::Timezone.validate!(conf['timezone'])
elsif conf['utc']
conf['timezone'] = "+0000"
# v0.12 assumes UTC without any configuration
# 'localtime=false && no timezone key' means UTC
conf['localtime'] = "false"
conf.delete('utc')
elsif conf['localtime']
conf['timezone'] = Time.now.strftime('%z')
conf['localtime'] = "true"
else
conf['timezone'] = "+0000" # v0.12 assumes UTC without any configuration
# v0.12 assumes UTC without any configuration
# 'localtime=false && no timezone key' means UTC
conf['localtime'] = "false"
end

Expand Down
31 changes: 30 additions & 1 deletion test/test_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,16 @@ def initialize
@written_chunk_keys = []
@errors_in_write = []
end

def configure(conf)
super

@formatter = Fluent::Plugin.new_formatter('out_file')
@formatter.configure(conf)
end

def format(tag, time, record)
[tag, time, record].to_json + "\n"
@formatter.format(tag, time, record)
end
def write(chunk)
@written_chunk_keys << chunk.key
Expand All @@ -203,6 +211,16 @@ def create_driver(conf=CONFIG)
Fluent::Test::TimeSlicedOutputTestDriver.new(TimeSlicedOutputTestPlugin).configure(conf, true)
end

data(:none => '',
:utc => "utc",
:localtime => 'localtime',
:timezone => 'timezone +0000')
test 'configure with timezone related parameters' do |param|
assert_nothing_raised {
create_driver(CONFIG + param)
}
end

sub_test_case "test emit" do
setup do
@time = Time.parse("2011-01-02 13:14:15 UTC")
Expand Down Expand Up @@ -231,6 +249,17 @@ def create_driver(conf=CONFIG)
assert_equal [], d.instance.errors_in_write
assert_equal ["2016110808"], d.instance.written_chunk_keys # default timezone is UTC
end

test "check formatted time compatibility with utc. Should Z, not +00:00" do
d = create_driver(CONFIG + %[
utc
include_time_key
])
time = Time.parse("2016-11-08 12:00:00 UTC").to_i
d.emit({"a" => 1}, time)
d.expect_format %[2016-11-08T12:00:00Z\ttest\t{"a":1,"time":"2016-11-08T12:00:00Z"}\n]
d.run
end
end
end
end

0 comments on commit eb839f9

Please sign in to comment.