Skip to content

Commit

Permalink
Merge pull request #3108 from fluent/fix-3091
Browse files Browse the repository at this point in the history
in_exec: Add connect_mode parameter to read stderr. fix #3091
  • Loading branch information
repeatedly authored Aug 25, 2020
2 parents 3b760f5 + 58c6140 commit 45a12aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit 45a12aa

Please sign in to comment.