Add runner management health check for /ping
Even though we can check the health of the runner management, we would like to ensure an external health check validates the availability of all required services.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PingController < ApplicationController
|
||||
before_action :postgres_connected!
|
||||
before_action :postgres_connected!, :runner_manager_healthy!
|
||||
after_action :verify_authorized, except: %i[index]
|
||||
|
||||
def index
|
||||
@ -20,4 +20,11 @@ class PingController < ApplicationController
|
||||
|
||||
raise ActiveRecord::ConnectionNotEstablished
|
||||
end
|
||||
|
||||
def runner_manager_healthy!
|
||||
# any unhandled exception leads to a HTTP 500 response.
|
||||
return if Runner.strategy_class.health == true
|
||||
|
||||
raise Runner::Error::InternalServerError
|
||||
end
|
||||
end
|
||||
|
@ -53,6 +53,10 @@ class Runner::Strategy
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def self.health
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def self.release
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
@ -153,6 +153,16 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
||||
end
|
||||
end
|
||||
|
||||
def self.health
|
||||
url = "#{config[:url]}/ping"
|
||||
response = Faraday.get(url)
|
||||
JSON.parse(response.body)['message'] == 'Pong'
|
||||
rescue Faraday::Error => e
|
||||
raise Runner::Error::FaradayError.new("Request to DockerContainerPool failed: #{e.inspect}")
|
||||
rescue JSON::ParserError => e
|
||||
raise Runner::Error::UnexpectedResponse.new("DockerContainerPool returned invalid JSON: #{e.inspect}")
|
||||
end
|
||||
|
||||
def self.release
|
||||
url = "#{config[:url]}/docker_container_pool/dump_info"
|
||||
response = Faraday.get(url)
|
||||
|
@ -45,6 +45,10 @@ class Runner::Strategy::Null < Runner::Strategy
|
||||
|
||||
def self.config; end
|
||||
|
||||
def self.health
|
||||
true
|
||||
end
|
||||
|
||||
def self.release
|
||||
'N/A'
|
||||
end
|
||||
|
@ -216,6 +216,22 @@ class Runner::Strategy::Poseidon < Runner::Strategy
|
||||
@config ||= CodeOcean::Config.new(:code_ocean).read[:runner_management] || {}
|
||||
end
|
||||
|
||||
def self.health
|
||||
url = "#{config[:url]}/health"
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Checking health from #{url}" }
|
||||
response = http_connection.get url
|
||||
case response.status
|
||||
when 204
|
||||
true
|
||||
else
|
||||
raise Runner::Error::UnexpectedResponse.new("Poseidon sent unexpected response status code #{response.status}")
|
||||
end
|
||||
rescue Faraday::Error => e
|
||||
raise Runner::Error::FaradayError.new("Request to Poseidon failed: #{e.inspect}")
|
||||
ensure
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Finished getting health information" }
|
||||
end
|
||||
|
||||
def self.release
|
||||
url = "#{config[:url]}/version"
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Getting release from #{url}" }
|
||||
|
Reference in New Issue
Block a user