#8004 fix load order to start webserver after pipeline

Fixes #9398
This commit is contained in:
Tamara Braun 2017-10-22 14:02:45 +02:00 committed by Armin Braun
parent 57e7a8a56b
commit d919e93322
5 changed files with 21 additions and 29 deletions

View file

@ -84,12 +84,12 @@ class LogStash::Agent
@thread = Thread.current # this var is implicitly used by Stud.stop? @thread = Thread.current # this var is implicitly used by Stud.stop?
logger.debug("Starting agent") logger.debug("Starting agent")
start_webserver
transition_to_running transition_to_running
converge_state_and_update converge_state_and_update
start_webserver
if auto_reload? if auto_reload?
# `sleep_then_run` instead of firing the interval right away # `sleep_then_run` instead of firing the interval right away
Stud.interval(@reload_interval, :sleep_then_run => true) do Stud.interval(@reload_interval, :sleep_then_run => true) do

View file

@ -20,14 +20,12 @@ def wait_for_port(port, retry_attempts)
end end
def is_port_open?(port) def is_port_open?(port)
begin TCPSocket.open("localhost", port) do
s = TCPSocket.open("localhost", port)
s.close
return true return true
end
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
return false return false
end end
end
def send_data(port, data) def send_data(port, data)
socket = TCPSocket.new("127.0.0.1", port) socket = TCPSocket.new("127.0.0.1", port)

View file

@ -17,7 +17,7 @@ class LogstashService < Service
SETTINGS_CLI_FLAG = "--path.settings" SETTINGS_CLI_FLAG = "--path.settings"
STDIN_CONFIG = "input {stdin {}} output { }" STDIN_CONFIG = "input {stdin {}} output { }"
RETRY_ATTEMPTS = 10 RETRY_ATTEMPTS = 60
@process = nil @process = nil
@ -115,7 +115,6 @@ class LogstashService < Service
@env_variables.map { |k, v| @process.environment[k] = v} unless @env_variables.nil? @env_variables.map { |k, v| @process.environment[k] = v} unless @env_variables.nil?
@process.io.inherit! @process.io.inherit!
@process.start @process.start
wait_for_logstash
puts "Logstash started with PID #{@process.pid}" if @process.alive? puts "Logstash started with PID #{@process.pid}" if @process.alive?
end end
end end
@ -164,12 +163,13 @@ class LogstashService < Service
tries = RETRY_ATTEMPTS tries = RETRY_ATTEMPTS
while tries > 0 while tries > 0
if is_port_open? if is_port_open?
break return
else else
sleep 1 sleep 1
end end
tries -= 1 tries -= 1
end end
raise "Logstash REST API did not come up after #{RETRY_ATTEMPTS}s."
end end
# this method only overwrites existing config with new config # this method only overwrites existing config with new config

View file

@ -69,7 +69,6 @@ describe "Test that Logstash" do
test_env["LOGSTASH_KEYSTORE_PASS"] = "WRONG_PASSWRD" test_env["LOGSTASH_KEYSTORE_PASS"] = "WRONG_PASSWRD"
@logstash.env_variables = test_env @logstash.env_variables = test_env
@logstash.spawn_logstash("-e", "input {generator { count => 1 }} output { }", "--path.settings", settings_dir) @logstash.spawn_logstash("-e", "input {generator { count => 1 }} output { }", "--path.settings", settings_dir)
@logstash.wait_for_logstash
try(num_retries) do try(num_retries) do
expect(@logstash.exited?).to be(true) expect(@logstash.exited?).to be(true)
end end
@ -83,7 +82,6 @@ describe "Test that Logstash" do
test_env["LOGSTASH_KEYSTORE_PASS"] = "WRONG_PASSWRD" test_env["LOGSTASH_KEYSTORE_PASS"] = "WRONG_PASSWRD"
@logstash.env_variables = test_env @logstash.env_variables = test_env
@logstash.spawn_logstash("-e", "input {generator { count => 1 }} output { }", "--path.settings", settings_dir) @logstash.spawn_logstash("-e", "input {generator { count => 1 }} output { }", "--path.settings", settings_dir)
@logstash.wait_for_logstash
try(num_retries) do try(num_retries) do
expect(@logstash.exited?).to be(true) expect(@logstash.exited?).to be(true)
end end
@ -97,7 +95,6 @@ describe "Test that Logstash" do
test_env["LOGSTASH_KEYSTORE_PASS"] = "keystore_pa9454w3rd" test_env["LOGSTASH_KEYSTORE_PASS"] = "keystore_pa9454w3rd"
@logstash.env_variables = test_env @logstash.env_variables = test_env
@logstash.spawn_logstash("-e", "input {stdin {}} output { }", "--path.settings", settings_dir) @logstash.spawn_logstash("-e", "input {stdin {}} output { }", "--path.settings", settings_dir)
@logstash.wait_for_logstash
try(num_retries) do try(num_retries) do
expect(@logstash.exited?).to be(true) expect(@logstash.exited?).to be(true)
end end

View file

@ -127,11 +127,8 @@ describe "Test Logstash instance whose default settings are overridden" do
http_port = random_port http_port = random_port
change_setting("http.port", http_port) change_setting("http.port", http_port)
@logstash_service.spawn_logstash("-e", tcp_config) @logstash_service.spawn_logstash("-e", tcp_config)
@logstash_service.wait_for_logstash wait_for_port(http_port, 60)
try(num_retries) do
expect(is_port_open?(http_port)).to be true expect(is_port_open?(http_port)).to be true
end
# check LS is up and running with new data path # check LS is up and running with new data path
try(num_retries) do try(num_retries) do
expect(is_port_open?(test_port)).to be true expect(is_port_open?(test_port)).to be true