Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions lib/fluent/plugin/in_exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ExecInput < Fluent::Plugin::Input
config_param :tag, :string, default: nil
desc 'The interval time between periodic program runs.'
config_param :run_interval, :time, default: nil
desc 'Command (program) execution timeout.'
config_param :command_timeout, :time, default: nil
desc 'The default block size to read if parser requires partial read.'
config_param :read_block_size, :size, default: 10240 # 10k
desc 'The encoding to receive the result of the command, especially for non-ascii characters.'
Expand Down Expand Up @@ -86,9 +88,9 @@ def start
options[:external_encoding] = @encoding if @encoding

if @run_interval
child_process_execute(:exec_input, @command, interval: @run_interval, **options, &method(:run))
child_process_execute(:exec_input, @command, interval: @run_interval, wait_timeout: @command_timeout, **options, &method(:run))
else
child_process_execute(:exec_input, @command, immediate: true, **options, &method(:run))
child_process_execute(:exec_input, @command, immediate: true, wait_timeout: @command_timeout, **options, &method(:run))
end
end

Expand Down
43 changes: 43 additions & 0 deletions test/plugin/test_in_exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,47 @@ def create_driver(conf)
assert_match(/LoadError/, event[2]['message'])
end
end
sub_test_case 'command_timeout' do
test 'configure command_timeout' do
d = create_driver %[
command ruby -e "sleep 10"
tag test
run_interval 1s
command_timeout 1s
<parse>
@type none
</parse>
]
assert_equal 1.0, d.instance.command_timeout
end

test 'command_timeout kills long-running child process' do
d = create_driver %[
command ruby -e "sleep 10"
tag test
run_interval 5s
command_timeout 1s
<parse>
@type none
</parse>
]
start_time = Time.now
d.run(timeout: 3)
elapsed = Time.now - start_time

assert elapsed < 4, "command should have been killed by command_timeout"
Comment thread
zoklk marked this conversation as resolved.
Outdated
end

test 'command_timeout defaults to nil' do
d = create_driver %[
command ruby -e "puts 'hello'"
tag test
run_interval 1s
<parse>
@type none
</parse>
]
assert_nil d.instance.command_timeout
end
end
end
Loading