Skip to content

Commit

Permalink
Add health monitor gem (#228)
Browse files Browse the repository at this point in the history
- This application does not have Honeybadger, so skipping the Honeybadger notification

Closes #213
  • Loading branch information
maxkadel authored Nov 4, 2024
1 parent 80964fe commit 238ba38
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ group :development do
end

gem 'dockerfile-rails', '>= 1.6', group: :development

gem 'health-monitor-rails', '~> 12.3'
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ GEM
fiber-storage (1.0.0)
globalid (1.2.1)
activesupport (>= 6.1)
health-monitor-rails (12.3.0)
railties (>= 6.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
importmap-rails (2.0.1)
Expand Down Expand Up @@ -390,6 +392,7 @@ GEM
PLATFORMS
aarch64-linux
arm64-darwin-21
arm64-darwin-23
x86_64-darwin-20
x86_64-linux

Expand All @@ -406,6 +409,7 @@ DEPENDENCIES
debug
dockerfile-rails (>= 1.6)
ed25519
health-monitor-rails (~> 12.3)
importmap-rails
jbuilder
kaminari
Expand Down
12 changes: 12 additions & 0 deletions config/initializers/health_monitor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

Rails.application.config.after_initialize do
HealthMonitor.configure do |config|
# Make this health check available at /health
config.path = :health

config.error_callback = proc do |e|
Rails.logger.error "Health check failed with: #{e.message}"
end
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

Rails.application.routes.draw do
mount HealthMonitor::Engine, at: '/'

root 'welcome#index'
get '/welcome/index'
get '/filing_rules', to: 'welcome#filing_rules'
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions spec/requests/health_check_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Health Check' do
describe 'GET /health' do
it 'has a health check' do
get '/health.json'
expect(response).to be_successful
end
end

context 'with a bad database configuration' do
before do
allow_any_instance_of(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).to receive(:execute) do |instance|
raise StandardError if database.blank? || instance.pool.db_config.name == database.to_s
end
end

it 'errors' do
get '/health.json'
expect(response).not_to be_successful
expect(response).to have_http_status :service_unavailable
end
end
end

0 comments on commit 238ba38

Please sign in to comment.