Skip to content

Commit b5c7d5a

Browse files
Ap 527 healthcheck (#11)
* AP-527 Move healthchecks to OkComputer * Renaming class to fit with zeitwerk * Tweak collector spec having ordering issues * Fixed request spec * a number of improvements based on code review feedback(logging, key names, error messages, etc) * Remove unnecessary system spec and a little cleanup * Remove ordered expects from process files * Remove ALL ordered expects * Update change log
1 parent a8026f4 commit b5c7d5a

25 files changed

Lines changed: 832 additions & 659 deletions

.yarnrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# yarn lockfile v1
33

44

5-
lastUpdateCheck 1762849565021
5+
lastUpdateCheck 1770150293563

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.7.8 (xxxx-xx-xx)
2+
3+
* Implement OKComputer for healthchecks
4+
* Refactor collector_spec to not include brittle ".ordered" expectations
5+
16
# 1.7.5 (2025-12-17)
27

38
* Hotfix for release workflow issue

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ gem 'jsbundling-rails'
1717
gem 'jwt', '~> 2.2'
1818
# Workaround for https://github.com/alexspeller/non-stupid-digest-assets/issues/54
1919
gem 'non-stupid-digest-assets', git: 'https://github.com/BerkeleyLibrary/non-stupid-digest-assets.git', ref: '1de0c38'
20+
gem 'okcomputer', '~> 1.19', '>= 1.19.1'
2021
gem 'omniauth-cas', '~> 2.0'
2122
gem 'pagy', '~> 5.6'
2223
gem 'pg', '~> 1.2'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ GEM
7979
amazing_print (1.4.0)
8080
ast (2.4.2)
8181
awesome_print (1.9.2)
82+
benchmark (0.5.0)
8283
berkeley_library-alma (0.0.7.1)
8384
berkeley_library-logging (~> 0.2)
8485
berkeley_library-marc (~> 0.3.1)
@@ -217,6 +218,8 @@ GEM
217218
nokogiri (1.15.2-x86_64-linux)
218219
racc (~> 1.4)
219220
oj (3.14.3)
221+
okcomputer (1.19.1)
222+
benchmark
220223
omniauth (1.9.2)
221224
hashie (>= 3.4.6)
222225
rack (>= 1.6.2, < 3)
@@ -411,6 +414,7 @@ DEPENDENCIES
411414
jwt (~> 2.2)
412415
listen
413416
non-stupid-digest-assets!
417+
okcomputer (~> 1.19, >= 1.19.1)
414418
omniauth-cas (~> 2.0)
415419
pagy (~> 5.6)
416420
pg (~> 1.2)

app/controllers/health_controller.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/lib/health/check.rb

Lines changed: 0 additions & 149 deletions
This file was deleted.

app/lib/health/result.rb

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/lib/health/status.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/lib/health_checks.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module HealthChecks
4+
CHECK_FILES = %w[
5+
iiif_server_check
6+
lending_root_path
7+
test_item_exists
8+
].freeze
9+
10+
CHECK_FILES.each do |name|
11+
require File.join(__dir__, "health_checks/#{name}")
12+
end
13+
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module HealthChecks
2+
class IIIFServerCheck < OkComputer::Check
3+
include BerkeleyLibrary::Logging
4+
5+
def check
6+
result = validate_iiif_server
7+
mark_message result[:message]
8+
mark_failure if result[:failure]
9+
rescue StandardError => e
10+
logger.error(e)
11+
mark_message e.class.name
12+
mark_failure
13+
end
14+
15+
private
16+
17+
def iiif_connection
18+
@iiif_connection ||= Faraday.new do |f|
19+
f.options.open_timeout = 2
20+
f.options.timeout = 3
21+
end
22+
end
23+
24+
def iiif_test_uri
25+
base_uri = Lending::Config.iiif_base_uri
26+
return unless base_uri
27+
28+
item = Item.active.first || Item.inactive.first
29+
return unless item
30+
31+
BerkeleyLibrary::Util::URIs.append(
32+
base_uri,
33+
item.iiif_directory.first_image_url_path,
34+
'info.json'
35+
)
36+
end
37+
38+
# Returns a hash with :message and :failure keys
39+
def validate_iiif_server
40+
test_uri = iiif_test_uri
41+
return { message: 'Unable to construct test image URI', failure: true } unless test_uri
42+
43+
response = iiif_connection.head(test_uri)
44+
return { message: "HEAD #{test_uri} returned status #{response.status}", failure: true } unless response.success?
45+
46+
acao_header = response.headers['Access-Control-Allow-Origin']
47+
return { message: "HEAD #{test_uri} missing Access-Control-Allow-Origin header", failure: true } if acao_header.blank?
48+
49+
{ message: 'IIIF server reachable', failure: false }
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)