From a9be611d0012d1891596e0bac97eaa2392118ec6 Mon Sep 17 00:00:00 2001 From: John Ma Date: Fri, 12 Oct 2018 15:57:53 -0400 Subject: [PATCH] Fixed #269 Add health-check endpoint (GRN-3) (#290) * * * * --- Gemfile | 3 ++ Gemfile.lock | 3 ++ config/initializers/health_check.rb | 49 +++++++++++++++++++++++++++++ config/routes.rb | 2 ++ 4 files changed, 57 insertions(+) create mode 100644 config/initializers/health_check.rb diff --git a/Gemfile b/Gemfile index f3710da2..e20c06e7 100644 --- a/Gemfile +++ b/Gemfile @@ -66,6 +66,9 @@ gem 'http_accept_language' # Markdown parsing. gem 'redcarpet' +# For health check endpoint +gem "health_check" + group :production do # Use a postgres database in production. gem 'pg', '~> 0.18' diff --git a/Gemfile.lock b/Gemfile.lock index 458f2783..0401dd50 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -97,6 +97,8 @@ GEM activesupport (>= 4.2.0) hashdiff (0.3.7) hashie (3.5.7) + health_check (3.0.0) + railties (>= 5.0) http-cookie (1.0.3) domain_name (~> 0.5) http_accept_language (2.1.1) @@ -327,6 +329,7 @@ DEPENDENCIES dotenv-rails factory_bot_rails faker + health_check http_accept_language jbuilder (~> 2.5) jquery-rails diff --git a/config/initializers/health_check.rb b/config/initializers/health_check.rb new file mode 100644 index 00000000..44fd9203 --- /dev/null +++ b/config/initializers/health_check.rb @@ -0,0 +1,49 @@ +# 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 + + # bucket names to test connectivity - required only if s3 check used, access permissions can be mixed + config.buckets = { 'bucket_name' => [:R, :W, :D] } + + # You can customize which checks happen on a standard health check, eg to set an explicit list use: + config.standard_checks = %w(database migrations custom) + + # Or to exclude one check: + config.standard_checks -= %w(emailconf) + + # You can set what tests are run with the 'full' or 'all' parameter + config.full_checks = %w(database migrations custom email cache redis resque-redis sidekiq-redis s3) + + # 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 + + # When redis url is non-standard + config.redis_url = 'redis_url' +end diff --git a/config/routes.rb b/config/routes.rb index c8f40630..597c78b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,8 @@ # with BigBlueButton; if not, see . Rails.application.routes.draw do + get 'health_check', to: 'health_check/health_check#index' + # Error routes. match '/404', to: 'errors#not_found', via: :all match '/422', to: 'errors#unprocessable', via: :all