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

Skip the refresh of watching list on startup. #1487

Merged
merged 1 commit into from
Mar 6, 2017
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
4 changes: 3 additions & 1 deletion lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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