Skip to content

Commit 238ba38

Browse files
authored
Add health monitor gem (#228)
- This application does not have Honeybadger, so skipping the Honeybadger notification Closes #213
1 parent 80964fe commit 238ba38

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ group :development do
9090
end
9191

9292
gem 'dockerfile-rails', '>= 1.6', group: :development
93+
94+
gem 'health-monitor-rails', '~> 12.3'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ GEM
149149
fiber-storage (1.0.0)
150150
globalid (1.2.1)
151151
activesupport (>= 6.1)
152+
health-monitor-rails (12.3.0)
153+
railties (>= 6.1)
152154
i18n (1.14.5)
153155
concurrent-ruby (~> 1.0)
154156
importmap-rails (2.0.1)
@@ -390,6 +392,7 @@ GEM
390392
PLATFORMS
391393
aarch64-linux
392394
arm64-darwin-21
395+
arm64-darwin-23
393396
x86_64-darwin-20
394397
x86_64-linux
395398

@@ -406,6 +409,7 @@ DEPENDENCIES
406409
debug
407410
dockerfile-rails (>= 1.6)
408411
ed25519
412+
health-monitor-rails (~> 12.3)
409413
importmap-rails
410414
jbuilder
411415
kaminari
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
Rails.application.config.after_initialize do
4+
HealthMonitor.configure do |config|
5+
# Make this health check available at /health
6+
config.path = :health
7+
8+
config.error_callback = proc do |e|
9+
Rails.logger.error "Health check failed with: #{e.message}"
10+
end
11+
end
12+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
Rails.application.routes.draw do
4+
mount HealthMonitor::Engine, at: '/'
5+
46
root 'welcome#index'
57
get '/welcome/index'
68
get '/filing_rules', to: 'welcome#filing_rules'

db/schema.rb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/requests/health_check_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe 'Health Check' do
6+
describe 'GET /health' do
7+
it 'has a health check' do
8+
get '/health.json'
9+
expect(response).to be_successful
10+
end
11+
end
12+
13+
context 'with a bad database configuration' do
14+
before do
15+
allow_any_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).to receive(:execute) do |instance|
16+
raise StandardError if database.blank? || instance.pool.db_config.name == database.to_s
17+
end
18+
end
19+
20+
it 'errors' do
21+
get '/health.json'
22+
expect(response).not_to be_successful
23+
expect(response).to have_http_status :service_unavailable
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)