Skip to content

Commit 9dfe69d

Browse files
committed
Add additional health checks for external services
1 parent ba0dbd0 commit 9dfe69d

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ gem 'berkeley_library-location', '~> 4.2.0'
1010
gem 'berkeley_library-logging', '~> 0.2', '>= 0.2.7'
1111
gem 'berkeley_library-marc', '~> 0.3.1'
1212
gem 'berkeley_library-tind', '~> 0.8.0'
13-
gem 'berkeley_library-util', '~> 0.2.0'
13+
gem 'berkeley_library-util', '~> 0.3'
1414
gem 'bootstrap'
1515
gem 'dotenv-rails', '~> 2.8.1', require: 'dotenv/rails-now'
1616
gem 'faraday'

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ GEM
123123
rest-client (~> 2.1)
124124
rubyzip (~> 2.3, < 3.0)
125125
typesafe_enum (~> 0.3)
126-
berkeley_library-util (0.2.0)
126+
berkeley_library-util (0.3.0)
127127
berkeley_library-logging (~> 0.3)
128128
rest-client (~> 2.1)
129129
typesafe_enum (~> 0.3)
@@ -511,7 +511,7 @@ DEPENDENCIES
511511
berkeley_library-logging (~> 0.2, >= 0.2.7)
512512
berkeley_library-marc (~> 0.3.1)
513513
berkeley_library-tind (~> 0.8.0)
514-
berkeley_library-util (~> 0.2.0)
514+
berkeley_library-util (~> 0.3)
515515
bootstrap
516516
brakeman
517517
bundle-audit

config/application.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def log_active_storage_root!(active_storage_root)
107107
config.tind_base_uri = config.altmedia['tind_base_uri']
108108
config.tind_api_key = config.altmedia['tind_api_key']
109109

110+
config.hathiTrust_health_check_url = 'https://catalog.hathitrust.org/api/volumes/full/oclc/424023.json'
111+
config.whois_health_check_url = 'https://whois.arin.net/rest/poc/1AD-ARIN'
112+
config.berkeley_service_now_health_check_url = 'https://berkeley.service-now.com/kb_view.do?sysparm_article=KB0011960'
113+
110114
config.to_prepare do
111115
GoodJob::JobsController.class_eval do
112116
include AuthSupport

config/initializers/okcomputer.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
# Health check configuration
4+
require 'berkeley_library/util/uris/head_check'
45

56
OkComputer.logger = Rails.logger
67
OkComputer.check_in_parallel = true
@@ -26,3 +27,21 @@ def check
2627

2728
# Ensure connectivity to the mail system.
2829
OkComputer::Registry.register 'action-mailer', OkComputer::ActionMailerCheck.new
30+
31+
# Ensure TIND API is working.
32+
tind_health_check_url = "#{Rails.application.config.tind_base_uri}api/v1/search?In=en"
33+
OkComputer::Registry.register 'thind-api', BerkeleyLibrary::Util::HeadCheck.new(tind_health_check_url)
34+
35+
# Ensure HathiTrust API is working.
36+
OkComputer::Registry.register 'hathitrust-api', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.hathiTrust_health_check_url)
37+
38+
# Ensure ARIN Whois API is working.
39+
OkComputer::Registry.register 'whois-arin-api', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.whois_health_check_url)
40+
41+
# Ensure Berkeley ServiceNow is accessible.
42+
OkComputer::Registry.register 'berkeley-service-now', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.berkeley_service_now_health_check_url)
43+
44+
# Ensure PayPal Payflow is accessible.
45+
OkComputer::Registry.register 'paypal-payflow', OkComputer::HttpCheck.new(Rails.application.config.paypal_payflow_url)
46+
47+
# Since the WorldCat API service requests dynamically generated OCLC tokens, we are not doing a health check for it.

spec/request/okcomputer_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
require 'rails_helper'
22

33
RSpec.describe 'OKComputer', type: :request do
4-
before { allow(Alma::User).to receive(:find).and_return(Alma::User.new) }
4+
before do
5+
allow(Alma::User).to receive(:find).and_return(Alma::User.new)
6+
tind_health_check_url = "#{Rails.application.config.tind_base_uri}api/v1/search?In=en"
7+
stub_request(:head, tind_health_check_url).to_return(status: 200)
8+
stub_request(:head, Rails.application.config.whois_health_check_url).to_return(status: 200)
9+
stub_request(:head, Rails.application.config.hathiTrust_health_check_url).to_return(status: 200)
10+
stub_request(:head, Rails.application.config.berkeley_service_now_health_check_url).to_return(status: 200)
11+
stub_request(:get, Rails.application.config.paypal_payflow_url).to_return(status: 200)
12+
end
513

614
it 'is mounted at /okcomputer' do
715
get '/okcomputer'
816
expect(response).to have_http_status :ok
917
end
1018

1119
it 'returns all checks to /health' do
20+
1221
get '/health'
1322
expect(response.parsed_body.keys).to match_array %w[
1423
action-mailer
1524
alma-patron-lookup
1625
default
1726
database
1827
database-migrations
28+
thind-api
29+
whois-arin-api
30+
paypal-payflow
31+
hathitrust-api
32+
berkeley-service-now
1933
]
2034
pending 'https://github.com/emmahsax/okcomputer/pull/21'
2135
expect(response).to have_http_status :ok

0 commit comments

Comments
 (0)