Skip to content

Commit c703c97

Browse files
authored
AP-534: Add additional health checks for external services (#13)
1 parent e163b60 commit c703c97

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
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.x.healthcheck_urls.hathiTrust = 'https://catalog.hathitrust.org/api/volumes/full/oclc/424023.json'
111+
config.x.healthcheck_urls.whois = 'https://whois.arin.net/rest/poc/1AD-ARIN'
112+
config.x.healthcheck_urls.berkeley_service_now = '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: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
require 'net/smtp'
4+
require 'berkeley_library/util/uris/head_check'
45

56
# Health check configuration
6-
77
OkComputer.logger = Rails.logger
88
OkComputer.check_in_parallel = true
99

@@ -58,11 +58,29 @@ def check
5858
end
5959
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
6060

61+
# Ensure SMTP can connect
62+
OkComputer::Registry.register 'mail-connectivity', MailConnectivityCheck.new if ActionMailer::Base.delivery_method == :smtp
63+
6164
# Ensure Alma API is working.
6265
OkComputer::Registry.register 'alma-patron-lookup', AlmaPatronCheck.new
6366

6467
# Ensure database migrations have been run.
6568
OkComputer::Registry.register 'database-migrations', OkComputer::ActiveRecordMigrationsCheck.new
6669

67-
# Ensure SMTP can connect
68-
OkComputer::Registry.register 'mail-connectivity', MailConnectivityCheck.new if ActionMailer::Base.delivery_method == :smtp
70+
# Ensure TIND API is working.
71+
tind_health_check_url = "#{Rails.application.config.tind_base_uri}api/v1/search?In=en"
72+
OkComputer::Registry.register 'tind-api', BerkeleyLibrary::Util::HeadCheck.new(tind_health_check_url)
73+
74+
# Ensure HathiTrust API is working.
75+
OkComputer::Registry.register 'hathitrust-api', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.x.healthcheck_urls.hathiTrust)
76+
77+
# Ensure ARIN Whois API is working.
78+
OkComputer::Registry.register 'whois-arin-api', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.x.healthcheck_urls.whois)
79+
80+
# Ensure Berkeley ServiceNow is accessible.
81+
OkComputer::Registry.register 'berkeley-service-now', BerkeleyLibrary::Util::HeadCheck.new(Rails.application.config.x.healthcheck_urls.berkeley_service_now)
82+
83+
# Ensure PayPal Payflow is accessible.
84+
OkComputer::Registry.register 'paypal-payflow', OkComputer::HttpCheck.new(Rails.application.config.paypal_payflow_url)
85+
86+
# 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
RSpec.describe 'OKComputer', type: :request do
44
before do
55
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.x.healthcheck_urls.whois).to_return(status: 200)
9+
stub_request(:head, Rails.application.config.x.healthcheck_urls.hathiTrust).to_return(status: 200)
10+
stub_request(:head, Rails.application.config.x.healthcheck_urls.berkeley_service_now).to_return(status: 200)
11+
stub_request(:get, Rails.application.config.paypal_payflow_url).to_return(status: 200)
612
end
713

814
it 'is mounted at /okcomputer' do
@@ -25,6 +31,11 @@
2531
database
2632
alma-patron-lookup
2733
database-migrations
34+
tind-api
35+
whois-arin-api
36+
paypal-payflow
37+
hathitrust-api
38+
berkeley-service-now
2839
]
2940
end
3041
end
@@ -45,6 +56,11 @@
4556
database
4657
alma-patron-lookup
4758
database-migrations
59+
tind-api
60+
whois-arin-api
61+
paypal-payflow
62+
hathitrust-api
63+
berkeley-service-now
4864
mail-connectivity
4965
]
5066
end

0 commit comments

Comments
 (0)