From 67dc3b9c1131b5a7f3f861a0fe35169fda5cd398 Mon Sep 17 00:00:00 2001
From: DJ Mountney <david@twkie.net>
Date: Fri, 22 Apr 2016 09:50:08 -0700
Subject: [PATCH] Add the health_check gem end expose the health_check route

---
 Gemfile                             |  3 +++
 Gemfile.lock                        |  3 +++
 config/initializers/health_check.rb | 28 ++++++++++++++++++++++++++++
 config/routes.rb                    |  3 +++
 4 files changed, 37 insertions(+)
 create mode 100644 config/initializers/health_check.rb

diff --git a/Gemfile b/Gemfile
index 3e5c604ae06ed..204d19f71154b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -333,3 +333,6 @@ gem 'oauth2', '~> 1.0.0'
 
 # Soft deletion
 gem "paranoia", "~> 2.0"
+
+# Health check
+gem 'health_check', '~> 1.5.1'
diff --git a/Gemfile.lock b/Gemfile.lock
index 86b9142ef27de..de0f536641b9c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -402,6 +402,8 @@ GEM
       html2haml (>= 1.0.1)
       railties (>= 4.0.1)
     hashie (3.4.3)
+    health_check (1.5.1)
+      rails (>= 2.3.0)
     highline (1.7.8)
     hipchat (1.5.2)
       httparty
@@ -947,6 +949,7 @@ DEPENDENCIES
   grape (~> 0.13.0)
   grape-entity (~> 0.4.2)
   haml-rails (~> 0.9.0)
+  health_check (~> 1.5.1)
   hipchat (~> 1.5.0)
   html-pipeline (~> 1.11.0)
   httparty (~> 0.13.3)
diff --git a/config/initializers/health_check.rb b/config/initializers/health_check.rb
new file mode 100644
index 0000000000000..c111cfdf5ce01
--- /dev/null
+++ b/config/initializers/health_check.rb
@@ -0,0 +1,28 @@
+# HealthCheck.setup do |config|
+#   # 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
+#   config.standard_checks = [ 'database', 'migrations', 'custom' ]
+#
+#   # You can set what tests are run with the 'full' or 'all' parameter
+#   config.full_checks = ['database', 'migrations', 'custom', 'email', 'cache']
+#
+#   # Add one or more custom checks that return a blank string if ok, or an error message if there is an error
+#   config.add_custom_check do
+#      any code that returns blank on success and non blank string upon failure
+#   end
+# end
diff --git a/config/routes.rb b/config/routes.rb
index dafecc9464894..cac800b9a9c07 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -73,6 +73,9 @@
     mount Sidekiq::Web, at: '/admin/sidekiq', as: :sidekiq
   end
 
+  # Health check
+  health_check_routes
+
   # Enable Grack support
   mount Grack::AuthSpawner, at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) }, via: [:get, :post, :put]
 
-- 
GitLab