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 not to check tag and variable placeholders when configured as secondary #1338

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
44 changes: 30 additions & 14 deletions lib/fluent/plugin/out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,41 @@ def configure(conf)
end

path_suffix = @add_path_suffix ? @path_suffix : ''
@path_template = generate_path_template(@path, @buffer_config.timekey, @append, @compress_method, path_suffix: path_suffix, time_slice_format: configured_time_slice_format)

placeholder_validate!(:path, @path_template)

max_tag_index = get_placeholders_tag(@path_template).max || 1
max_tag_index = 1 if max_tag_index < 1
dummy_tag = (['a'] * max_tag_index).join('.')
dummy_record_keys = get_placeholders_keys(@path_template) || ['message']
dummy_record = Hash[dummy_record_keys.zip(['data'] * dummy_record_keys.size)]

test_meta1 = metadata_for_test(dummy_tag, Fluent::Engine.now, dummy_record)
test_path = extract_placeholders(@path_template, test_meta1)
unless ::Fluent::FileUtil.writable_p?(test_path)
raise Fluent::ConfigError, "out_file: `#{test_path}` is not writable"
path_timekey = if @chunk_key_time
@as_secondary ? @primary_instance.buffer_config.timekey : @buffer_config.timekey
else
nil
end
@path_template = generate_path_template(@path, path_timekey, @append, @compress_method, path_suffix: path_suffix, time_slice_format: configured_time_slice_format)

if @as_secondary
# When this plugin is configured as secondary & primary plugin has tag key, but this plugin may not have it.
# Increment placeholder can make another output file per chunk tag/keys even if original path doesn't include it.
placeholder_validators(:path, @path_template).select{|v| v.type == :time }.each do |v|
v.validate!
end
else
placeholder_validate!(:path, @path_template)

max_tag_index = get_placeholders_tag(@path_template).max || 1
max_tag_index = 1 if max_tag_index < 1
dummy_tag = (['a'] * max_tag_index).join('.')
dummy_record_keys = get_placeholders_keys(@path_template) || ['message']
dummy_record = Hash[dummy_record_keys.zip(['data'] * dummy_record_keys.size)]

test_meta1 = metadata_for_test(dummy_tag, Fluent::Engine.now, dummy_record)
test_path = extract_placeholders(@path_template, test_meta1)
unless ::Fluent::FileUtil.writable_p?(test_path)
raise Fluent::ConfigError, "out_file: `#{test_path}` is not writable"
end
end

@formatter = formatter_create

if @symlink_path && @buffer.respond_to?(:path)
if @as_secondary
raise Fluent::ConfigError, "symlink_path option is unavailable in <secondary>: consider to use secondary_file plugin"
end
if Fluent.windows?
log.warn "symlink_path is unavailable on Windows platform. disabled."
@symlink_path = nil
Expand Down
17 changes: 17 additions & 0 deletions test/plugin/test_out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ def create_driver(conf = CONFIG)
create_driver(conf)
end
end

test 'configured as secondary with primary using chunk_key_tag and not using chunk_key_time' do
require 'fluent/plugin/out_null'
port = unused_port
conf = config_element('match', '**', {
}, [
config_element('buffer', 'tag', {
}),
config_element('secondary', '', {
'@type' => 'file',
'path' => "#{TMP_DIR}/testing_to_dump_by_out_file",
}),
])
assert_nothing_raised do
Fluent::Test::Driver::Output.new(Fluent::Plugin::NullOutput).configure(conf)
end
end
end

sub_test_case 'fully configured output' do
Expand Down