Browse Source

Add healthcheck endpoint for web (#11770)

Yamagishi Kazutoshi 3 months ago
parent
commit
d7268befa8

+ 1
- 0
Gemfile View File

@@ -50,6 +50,7 @@ gem 'fastimage'
50 50
 gem 'goldfinger', '~> 2.1'
51 51
 gem 'hiredis', '~> 0.6'
52 52
 gem 'redis-namespace', '~> 1.5'
53
+gem 'health_check', '~> 3.0'
53 54
 gem 'htmlentities', '~> 4.3'
54 55
 gem 'http', '~> 3.3'
55 56
 gem 'http_accept_language', '~> 2.1'

+ 3
- 0
Gemfile.lock View File

@@ -278,6 +278,8 @@ GEM
278 278
       concurrent-ruby (~> 1.0)
279 279
     hashdiff (1.0.0)
280 280
     hashie (3.6.0)
281
+    health_check (3.0.0)
282
+      railties (>= 5.0)
281 283
     heapy (0.1.4)
282 284
     highline (2.0.1)
283 285
     hiredis (0.6.3)
@@ -706,6 +708,7 @@ DEPENDENCIES
706 708
   fuubar (~> 2.4)
707 709
   goldfinger (~> 2.1)
708 710
   hamlit-rails (~> 0.2)
711
+  health_check (~> 3.0)
709 712
   hiredis (~> 0.6)
710 713
   htmlentities (~> 4.3)
711 714
   http (~> 3.3)

+ 1
- 1
app/controllers/application_controller.rb View File

@@ -41,7 +41,7 @@ class ApplicationController < ActionController::Base
41 41
   private
42 42
 
43 43
   def https_enabled?
44
-    Rails.env.production?
44
+    Rails.env.production? && !request.path.start_with?('/health')
45 45
   end
46 46
 
47 47
   def authorized_fetch_mode?

+ 6
- 0
config/initializers/health_check.rb View File

@@ -0,0 +1,6 @@
1
+HealthCheck.setup do |config|
2
+  config.uri = 'health'
3
+
4
+  config.standard_checks = %w(database migrations cache)
5
+  config.full_checks = %w(database migrations cache)
6
+end

+ 2
- 0
config/routes.rb View File

@@ -10,6 +10,8 @@ Rails.application.routes.draw do
10 10
 
11 11
   mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
12 12
 
13
+  health_check_routes
14
+
13 15
   authenticate :user, lambda { |u| u.admin? } do
14 16
     mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq
15 17
     mount PgHero::Engine, at: 'pghero', as: :pghero

+ 2
- 2
docker-compose.yml View File

@@ -43,7 +43,7 @@ services:
43 43
       - external_network
44 44
       - internal_network
45 45
     healthcheck:
46
-      test: ["CMD-SHELL", "wget -q --spider --header 'x-forwarded-proto: https' --proxy=off localhost:3000/api/v1/instance || exit 1"]
46
+      test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:3000/health || exit 1"]
47 47
     ports:
48 48
       - "127.0.0.1:3000:3000"
49 49
     depends_on:
@@ -63,7 +63,7 @@ services:
63 63
       - external_network
64 64
       - internal_network
65 65
     healthcheck:
66
-      test: ["CMD-SHELL", "wget -q --spider --header 'x-forwarded-proto: https' --proxy=off localhost:4000/api/v1/streaming/health || exit 1"]
66
+      test: ["CMD-SHELL", "wget -q --spider --proxy=off localhost:4000/api/v1/streaming/health || exit 1"]
67 67
     ports:
68 68
       - "127.0.0.1:4000:4000"
69 69
     depends_on:

Loading…
Cancel
Save