From 195268878d97b51d062ba4cf65063ccc53c53da0 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Thu, 20 Nov 2025 12:59:31 -0800 Subject: [PATCH] Add health checks using the OKComputer gem - Add the OKComputer gem as a framework for health checking. - Configure checks for ActiveRecord, Migrations, and Solr. - Set up OKComputer's default routes, plus a route for /health which runs all checks and returns JSON (consistent with our other apps). --- Gemfile | 1 + Gemfile.lock | 5 +++++ config/initializers/okcomputer.rb | 13 +++++++++++++ config/routes.rb | 5 +++++ solr/geodata-test/solrconfig.xml | 2 +- solr/geodata/solrconfig.xml | 2 +- spec/requests/okcomputer_spec.rb | 19 +++++++++++++++++++ 7 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 config/initializers/okcomputer.rb create mode 100644 spec/requests/okcomputer_spec.rb diff --git a/Gemfile b/Gemfile index 84ae83b..a2c2e90 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem 'geoblacklight', '~> 4.4.2' gem 'importmap-rails' gem 'jbuilder' gem 'jquery-rails' +gem 'okcomputer', '~> 1.19' gem 'omniauth' gem 'omniauth-cas', '3.0.0' gem 'omniauth-rails_csrf_protection', '~> 1.0' diff --git a/Gemfile.lock b/Gemfile.lock index 1d09208..bfd1708 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -166,6 +166,7 @@ GEM faraday-retry (2.2.1) faraday (~> 2.0) ffi (1.17.0-aarch64-linux-gnu) + ffi (1.17.0-arm64-darwin) ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-linux-gnu) ffi (1.17.0-x86_64-linux-musl) @@ -281,6 +282,8 @@ GEM nio4r (2.7.4) nokogiri (1.16.7-aarch64-linux) racc (~> 1.4) + nokogiri (1.16.7-arm64-darwin) + racc (~> 1.4) nokogiri (1.16.7-x86_64-darwin) racc (~> 1.4) nokogiri (1.16.7-x86_64-linux) @@ -288,6 +291,7 @@ GEM oj (3.16.7) bigdecimal (>= 3.0) ostruct (>= 0.2) + okcomputer (1.19.0) omniauth (2.1.2) hashie (>= 3.4.6) rack (>= 2.2.3) @@ -542,6 +546,7 @@ DEPENDENCIES importmap-rails jbuilder jquery-rails + okcomputer (~> 1.19) omniauth omniauth-cas (= 3.0.0) omniauth-rails_csrf_protection (~> 1.0) diff --git a/config/initializers/okcomputer.rb b/config/initializers/okcomputer.rb new file mode 100644 index 0000000..2a41f10 --- /dev/null +++ b/config/initializers/okcomputer.rb @@ -0,0 +1,13 @@ +# initializers/okcomputer.rb +# Health checks configuration + +OkComputer.logger = Rails.logger +OkComputer.check_in_parallel = true + +# Check that DB migrations have run +OkComputer::Registry.register 'database-migrations', OkComputer::ActiveRecordMigrationsCheck.new + +# Check the Solr connection +# Requires the ping handler on the solr core (/admin/ping). +core_baseurl = Blacklight.default_index.connection.uri.to_s.chomp('/') +OkComputer::Registry.register 'solr', OkComputer::SolrCheck.new(core_baseurl) diff --git a/config/routes.rb b/config/routes.rb index ad08510..eed3e14 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +require 'okcomputer' + Rails.application.routes.draw do mount Blacklight::Engine => '/' root to: 'catalog#index' @@ -40,4 +42,7 @@ concerns :gbl_downloadable end resources :download, only: [:show] + + # Map OkComputer's /health/all.json to /health + get '/health', to: 'ok_computer/ok_computer#index', defaults: { format: :json } end diff --git a/solr/geodata-test/solrconfig.xml b/solr/geodata-test/solrconfig.xml index 5987ce4..bc012ef 100644 --- a/solr/geodata-test/solrconfig.xml +++ b/solr/geodata-test/solrconfig.xml @@ -182,7 +182,7 @@ the PingRequestHandler. relative paths are resolved against the data dir --> - server-enabled.txt + - server-enabled.txt +