Skip to content

Commit b819ccf

Browse files
authored
buffer: warn if default timekey (1d) will be used (#5276)
**Which issue(s) this PR fixes**: Fixes # **What this PR does / why we need it**: By default, the value of timekey interval was set as interval 1d. Without changing flush related parameters, it will not be flushed at all in that period. This behavior is intentional design, but it might be surprised in some use cases. So, in some doubtful use-case, emit warning for it. ``` Before: no buffer configuration # no warning <buffer> @type file # no warning </buffer> <buffer time> @type file # no warning </buffer> <buffer []> @type file # no warning </buffer> After: no buffer configuration # warning <buffer> @type file # warning </buffer> <buffer time> @type file # warning </buffer> <buffer []> @type file # no warning </buffer> ``` **Docs Changes**: N/A **Release Note**: N/A Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
1 parent 7a3ebf6 commit b819ccf

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

lib/fluent/plugin/out_file.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,17 @@ def configure(conf)
117117
configured_time_slice_format = conf['time_slice_format']
118118

119119
if conf.elements(name: 'buffer').empty?
120+
# no <buffer> section, default time chunk key and timekey (1d) will be used.
121+
log.warn "default timekey interval (1d) will be used because of missing <buffer> section. To change the output frequency, please modify the timekey value"
122+
120123
conf.add_element('buffer', 'time')
124+
else
125+
unless conf.elements(name: 'buffer').first.has_key?('timekey')
126+
if conf.elements(name: 'buffer').first.arg != "[]"
127+
# with <buffer> section (except <buffer []>), and no timekey
128+
log.warn "default timekey interval (1d) will be used. To change the output frequency, please modify the timekey value"
129+
end
130+
end
121131
end
122132
buffer_conf = conf.elements(name: 'buffer').first
123133
# Fluent::PluginId#configure is not called yet, so we can't use #plugin_root_dir here.

test/command/test_fluentd.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,4 +1712,52 @@ def create_config_include_dir_configuration(config_path, config_dir, yaml_format
17121712
expected_warning_message)
17131713
end
17141714
end
1715+
1716+
sub_test_case "test suspicious timekey interval (1d) in out_file configuration" do
1717+
data('without buffer' => {buffer: nil, buffer_arg: nil, message: :missing_buffer},
1718+
'buffer' => {buffer: true, buffer_arg: '', message: :warning},
1719+
'buffer time' => {buffer: true, buffer_arg: 'time', message: :warning},
1720+
'buffer []' => {buffer: true, buffer_arg: '[]', message: nil})
1721+
test 'warn the default value of timekey (1d) is used as-is' do |data|
1722+
prefix = "default timekey interval (1d) will be used"
1723+
advice = "To change the output frequency, please modify the timekey value"
1724+
missing_warning = "#{prefix} because of missing <buffer> section. #{advice}"
1725+
warning = "#{prefix}. #{advice}"
1726+
1727+
conf_path = if data[:buffer]
1728+
create_conf_file("warning.conf", <<~EOF)
1729+
<system>
1730+
config_include_dir ""
1731+
</system>
1732+
<match>
1733+
@type file
1734+
tag test
1735+
path #{@tmp_dir}/test.log
1736+
<buffer #{data[:buffer_arg]}>
1737+
@type file
1738+
</buffer>
1739+
</match>
1740+
EOF
1741+
else
1742+
create_conf_file("warning.conf", <<~EOF)
1743+
<system>
1744+
config_include_dir ""
1745+
</system>
1746+
<match>
1747+
@type file
1748+
tag test
1749+
path #{@tmp_dir}/test.log
1750+
</match>
1751+
EOF
1752+
end
1753+
case data[:message]
1754+
when :missing_buffer
1755+
assert_log_matches(create_cmdline(conf_path, '--dry-run'), missing_warning, patterns_not_match: [warning])
1756+
when :warning
1757+
assert_log_matches(create_cmdline(conf_path, '--dry-run'), "warning", patterns_not_match: [missing_warning])
1758+
else
1759+
assert_log_matches(create_cmdline(conf_path, '--dry-run'), patterns_not_match: [warning, missing_warning])
1760+
end
1761+
end
1762+
end
17151763
end

0 commit comments

Comments
 (0)