Skip to content

Commit

Permalink
validate if timkey is less than equal 0
Browse files Browse the repository at this point in the history
Signed-off-by: Yuta Iwama <ganmacs@gmail.com>
  • Loading branch information
ganmacs committed Sep 11, 2019
1 parent 07d9eec commit 5a7db48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ def configure(conf)
Fluent::Timezone.validate!(@buffer_config.timekey_zone)
@timekey_zone = @buffer_config.timekey_use_utc ? '+0000' : @buffer_config.timekey_zone
@timekey = @buffer_config.timekey
if @timekey <= 0
raise Fluent::ConfigError, "timekey should be greater than 0. current timekey: #{@timekey}"
end
@timekey_use_utc = @buffer_config.timekey_use_utc
@offset = Fluent::Timezone.utc_offset(@timekey_zone)
@calculate_offset = @offset.respond_to?(:call) ? @offset : nil
Expand Down
12 changes: 12 additions & 0 deletions test/plugin/test_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,18 @@ def waiting(seconds)
end
end

test 'raises an error if timekey is less than equal 0' do
i = create_output(:delayed)
assert_raise Fluent::ConfigError.new('timekey should be greater than 0. current timekey: 0.0') do
i.configure(config_element('ROOT','',{},[config_element('buffer', 'time', { "timekey" => 0 })]))
end

i = create_output(:delayed)
assert_raise Fluent::ConfigError.new('timekey should be greater than 0. current timekey: -1.0') do
i.configure(config_element('ROOT','',{},[config_element('buffer', 'time', { "timekey" => -1 })]))
end
end

sub_test_case 'sync output feature' do
setup do
@i = create_output(:sync)
Expand Down

0 comments on commit 5a7db48

Please sign in to comment.