Skip to content

Commit

Permalink
Merge pull request #1442 from fluent/improve-flush_interval-handling
Browse files Browse the repository at this point in the history
Improve flush_interval handling
  • Loading branch information
repeatedly authored Feb 17, 2017
2 parents 6e13360 + 3a7ed6d commit 8f9a766
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def configure(conf)
end

has_buffer_section = (conf.elements(name: 'buffer').size > 0)
has_flush_interval = conf.has_key?('flush_interval')

super

Expand Down Expand Up @@ -290,7 +291,12 @@ def configure(conf)

@flush_mode = @buffer_config.flush_mode
if @flush_mode == :default
@flush_mode = (@chunk_key_time ? :lazy : :interval)
if has_flush_interval
log.info "'flush_interval' is configured at out side of <buffer>. 'flush_mode' is set to 'interval' to keep existing behaviour"
@flush_mode = :interval
else
@flush_mode = (@chunk_key_time ? :lazy : :interval)
end
end

buffer_type = @buffer_config[:@type]
Expand All @@ -310,6 +316,14 @@ def configure(conf)
log.warn "'flush_at_shutdown' is false, and buffer plugin '#{buf_type}' is not persistent buffer."
log.warn "your configuration will lose buffered data at shutdown. please confirm your configuration again."
end

if (@flush_mode != :interval) && buffer_conf.has_key?('flush_interval')
if buffer_conf.has_key?('flush_mode')
raise Fluent::ConfigError, "'flush_interval' can't be specified when 'flush_mode' is not 'interval' explicitly: '#{@flush_mode}'"
else
log.warn "'flush_interval' is ignored because default 'flush_mode' is not 'interval': '#{@flush_mode}'"
end
end
end

if @secondary_config
Expand Down
18 changes: 18 additions & 0 deletions test/plugin/test_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,24 @@ def waiting(seconds)
i.stop; i.before_shutdown; i.shutdown; i.after_shutdown; i.close; i.terminate
end

test 'flush_interval is ignored when flush_mode is not interval' do
mock(@i.log).warn("'flush_interval' is ignored because default 'flush_mode' is not 'interval': 'lazy'")
@i.configure(config_element('ROOT', '', {}, [config_element('buffer', 'time', {'timekey' => 60*30, 'flush_interval' => 10})]))
end

data(:lazy => 'lazy', :immediate => 'immediate')
test 'flush_interval and non-interval flush_mode is exclusive ' do |mode|
assert_raise Fluent::ConfigError.new("'flush_interval' can't be specified when 'flush_mode' is not 'interval' explicitly: '#{mode}'") do
@i.configure(config_element('ROOT', '', {}, [config_element('buffer', '', {'flush_mode' => mode, 'flush_interval' => 10})]))
end
end

test 'flush_mode is set to interval when flush_interval with v0.12 configuration is given' do
mock(@i.log).info("'flush_interval' is configured at out side of <buffer>. 'flush_mode' is set to 'interval' to keep existing behaviour")
@i.configure(config_element('ROOT', '', {'flush_interval' => 60}, []))
assert_equal :interval, @i.instance_variable_get(:@flush_mode)
end

test "Warn if primary type is different from secondary type and either primary or secondary has custom_format" do
o = create_output(:buffered)
mock(o.log).warn("secondary type should be same with primary one",
Expand Down
2 changes: 2 additions & 0 deletions test/plugin_helper/test_compat_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def write(chunk); end # dummy
assert_equal [], @i.buffer_config.chunk_keys
assert_equal 8, @i.buffer_config.flush_thread_count
assert_equal 10, @i.buffer_config.flush_interval
assert_equal :default, @i.buffer_config.flush_mode
assert @i.buffer_config.flush_at_shutdown

assert_equal 8*1024*1024, @i.buffer.chunk_limit_size
Expand All @@ -131,6 +132,7 @@ def write(chunk); end # dummy
assert @i.buffer_config.retry_forever
assert_equal 60*60, @i.buffer_config.retry_max_interval
assert_equal :block, @i.buffer_config.overflow_action
assert_equal :default, @i.buffer_config.flush_mode

assert !@i.chunk_key_tag
assert_equal [], @i.chunk_keys
Expand Down

0 comments on commit 8f9a766

Please sign in to comment.