diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 3fe47c90c4..9863296d6f 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -79,6 +79,8 @@ def initialize config_param :open_on_every_update, :bool, default: false desc 'Limit the watching files that the modification time is within the specified time range (when use \'*\' in path).' config_param :limit_recently_modified, :time, default: nil + desc 'Enable the option to skip the refresh of watching list on startup.' + config_param :skip_refresh_on_startup, :bool, default: false attr_reader :paths @@ -160,7 +162,7 @@ def start @pf = PositionFile.parse(@pf_file) end - refresh_watchers + refresh_watchers unless @skip_refresh_on_startup timer_execute(:in_tail_refresh_watchers, @refresh_interval, &method(:refresh_watchers)) end diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 590c5016c5..ac4bf205eb 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -1198,4 +1198,19 @@ def test_limit_recently_modified assert_equal expected_files, plugin.expand_paths.sort end end + + def test_skip_refresh_on_startup + FileUtils.touch("#{TMP_DIR}/tail.txt") + config = config_element('', '', { + 'format' => 'none', + 'refresh_interval' => 1, + 'skip_refresh_on_startup' => true + }) + d = create_driver(config) + d.run(shutdown: false) {} + assert_equal 0, d.instance.instance_variable_get(:@tails).keys.size + # detect a file at first execution of in_tail_refresh_watchers timer + waiting(5) { sleep 0.1 until d.instance.instance_variable_get(:@tails).keys.size == 1 } + d.instance_shutdown + end end