From 96abf0536a1a5e1ec77986325aa8d666cbeaddf1 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Wed, 8 Jun 2022 18:50:54 +0200 Subject: [PATCH] Add simple health check --- app/controllers/health_controller.rb | 18 ++++++++++++++++++ chart/templates/deployment.yaml | 6 +----- config/routes.rb | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 app/controllers/health_controller.rb diff --git a/app/controllers/health_controller.rb b/app/controllers/health_controller.rb new file mode 100644 index 0000000..d72fc9a --- /dev/null +++ b/app/controllers/health_controller.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class HealthController < ApplicationController + def index + errors = [] + errors << 'database not conneected' unless database_connected? + status = errors.empty? ? :ok : :internal_server_error + render json: { errors: }, status: + end + + private + + def database_connected? + ApplicationRecord.connection.select_value('SELECT 1') == 1 + rescue StandardError + false + end +end diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index cd225cf..2ad7e96 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -34,13 +34,9 @@ spec: secretKeyRef: name: rails-master-key key: master.key - livenessProbe: - httpGet: - path: / - port: http readinessProbe: httpGet: - path: / + path: /healthz port: http resources: {{- toYaml .Values.resources | nindent 12 }} diff --git a/config/routes.rb b/config/routes.rb index 143d90c..101e869 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,4 +17,6 @@ Rails.application.routes.draw do end resources :match_scores, only: %i[show update] resources :groups, only: %i[show] + + get 'healthz', to: 'health#index' end