Skip to content

Commit

Permalink
Merge pull request #2920 from ashie/issue-2915
Browse files Browse the repository at this point in the history
Allow to launch fluentd from `C:\Program Files\`
  • Loading branch information
repeatedly committed Apr 10, 2020
2 parents 2d50f34 + 5c129dd commit b461266
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 14 deletions.
11 changes: 7 additions & 4 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,11 @@ def build_system_config(conf)
RUBY_ENCODING_OPTIONS_REGEX = %r{\A(-E|--encoding=|--internal-encoding=|--external-encoding=)}.freeze

def build_spawn_command
fluentd_spawn_cmd = [ServerEngine.ruby_bin_path]
if ENV['TEST_RUBY_PATH']
fluentd_spawn_cmd = [ENV['TEST_RUBY_PATH']]
else
fluentd_spawn_cmd = [ServerEngine.ruby_bin_path]
end

rubyopt = ENV['RUBYOPT']
if rubyopt
Expand All @@ -897,10 +901,9 @@ def build_spawn_command

# Adding `-h` so that it can avoid ruby's command blocking
# e.g. `ruby -Eascii-8bit:ascii-8bit` will block. but `ruby -Eascii-8bit:ascii-8bit -h` won't.
cmd = fluentd_spawn_cmd.join(' ')
_, e, s = Open3.capture3("#{cmd} -h")
_, e, s = Open3.capture3(*fluentd_spawn_cmd, "-h")
if s.exitstatus != 0
$log.error('Invalid option is passed to RUBYOPT', command: cmd, error: e)
$log.error('Invalid option is passed to RUBYOPT', command: fluentd_spawn_cmd, error: e)
exit s.exitstatus
end

Expand Down
67 changes: 57 additions & 10 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TestFluentdCommand < ::Test::Unit::TestCase
FileUtils.mkdir_p(TMP_DIR)
@supervisor_pid = nil
@worker_pids = []
ENV["TEST_RUBY_PATH"] = nil
end

def process_exist?(pid)
Expand Down Expand Up @@ -98,7 +99,8 @@ def eager_read(io)

def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout: 10, env: {})
matched = false
assert_error_msg = "matched correctly"
matched_wrongly = false
assert_error_msg = ""
stdio_buf = ""
begin
execute_command(cmdline, TMP_DIR, env) do |pid, stdout|
Expand Down Expand Up @@ -128,23 +130,36 @@ def assert_log_matches(cmdline, *pattern_list, patterns_not_match: [], timeout:
end
end
rescue Timeout::Error
assert_error_msg = "execution timeout with command out:\n" + stdio_buf
assert_error_msg = "execution timeout"
rescue => e
assert_error_msg = "unexpected error in launching fluentd: #{e.inspect}\n" + stdio_buf
assert_error_msg = "unexpected error in launching fluentd: #{e.inspect}"
else
assert_error_msg = "log doesn't match" unless matched
end
assert matched, assert_error_msg

unless patterns_not_match.empty?
if patterns_not_match.empty?
assert_error_msg = build_message(assert_error_msg,
"<?>\nwas expected to include:\n<?>",
stdio_buf, pattern_list)
else
lines = stdio_buf.split("\n")
patterns_not_match.each do |ptn|
matched_wrongly = if ptn.is_a? Regexp
lines.any?{|line| ptn.match(line) }
else
lines.any?{|line| line.include?(ptn) }
end
assert_false matched_wrongly, "pattern exists in logs wrongly:\n" + stdio_buf
if matched_wrongly
assert_error_msg << "\n" unless assert_error_msg.empty?
assert_error_msg << "pattern exists in logs wrongly: #{ptn}"
end
end
assert_error_msg = build_message(assert_error_msg,
"<?>\nwas expected to include:\n<?>\nand not include:\n<?>",
stdio_buf, pattern_list, patterns_not_match)
end

assert matched && !matched_wrongly, assert_error_msg
end

def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 10)
Expand Down Expand Up @@ -842,8 +857,7 @@ def multi_workers_ready?
'-external-encoding' => '--external-encoding=utf-8',
'-internal-encoding' => '--internal-encoding=utf-8',
)
test "-E option is set to RUBYOPT3" do |opt|
omit "hard to run correctly on Windows. Need to debug." if Fluent.windows?
test "-E option is set to RUBYOPT" do |opt|
conf = <<CONF
<source>
@type dummy
Expand All @@ -854,6 +868,7 @@ def multi_workers_ready?
</match>
CONF
conf_path = create_conf_file('rubyopt_test.conf', conf)
opt << " #{ENV['RUBYOPT']}" if ENV['RUBYOPT']
assert_log_matches(
create_cmdline(conf_path),
*opt.split(' '),
Expand All @@ -862,7 +877,7 @@ def multi_workers_ready?
)
end

test "without RUBYOPT" do
test "without RUBYOPT" do
conf = <<CONF
<source>
@type dummy
Expand All @@ -877,7 +892,7 @@ def multi_workers_ready?
end

test 'invalid values are set to RUBYOPT' do
omit "hard to run correctly on Windows. Need to debug." if Fluent.windows?
omit "hard to run correctly because RUBYOPT=-r/path/to/bundler/setup is required on Windows while this test set invalid RUBYOPT" if Fluent.windows?
conf = <<CONF
<source>
@type dummy
Expand All @@ -895,6 +910,38 @@ def multi_workers_ready?
)
end

# https://github.com/fluent/fluentd/issues/2915
test "ruby path contains spaces" do
conf = <<CONF
<source>
@type dummy
tag dummy
</source>
<match>
@type null
</match>
CONF
ruby_path = ServerEngine.ruby_bin_path
tmp_ruby_path = File.join(TMP_DIR, "ruby with spaces")
if Fluent.windows?
tmp_ruby_path << ".bat"
File.open(tmp_ruby_path, "w") do |file|
file.write "#{ruby_path} %*"
end
else
FileUtils.ln_sf(ruby_path, tmp_ruby_path)
end
ENV["TEST_RUBY_PATH"] = tmp_ruby_path
cmd_path = File.expand_path(File.dirname(__FILE__) + "../../../bin/fluentd")
conf_path = create_conf_file('space_mixed_ruby_path_test.conf', conf)
args = ["bundle", "exec", tmp_ruby_path, cmd_path, "-c", conf_path]
assert_log_matches(
args,
'spawn command to main:',
'-Eascii-8bit:ascii-8bit'
)
end

test 'success to start workers when file buffer is configured in non-workers way only for specific worker' do
conf = <<CONF
<system>
Expand Down

0 comments on commit b461266

Please sign in to comment.