Skip to content

Commit

Permalink
add /healthcheck endpoint for okcomputer (#1054)
Browse files Browse the repository at this point in the history
* add /healthcheck endpoint for okcomputer

* you're killing me rubo
  • Loading branch information
rococodogs authored Sep 5, 2023
1 parent 74ea5eb commit 9056152
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RUN bundle config unset with && \
ENTRYPOINT ["/spot/bin/spot-entrypoint.sh"]
CMD ["bundle", "exec", "rails", "server", "-b", "ssl://0.0.0.0:443?key=/spot/tmp/ssl/application.key&cert=/spot/tmp/ssl/application.crt"]

HEALTHCHECK CMD curl -skf https://localhost || exit 1
HEALTHCHECK CMD curl -skf https://localhost/healthcheck/default || exit 1

##
# Target: spot-asset-builder
Expand Down
42 changes: 2 additions & 40 deletions config/initializers/okcomputer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,12 @@
#
# Configuration for OkComputer, an engine to register system healthchecks

module Spot
class CantaloupeCheck < ::OkComputer::HttpCheck
require 'json'
require 'openssl'

def check
response = JSON.parse(perform_request)
message = case response['color']
when 'GREEN' then 'Cantaloupe check successful!'
when 'YELLOW' then "WARNING: #{response['message']}"
when 'RED' then "ERROR: #{response['message']}"
end
mark_message(message)
mark_failure unless response['color'] == 'GREEN'
rescue => e
mark_message("Error: '#{e}'")
mark_failure
end
end

def perform_request
Timeout.timeout(request_timeout) do
options = { read_timeout: request_timeout }

options[:http_basic_authentication] = basic_auth_options if basic_auth_options.any?
options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE

url.read(options)
end
rescue => e
raise ConnectionFailed, e
end
end

# by default, OkComputer mounts at `/okcomputer`. setting this to `false`
# lets us mount it manually (and at a different endpoint) in config/routes.rb
OkComputer.mount_at = false

OkComputer.check_in_parallel = true

solr_config = Rails.application.config_for(:solr)
fcrepo_config = Rails.application.config_for(:fedora)
redis_config = Rails.application.config_for(:redis)
Expand All @@ -57,13 +25,7 @@ def perform_request
OkComputer::Registry.register('solr', OkComputer::SolrCheck.new(solr_config['url'])) if solr_config['url']
OkComputer::Registry.register('redis', OkComputer::RedisCheck.new(redis_config)) if redis_config.present?
OkComputer::Registry.register('fedora', OkComputer::HttpCheck.new(fcrepo_uri)) if fcrepo_uri
OkComputer::Registry.register('cantaloupe', Spot::CantaloupeCheck.new("#{ENV['URL_HOST']}/iiif/health")) if ENV['URL_HOST'].present?

sidekiq_config.fetch(:queues, []).each do |queue|
OkComputer::Registry.register "sidekiq :#{queue}", OkComputer::SidekiqLatencyCheck.new(queue.to_sym)
end

if ENV['FITS_SERVLET_URL'].present?
fits_url = "#{ENV['FITS_SERVLET_URL']}/version"
OkComputer::Registry.register 'fits (servlet)', OkComputer::HttpCheck.new(fits_url)
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
mount BlacklightAdvancedSearch::Engine => '/'
mount Hydra::RoleManagement::Engine => '/admin'
mount Hyrax::Engine, at: '/'
mount OkComputer::Engine, at: '/healthcheck'
mount Sidekiq::Web => '/sidekiq'
mount Qa::Engine => '/authorities'

Expand Down

0 comments on commit 9056152

Please sign in to comment.