GRN2-xx: Removed Health Check Gem (#840)

* Initial work on removing health check gem

* Added health checks

* Fixed gemfile
This commit is contained in:
Ahmad Farhat 2019-10-21 12:09:31 -04:00 committed by Jesus Federico
parent 9c9867b4e7
commit 933408f68b
5 changed files with 75 additions and 52 deletions

View File

@ -71,9 +71,6 @@ gem 'http_accept_language'
# Markdown parsing.
gem 'redcarpet'
# For health check endpoint
gem "health_check"
# For limiting access based on user roles
gem 'cancancan', '~> 2.0'

View File

@ -137,8 +137,6 @@ GEM
activesupport (>= 4.2.0)
hashdiff (0.4.0)
hashie (3.6.0)
health_check (3.0.0)
railties (>= 5.0)
hiredis (0.6.3)
http_accept_language (2.1.1)
i18n (1.6.0)
@ -363,7 +361,6 @@ DEPENDENCIES
factory_bot_rails
faker
font-awesome-sass (~> 5.9.0)
health_check
hiredis
http_accept_language
i18n-language-mapping (~> 0.1.0)

View File

@ -0,0 +1,74 @@
# frozen_string_literal: true
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
class HealthCheckController < ApplicationController
skip_before_action :redirect_to_https, :set_user_domain, :set_user_settings, :maintenance_mode?, :migration_error?,
:user_locale, :check_admin_password, :check_user_role
# GET /health_check
def all
response = "success"
@cache_expire = 10.seconds
begin
cache_check
database_check
email_check
rescue => e
response = "Health Check Failure: #{e}"
end
render plain: response
end
private
def cache_check
if Rails.cache.write("__health_check_cache_write__", "true", expires_in: @cache_expire)
raise "Unable to read from cache" unless Rails.cache.read("__health_check_cache_write__") == "true"
else
raise "Unable to write to cache"
end
end
def database_check
if defined?(ActiveRecord)
raise "Database not responding" unless ActiveRecord::Migrator.current_version
end
raise "Pending migrations" unless ActiveRecord::Migration.check_pending!.nil?
end
def email_check
test_smtp if Rails.configuration.action_mailer.delivery_method == :smtp
end
def test_smtp
settings = ActionMailer::Base.smtp_settings
smtp = Net::SMTP.new(settings[:address], settings[:port])
if settings[:enable_starttls_auto] == "true"
smtp.enable_starttls_auto if smtp.respond_to?(:enable_starttls_auto)
end
smtp.start(settings[:domain]) do |s|
s.authenticate(settings[:user_name], settings[:password], settings[:authentication])
end
rescue => e
raise "Unable to connect to SMTP Server - #{e}"
end
end

View File

@ -1,45 +0,0 @@
# frozen_string_literal: true
# Health check to monitor the status of the rails server
HealthCheck.setup do |config|
# uri prefix (no leading slash)
config.uri = 'health_check'
# Text output upon success
config.success = 'success'
# Timeout in seconds used when checking smtp server
config.smtp_timeout = 30.0
# http status code used when plain text error message is output
# Set to 200 if you want your want to distinguish between partial (text does not include success) and
# total failure of rails application (http status of 500 etc)
config.http_status_for_error_text = 500
# http status code used when an error object is output (json or xml)
# Set to 200 if you want your want to distinguish between partial (healthy property == false) and
# total failure of rails application (http status of 500 etc)
config.http_status_for_error_object = 500
# You can customize which checks happen on a standard health check, eg to set an explicit list use:
config.standard_checks = %w(database migrations emailconf db-migration)
# You can set what tests are run with the 'full' or 'all' parameter
config.full_checks = %w(database migrations email cache)
config.add_custom_check('db-migration') do
# any code that returns blank on success and non blank string upon failure
ENV["DB_MIGRATE_FAILED"].blank? ? "" : "Database migration failed"
end
# max-age of response in seconds
# cache-control is public when max_age > 1 and basic_auth_username is not set
# You can force private without authentication for longer max_age by
# setting basic_auth_username but not basic_auth_password
config.max_age = 1
# http status code used when the ip is not allowed for the request
config.http_status_for_ip_whitelist_error = 403
end

View File

@ -17,7 +17,7 @@
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
Rails.application.routes.draw do
get 'health_check', to: 'health_check/health_check#index'
get '/health_check', to: 'health_check#all'
# Error routes.
match '/401', to: 'errors#unauthorized', via: :all, as: :unauthorized