Skip to content

Commit f264c12

Browse files
Adds /health endpoint using the OKComputer gem
- Adds the OKComputer gem as a framework for health checking. - Configures checks for AR/migrations and Solr. - Checks are served as JSON on /health.
1 parent 9a96a9c commit f264c12

File tree

7 files changed

+42
-2
lines changed

7 files changed

+42
-2
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gem 'geoblacklight', '~> 4.4.2'
1313
gem 'importmap-rails'
1414
gem 'jbuilder'
1515
gem 'jquery-rails'
16+
gem 'okcomputer', '~> 1.19'
1617
gem 'omniauth'
1718
gem 'omniauth-cas', '3.0.0'
1819
gem 'omniauth-rails_csrf_protection', '~> 1.0'

Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ GEM
166166
faraday-retry (2.2.1)
167167
faraday (~> 2.0)
168168
ffi (1.17.0-aarch64-linux-gnu)
169+
ffi (1.17.0-arm64-darwin)
169170
ffi (1.17.0-x86_64-darwin)
170171
ffi (1.17.0-x86_64-linux-gnu)
171172
ffi (1.17.0-x86_64-linux-musl)
@@ -281,13 +282,16 @@ GEM
281282
nio4r (2.7.4)
282283
nokogiri (1.16.7-aarch64-linux)
283284
racc (~> 1.4)
285+
nokogiri (1.16.7-arm64-darwin)
286+
racc (~> 1.4)
284287
nokogiri (1.16.7-x86_64-darwin)
285288
racc (~> 1.4)
286289
nokogiri (1.16.7-x86_64-linux)
287290
racc (~> 1.4)
288291
oj (3.16.7)
289292
bigdecimal (>= 3.0)
290293
ostruct (>= 0.2)
294+
okcomputer (1.19.0)
291295
omniauth (2.1.2)
292296
hashie (>= 3.4.6)
293297
rack (>= 2.2.3)
@@ -542,6 +546,7 @@ DEPENDENCIES
542546
importmap-rails
543547
jbuilder
544548
jquery-rails
549+
okcomputer (~> 1.19)
545550
omniauth
546551
omniauth-cas (= 3.0.0)
547552
omniauth-rails_csrf_protection (~> 1.0)

config/initializers/okcomputer.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# initializers/okcomputer.rb
2+
# Health checks configuration
3+
4+
OkComputer.mount_at = false
5+
OkComputer.logger = Rails.logger
6+
OkComputer.check_in_parallel = true
7+
8+
# Check the Solr connection
9+
# Requires the ping handler on the solr core (<core>/admin/ping).
10+
core_baseurl = Blacklight.default_index.connection.uri.to_s.chomp('/')
11+
OkComputer::Registry.register 'solr', OkComputer::SolrCheck.new(core_baseurl)
12+
13+
# Check that DB migrations have run
14+
OkComputer::Registry.register 'database-migrations', OkComputer::ActiveRecordMigrationsCheck.new

config/routes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'okcomputer'
2+
13
Rails.application.routes.draw do
24
mount Blacklight::Engine => '/'
35
root to: 'catalog#index'
@@ -40,4 +42,8 @@
4042
concerns :gbl_downloadable
4143
end
4244
resources :download, only: [:show]
45+
46+
# Map OkComputer's /health/all.json to /health
47+
# Don't mount any other routes
48+
get "/health", to: "ok_computer/ok_computer#index", defaults: { format: :json }
4349
end

solr/geodata-test/solrconfig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
the PingRequestHandler.
183183
relative paths are resolved against the data dir
184184
-->
185-
<str name="healthcheckFile">server-enabled.txt</str>
185+
<!-- <str name="healthcheckFile">server-enabled.txt</str> -->
186186
</requestHandler>
187187

188188
<requestHandler name="/analysis/field"

solr/geodata/solrconfig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
the PingRequestHandler.
183183
relative paths are resolved against the data dir
184184
-->
185-
<str name="healthcheckFile">server-enabled.txt</str>
185+
<!-- <str name="healthcheckFile">server-enabled.txt</str> -->
186186
</requestHandler>
187187

188188
<requestHandler name="/analysis/field"

spec/requests/health_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe '/health', type: :request do
4+
it 'renders health checks' do
5+
get '/health'
6+
expect(response).to have_http_status :ok
7+
expect(response.parsed_body.keys).to match_array %w(
8+
default
9+
database
10+
database-migrations
11+
solr
12+
)
13+
end
14+
end

0 commit comments

Comments
 (0)