From 9dfe69d5e31295f2f435789b7bfa8a959da35fb6 Mon Sep 17 00:00:00 2001 From: zhouyu Date: Thu, 5 Feb 2026 14:31:46 -0800 Subject: [PATCH] Add additional health checks for external services --- Gemfile | 2 +- Gemfile.lock | 4 ++-- config/application.rb | 4 ++++ config/initializers/okcomputer.rb | 19 +++++++++++++++++++ spec/request/okcomputer_spec.rb | 16 +++++++++++++++- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 9eedd10d..a69eb312 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem 'berkeley_library-location', '~> 4.2.0' gem 'berkeley_library-logging', '~> 0.2', '>= 0.2.7' gem 'berkeley_library-marc', '~> 0.3.1' gem 'berkeley_library-tind', '~> 0.8.0' -gem 'berkeley_library-util', '~> 0.2.0' +gem 'berkeley_library-util', '~> 0.3' gem 'bootstrap' gem 'dotenv-rails', '~> 2.8.1', require: 'dotenv/rails-now' gem 'faraday' diff --git a/Gemfile.lock b/Gemfile.lock index 01b9af14..89a112d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -123,7 +123,7 @@ GEM rest-client (~> 2.1) rubyzip (~> 2.3, < 3.0) typesafe_enum (~> 0.3) - berkeley_library-util (0.2.0) + berkeley_library-util (0.3.0) berkeley_library-logging (~> 0.3) rest-client (~> 2.1) typesafe_enum (~> 0.3) @@ -511,7 +511,7 @@ DEPENDENCIES berkeley_library-logging (~> 0.2, >= 0.2.7) berkeley_library-marc (~> 0.3.1) berkeley_library-tind (~> 0.8.0) - berkeley_library-util (~> 0.2.0) + berkeley_library-util (~> 0.3) bootstrap brakeman bundle-audit diff --git a/config/application.rb b/config/application.rb index e80dbd00..d5fefb65 100644 --- a/config/application.rb +++ b/config/application.rb @@ -107,6 +107,10 @@ def log_active_storage_root!(active_storage_root) config.tind_base_uri = config.altmedia['tind_base_uri'] config.tind_api_key = config.altmedia['tind_api_key'] + config.hathiTrust_health_check_url = 'https://catalog.hathitrust.org/api/volumes/full/oclc/424023.json' + config.whois_health_check_url = 'https://whois.arin.net/rest/poc/1AD-ARIN' + config.berkeley_service_now_health_check_url = 'https://berkeley.service-now.com/kb_view.do?sysparm_article=KB0011960' + config.to_prepare do GoodJob::JobsController.class_eval do include AuthSupport diff --git a/config/initializers/okcomputer.rb b/config/initializers/okcomputer.rb index b61c407a..79d6ad82 100644 --- a/config/initializers/okcomputer.rb +++ b/config/initializers/okcomputer.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # Health check configuration +require 'berkeley_library/util/uris/head_check' OkComputer.logger = Rails.logger OkComputer.check_in_parallel = true @@ -26,3 +27,21 @@ def check # Ensure connectivity to the mail system. OkComputer::Registry.register 'action-mailer', OkComputer::ActionMailerCheck.new + +# Ensure TIND API is working. +tind_health_check_url = "#{Rails.application.config.tind_base_uri}api/v1/search?In=en" +OkComputer::Registry.register 'thind-api', BerkeleyLibrary::Util::HeadCheck.new(tind_health_check_url) + +# Ensure HathiTrust API is working. +OkComputer::Registry.register 'hathitrust-api', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.hathiTrust_health_check_url) + +# Ensure ARIN Whois API is working. +OkComputer::Registry.register 'whois-arin-api', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.whois_health_check_url) + +# Ensure Berkeley ServiceNow is accessible. +OkComputer::Registry.register 'berkeley-service-now', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.berkeley_service_now_health_check_url) + +# Ensure PayPal Payflow is accessible. +OkComputer::Registry.register 'paypal-payflow', OkComputer::HttpCheck.new(Rails.application.config.paypal_payflow_url) + +# Since the WorldCat API service requests dynamically generated OCLC tokens, we are not doing a health check for it. diff --git a/spec/request/okcomputer_spec.rb b/spec/request/okcomputer_spec.rb index fbf8d418..a06719b8 100644 --- a/spec/request/okcomputer_spec.rb +++ b/spec/request/okcomputer_spec.rb @@ -1,7 +1,15 @@ require 'rails_helper' RSpec.describe 'OKComputer', type: :request do - before { allow(Alma::User).to receive(:find).and_return(Alma::User.new) } + before do + allow(Alma::User).to receive(:find).and_return(Alma::User.new) + tind_health_check_url = "#{Rails.application.config.tind_base_uri}api/v1/search?In=en" + stub_request(:head, tind_health_check_url).to_return(status: 200) + stub_request(:head, Rails.application.config.whois_health_check_url).to_return(status: 200) + stub_request(:head, Rails.application.config.hathiTrust_health_check_url).to_return(status: 200) + stub_request(:head, Rails.application.config.berkeley_service_now_health_check_url).to_return(status: 200) + stub_request(:get, Rails.application.config.paypal_payflow_url).to_return(status: 200) + end it 'is mounted at /okcomputer' do get '/okcomputer' @@ -9,6 +17,7 @@ end it 'returns all checks to /health' do + get '/health' expect(response.parsed_body.keys).to match_array %w[ action-mailer @@ -16,6 +25,11 @@ default database database-migrations + thind-api + whois-arin-api + paypal-payflow + hathitrust-api + berkeley-service-now ] pending 'https://github.com/emmahsax/okcomputer/pull/21' expect(response).to have_http_status :ok