Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ gem 'lograge', '>=0.11.2'
gem 'mutex_m'
gem 'netaddr', '~> 1.5', '>= 1.5.1'
gem 'net-ssh'
gem 'okcomputer', '~> 1.19'
gem 'omniauth', '~> 1.9', '>= 1.9.2'
gem 'omniauth-cas', '~> 2.0'
gem 'pg', '~> 1.2'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ GEM
execjs (~> 2)
awesome_print (1.9.2)
base64 (0.3.0)
benchmark (0.5.0)
berkeley_library-alma (0.1.1)
berkeley_library-logging (~> 0.2)
berkeley_library-marc (~> 0.3.1)
Expand Down Expand Up @@ -258,6 +259,8 @@ GEM
oj (3.16.11)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
okcomputer (1.19.1)
benchmark
omniauth (1.9.2)
hashie (>= 3.4.6)
rack (>= 1.6.2, < 3)
Expand Down Expand Up @@ -500,6 +503,7 @@ DEPENDENCIES
mutex_m
net-ssh
netaddr (~> 1.5, >= 1.5.1)
okcomputer (~> 1.19)
omniauth (~> 1.9, >= 1.9.2)
omniauth-cas (~> 2.0)
pg (~> 1.2)
Expand Down
8 changes: 0 additions & 8 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
# We'll likely be asked to remove this at some point, but for now it's useful
# to have in development.
class HomeController < ApplicationController

# TODO: Move this to a HealthController that extends ActionController::API
# - note: may involve extracting some of ApplicationController into a mixin
def health
check = Health::Check.new
render json: check, status: check.http_status_code
end

def admin
render :admin if require_framework_admin!
end
Expand Down
57 changes: 0 additions & 57 deletions app/lib/health/check.rb

This file was deleted.

28 changes: 0 additions & 28 deletions app/lib/health/result.rb

This file was deleted.

23 changes: 0 additions & 23 deletions app/lib/health/status.rb

This file was deleted.

28 changes: 28 additions & 0 deletions config/initializers/okcomputer.rb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general comment that doesn't need to block merging: do we need checks on other external services? the list i'm thinking of here is tind, paypal, worldcat, hathitrust, whois.arin.net, and berkeley servicenow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree that more external service checks would be useful, if for nothing more than a way to say "yes, our connection to XYZ is down". I figure these can be added as time permits. Checking ARIN will likely be easier than TIND, which will both be easier than PayPal, for example.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# Health check configuration

OkComputer.logger = Rails.logger
OkComputer.check_in_parallel = true

class AlmaPatronCheck < OkComputer::Check
TEST_PATRON_ID = '000311@lbl.gov'

def check
Alma::User.find(TEST_PATRON_ID)
mark_message 'Success'
rescue StandardError => e
mark_failure
Rails.logger.warn "Couldn't connect to Alma API during health check: #{e}"
mark_message 'Failed'
end
end

# Ensure Alma API is working.
OkComputer::Registry.register 'alma-patron-lookup', AlmaPatronCheck.new

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

# Ensure connectivity to the mail system.
OkComputer::Registry.register 'action-mailer', OkComputer::ActionMailerCheck.new
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
root to: redirect('/forms/altmedia/new')

get 'admin', to: 'home#admin'
get 'health', to: 'home#health'
get 'health', to: 'ok_computer/ok_computer#index', defaults: { format: :json }
get 'home', to: 'home#index'
get 'build_info', to: 'home#build_info'

Expand Down
9 changes: 0 additions & 9 deletions lib/tasks/health.rake

This file was deleted.

28 changes: 0 additions & 28 deletions spec/lib/health/status_spec.rb

This file was deleted.

35 changes: 0 additions & 35 deletions spec/request/home_request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,6 @@
require 'calnet_helper'

describe HomeController, type: :request do
describe :health do
it 'returns OK for a successful patron lookup' do
patron = Alma::User.new

expect(Alma::User).to receive(:find).with(Health::Check::TEST_PATRON_ID).and_return(patron)
get health_path
expect(response).to have_http_status(:ok)
expected_body = {
'status' => 'pass',
'details' => {
'patron_api:find' => {
'status' => 'pass'
}
}
}
expect(JSON.parse(response.body)).to eq(expected_body)
end

it 'returns 429 Too Many Requests for a failure' do
expect(Alma::User).to receive(:find).and_raise('Something went wrong')
get health_path
expect(response).to have_http_status(:too_many_requests)
expected_body = {
'status' => 'warn',
'details' => {
'patron_api:find' => {
'status' => 'warn',
'output' => 'RuntimeError'
}
}
}
expect(JSON.parse(response.body)).to eq(expected_body)
end
end

RSpec.shared_examples 'allow admin' do |page:|

before do
Expand Down
29 changes: 29 additions & 0 deletions spec/request/okcomputer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rails_helper'

RSpec.describe 'OKComputer', type: :request do
before { allow(Alma::User).to receive(:find).and_return(Alma::User.new) }

it 'is mounted at /okcomputer' do
get '/okcomputer'
expect(response).to have_http_status :ok
end

it 'returns all checks to /health' do
get '/health'
expect(response.parsed_body.keys).to match_array %w[
action-mailer
alma-patron-lookup
default
database
database-migrations
]
pending 'https://github.com/emmahsax/okcomputer/pull/21'
expect(response).to have_http_status :ok
end

it 'fails when Alma lookups fail' do
expect(Alma::User).to receive(:find).and_raise('Uh oh!')
get '/health'
expect(response).not_to have_http_status :ok
end
end
8 changes: 0 additions & 8 deletions spec/system/home_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
require 'support/build_info_context'

describe :home, type: :system do
describe :health do
it 'does something sensible for a general error' do
expect(Health::Check).to receive(:new).and_raise('Something went wrong')
visit health_path
expect(page).to have_content('Internal Server Error')
end
end

describe :admin do
context 'without login' do
it 'redirects to login' do
Expand Down