Skip to content

Commit

Permalink
out_file: add warn message for symlink_path setting (#4502)
Browse files Browse the repository at this point in the history
Backported from 74b2e3d.

Signed-off-by: Shingo Nakayama <[email protected]>
Signed-off-by: Daijiro Fukuda <[email protected]>
Co-authored-by: Daijiro Fukuda <[email protected]>
  • Loading branch information
Shingo-Nakayama and daipom committed May 29, 2024
1 parent aeed909 commit c0c4814
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/fluent/plugin/out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ def configure(conf)
log.warn "symlink_path is unavailable on Windows platform. disabled."
@symlink_path = nil
else
placeholder_validators(:symlink_path, @symlink_path).reject{ |v| v.type == :time }.each do |v|
begin
v.validate!
rescue Fluent::ConfigError => e
log.warn "#{e}. This means multiple chunks are competing for a single symlink_path, so some logs may not be taken from the symlink."
end
end

@buffer.extend SymlinkBufferMixin
@buffer.symlink_path = @symlink_path
@buffer.output_plugin_for_symlink = self
Expand Down
22 changes: 21 additions & 1 deletion test/plugin/test_out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def create_driver(conf = CONFIG, opts = {})
'path' => "#{TMP_DIR}/${tag}/${type}/conf_test.%Y%m%d.%H%M.log",
'add_path_suffix' => 'false',
'append' => "true",
'symlink_path' => "#{TMP_DIR}/conf_test.current.log",
'symlink_path' => "#{TMP_DIR}/${tag}/conf_test.current.log",
'compress' => 'gzip',
'recompress' => 'true',
}, [
Expand Down Expand Up @@ -183,6 +183,26 @@ def create_driver(conf = CONFIG, opts = {})
Fluent::Test::Driver::Output.new(Fluent::Plugin::NullOutput).configure(conf)
end
end

test 'warning for symlink_path not including correct placeholders corresponding to chunk keys' do
omit "Windows doesn't support symlink" if Fluent.windows?
conf = config_element('match', '**', {
'path' => "#{TMP_DIR}/${tag}/${key1}/${key2}/conf_test.%Y%m%d.%H%M.log",
'symlink_path' => "#{TMP_DIR}/conf_test.current.log",
}, [
config_element('buffer', 'time,tag,key1,key2', {
'@type' => 'file',
'timekey' => '1d',
'path' => "#{TMP_DIR}/buf_conf_test",
}),
])
assert_nothing_raised do
d = create_driver(conf)
assert do
d.logs.count { |log| log.include?("multiple chunks are competing for a single symlink_path") } == 2
end
end
end
end

sub_test_case 'fully configured output' do
Expand Down

0 comments on commit c0c4814

Please sign in to comment.