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 a bug not to use plugin root directory for buffer path even if configured correctly #1417

Merged
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
9 changes: 5 additions & 4 deletions lib/fluent/plugin/out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ def configure(conf)

configured_time_slice_format = conf['time_slice_format']

# v0.14 file buffer handles path as directory if '*' is missing
# 'dummy_path' is not to raise configuration error for 'path' in file buffer plugin,
# but raise it in this plugin.
if conf.elements(name: 'buffer').empty?
conf.add_element('buffer', 'time')
end
buffer_conf = conf.elements(name: 'buffer').first
unless buffer_conf.has_key?('path')
# Fluent::PluginId#configure is not called yet, so we can't use #plugin_root_dir here.
if !buffer_conf.has_key?('path') && !(conf['@id'] && system_config.root_dir)
# v0.14 file buffer handles path as directory if '*' is missing
# 'dummy_path' is not to raise configuration error for 'path' in file buffer plugin,
# but raise it in this plugin.
buffer_conf['path'] = conf['path'] || '/tmp/dummy_path'
end

Expand Down
26 changes: 24 additions & 2 deletions test/plugin/test_out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def setup
utc
]

def create_driver(conf = CONFIG)
Fluent::Test::Driver::Output.new(Fluent::Plugin::FileOutput).configure(conf)
def create_driver(conf = CONFIG, opts = {})
Fluent::Test::Driver::Output.new(Fluent::Plugin::FileOutput, opts: opts).configure(conf)
end

sub_test_case 'configuration' do
Expand All @@ -37,7 +37,29 @@ def create_driver(conf = CONFIG)
assert_equal :gzip, d.instance.instance_eval{ @compress_method }
end

test 'using root_dir for buffer path' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does test_out_file have tests for buffer_conf['path'] = conf['path'] || '/tmp/dummy_path' line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just configuration error for config_param :path (in out_file), so it's clear that out_file raises configuration error for missing path...
But anyway, i added it.

system_conf_opts = {'root_dir' => File.join(TMP_DIR, 'testrootdir')}
buf_conf = config_element('buffer', '', {'flush_interval' => '1s'})
conf = config_element('match', '**', {'@id' => 'myout', 'path' => 'test_path', 'append' => 'true'}, [buf_conf])
d = create_driver(conf, system_conf_opts)

assert_equal 'test_path', d.instance.path
assert d.instance.append

assert d.instance.buffer.respond_to?(:path) # file buffer
assert_equal 1, d.instance.buffer_config.flush_interval

assert_equal File.join(TMP_DIR, 'testrootdir', 'worker0', 'myout'), d.instance.plugin_root_dir

buffer_path_under_root_dir = File.join(TMP_DIR, 'testrootdir', 'worker0', 'myout', 'buffer', 'buffer.*.log')
assert_equal buffer_path_under_root_dir, d.instance.buffer.path
end

test 'path should be writable' do
assert_raise(Fluent::ConfigError.new("'path' parameter is required")) do
create_driver ""
end

assert_nothing_raised do
create_driver %[path #{TMP_DIR}/test_path]
end
Expand Down