Skip to content

Commit

Permalink
fix to warn for configuration which makes too many staged chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris committed Jun 16, 2016
1 parent 397d8ea commit bec97a5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Output < Base
CHUNK_KEY_PATTERN = /^[-_.@a-zA-Z0-9]+$/
CHUNK_KEY_PLACEHOLDER_PATTERN = /\$\{[-_.@a-zA-Z0-9]+\}/

CHUNKING_FIELD_WARN_NUM = 4

config_param :time_as_integer, :bool, default: false

# `<buffer>` and `<secondary>` sections are available only when '#format' and '#write' are implemented
Expand Down Expand Up @@ -253,6 +255,10 @@ def configure(conf)
@output_time_formatter_cache = {}
end

if (@chunk_key_tag ? 1 : 0) + @chunk_keys.size >= CHUNKING_FIELD_WARN_NUM
log.warn "many chunk keys specified, and it may cause too many chunks on your system."
end

# no chunk keys or only tags (chunking can be done without iterating event stream)
@simple_chunking = !@chunk_key_time && @chunk_keys.empty?

Expand Down
51 changes: 51 additions & 0 deletions test/plugin/test_output_as_buffered.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,57 @@ def waiting(seconds)
Timecop.return
end

sub_test_case 'buffered output configured with many chunk keys' do
setup do
@stored_global_logger = $log
$log = Fluent::Test::TestLogger.new
@hash = {
'flush_mode' => 'interval',
'flush_thread_burst_interval' => 0.01,
'chunk_limit_size' => 1024,
'timekey' => 60,
}
@i = create_output(:buffered)
end
teardown do
$log = @stored_global_logger
end
test 'nothing are warned with less chunk keys' do
chunk_keys = 'time,key1,key2,key3'
@i.configure(config_element('ROOT','',{},[config_element('buffer',chunk_keys,@hash)]))
logs = @i.log.out.logs.dup
@i.start
assert{ logs.select{|log| log.include?('[warn]') }.size == 0 }
end

test 'a warning reported with 4 chunk keys' do
chunk_keys = 'key1,key2,key3,key4'
@i.configure(config_element('ROOT','',{},[config_element('buffer',chunk_keys,@hash)]))
logs = @i.log.out.logs.dup

@i.start # this calls `log.reset`... capturing logs about configure must be done before this line
assert_equal ['key1', 'key2', 'key3', 'key4'], @i.chunk_keys

assert{ logs.select{|log| log.include?('[warn]: many chunk keys specified, and it may cause too many chunks on your system.') }.size == 1 }
end

test 'a warning reported with 4 chunk keys including "tag"' do
chunk_keys = 'tag,key1,key2,key3'
@i.configure(config_element('ROOT','',{},[config_element('buffer',chunk_keys,@hash)]))
logs = @i.log.out.logs.dup
@i.start # this calls `log.reset`... capturing logs about configure must be done before this line
assert{ logs.select{|log| log.include?('[warn]: many chunk keys specified, and it may cause too many chunks on your system.') }.size == 1 }
end

test 'time key is not included for warned chunk keys' do
chunk_keys = 'time,key1,key2,key3'
@i.configure(config_element('ROOT','',{},[config_element('buffer',chunk_keys,@hash)]))
logs = @i.log.out.logs.dup
@i.start
assert{ logs.select{|log| log.include?('[warn]') }.size == 0 }
end
end

sub_test_case 'buffered output feature without any buffer key, flush_mode: lazy' do
setup do
hash = {
Expand Down

0 comments on commit bec97a5

Please sign in to comment.