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

in_exec: Add connect_mode parameter to read stderr. fix #3091 #3108

Merged
merged 1 commit into from
Aug 25, 2020
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
6 changes: 4 additions & 2 deletions lib/fluent/plugin/in_exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ExecInput < Fluent::Plugin::Input

desc 'The command (program) to execute.'
config_param :command, :string
desc 'Specify connect mode to executed process'
config_param :connect_mode, :enum, list: [:read, :read_with_stderr], default: :read

config_section :parse do
config_set_default :@type, 'tsv'
Expand Down Expand Up @@ -72,9 +74,9 @@ def start
super

if @run_interval
child_process_execute(:exec_input, @command, interval: @run_interval, mode: [:read], &method(:run))
child_process_execute(:exec_input, @command, interval: @run_interval, mode: [@connect_mode], &method(:run))
else
child_process_execute(:exec_input, @command, immediate: true, mode: [:read], &method(:run))
child_process_execute(:exec_input, @command, immediate: true, mode: [@connect_mode], &method(:run))
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/plugin/test_in_exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,22 @@ def create_driver(conf)
assert_equal [tag, time, record], event
}
end

test 'emit error message with read_with_stderr' do
d = create_driver %[
tag test
command ruby #{File.join(File.dirname(SCRIPT_PATH), 'foo_bar_baz_no_existence.rb')}
connect_mode read_with_stderr
<parse>
@type none
</parse>
]
d.run(expect_records: 1, timeout: 10)

assert{ d.events.length > 0 }
d.events.each do |event|
assert_equal 'test', event[0]
assert_match /LoadError/, event[2]['message']
end
end
end