Skip to content

Commit f8e0075

Browse files
committed
AP-521: convert health checks to okcomputer
1 parent b872878 commit f8e0075

File tree

14 files changed

+81
-321
lines changed

14 files changed

+81
-321
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gem 'berkeley_library-logging', '~> 0.2'
1111
gem 'browser', '~> 4.2'
1212
gem 'jbuilder', '~> 2.7'
1313
gem 'non-stupid-digest-assets', '~> 1.0' # Allow static pages (e.g. 404.html) to link to compiled assets
14+
gem 'okcomputer', '~> 1.19'
1415
gem 'omniauth-cas', '~> 2.0'
1516
gem 'puma', '~> 5.3', '>= 5.3.1'
1617
gem 'rails', '~> 7.0.4'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ GEM
7070
public_suffix (>= 2.0.2, < 6.0)
7171
amazing_print (1.5.0)
7272
ast (2.4.2)
73+
benchmark (0.5.0)
7374
berkeley_library-av-core (0.4.3)
7475
berkeley_library-logging (~> 0.2)
7576
berkeley_library-marc (~> 0.2, >= 0.2.1)
@@ -187,6 +188,8 @@ GEM
187188
non-stupid-digest-assets (1.0.9)
188189
sprockets (>= 2.0)
189190
oj (3.16.1)
191+
okcomputer (1.19.1)
192+
benchmark
190193
omniauth (1.9.2)
191194
hashie (>= 3.4.6)
192195
rack (>= 1.6.2, < 3)
@@ -368,6 +371,7 @@ DEPENDENCIES
368371
jbuilder (~> 2.7)
369372
listen (>= 3.0)
370373
non-stupid-digest-assets (~> 1.0)
374+
okcomputer (~> 1.19)
371375
omniauth-cas (~> 2.0)
372376
puma (~> 5.3, >= 5.3.1)
373377
rails (~> 7.0.4)

app/controllers/player_controller.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'active_record'
22
require 'berkeley_library/av/core'
3-
require 'health/check'
43

54
class PlayerController < ApplicationController
65

@@ -35,11 +34,6 @@ def access_restricted(exception)
3534
}
3635
end
3736

38-
def health
39-
check = Health::Check.new
40-
render json: check, status: check.http_status_code
41-
end
42-
4337
def preview
4438
render locals: { tracks: preview_tracks }
4539
end

app/lib/health/check.rb

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

app/lib/health/result.rb

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

app/lib/health/status.rb

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

config/initializers/okcomputer.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
# Health check configuration
4+
5+
OkComputer.logger = Rails.logger
6+
OkComputer.check_in_parallel = true
7+
8+
ALMA_TEST_ID = 'b23305522'
9+
TIND_TEST_ID = '(pacradio)01469'
10+
WOWZA_TEST_COLL = 'Pacifica'
11+
WOWZA_TEST_PATH = 'PRA_NHPRC1_AZ1084_00_000_00.mp3'
12+
13+
ALMA_TEST_URL = BerkeleyLibrary::AV::Metadata::Source::ALMA.marc_uri_for(ALMA_TEST_ID).to_s
14+
WOWZA_TEST_URL = BerkeleyLibrary::AV::Track.hls_uri_for(collection: WOWZA_TEST_COLL, relative_path: WOWZA_TEST_PATH).to_s
15+
16+
class TindCheck < OkComputer::Check
17+
def check
18+
_ = BerkeleyLibrary::AV::Record.from_metadata(collection: WOWZA_TEST_COLL, record_id: TIND_TEST_ID)
19+
mark_message 'Authenticated TIND HTTP check successful'
20+
rescue BerkeleyLibrary::AV::RecordNotFound
21+
mark_failure
22+
mark_message("Authenticated TIND HTTP check failed: record #{TIND_TEST_ID} not found")
23+
rescue StandardError => e
24+
mark_failure
25+
mark_message("Authenticated TIND HTTP check failed: #{e}")
26+
end
27+
end
28+
29+
# Ensure Alma and TIND APIs are working.
30+
OkComputer::Registry.register 'alma-metadata', OkComputer::HttpCheck.new(ALMA_TEST_URL)
31+
OkComputer::Registry.register 'tind-metadata', TindCheck.new
32+
33+
# Ensure Wowza is working
34+
OkComputer::Registry.register 'wowza-streaming', OkComputer::HttpCheck.new(WOWZA_TEST_URL)

config/routes.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
get '/:collection/:record_id', to: 'player#show', as: :player
1212

1313
defaults format: 'json' do
14-
# TODO: separate HealthController
15-
get '/health', to: 'player#health'
14+
get '/health', to: 'ok_computer/ok_computer#index'
1615
end
1716

1817
# Expects query string: collection=<collection>&relative_path=<paths>, where

lib/tasks/health.rake

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

spec/data/playlist.m3u8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#EXTM3U
2+
#EXT-X-VERSION:3
3+
#EXT-X-STREAM-INF:BANDWIDTH=170413,CODECS="mp4a.40.34"
4+
chunklist_w600161955.m3u8

0 commit comments

Comments
 (0)