update puma and add puma health check

pull/8483/head
Markus Kahl 4 years ago
parent abd42e7aea
commit 1b82908a1d
  1. 2
      Gemfile
  2. 2
      Gemfile.lock
  3. 53
      config/initializers/health_checks.rb
  4. 2
      lib/open_project/configuration.rb

@ -167,7 +167,7 @@ gem 'sprockets', '~> 3.7.0'
# also, better than thin since we can control worker concurrency. # also, better than thin since we can control worker concurrency.
gem 'unicorn' gem 'unicorn'
gem 'puma', '~> 4.3.1' # used for development and optionally for production gem 'puma', '~> 4.3.5' # used for development and optionally for production
gem 'nokogiri', '~> 1.10.8' gem 'nokogiri', '~> 1.10.8'

@ -1080,7 +1080,7 @@ DEPENDENCIES
pry-rescue (~> 1.5.0) pry-rescue (~> 1.5.0)
pry-stack_explorer (~> 0.4.9.2) pry-stack_explorer (~> 0.4.9.2)
puffing-billy (~> 2.3.1) puffing-billy (~> 2.3.1)
puma (~> 4.3.1) puma (~> 4.3.5)
rack-attack (~> 6.2.2) rack-attack (~> 6.2.2)
rack-mini-profiler rack-mini-profiler
rack-protection (~> 2.0.8) rack-protection (~> 2.0.8)

@ -19,6 +19,53 @@ class DelayedJobNeverRanCheck < OkComputer::Check
end end
end end
class PumaCheck < OkComputer::Check
attr_reader :threshold
def initialize(backlog_threshold)
@threshold = backlog_threshold.to_i
end
def check
stats = self.stats
return mark_message "N/A as Puma is not used." if stats.nil?
if stats[:running] > 0
mark_message "Puma is running"
else
mark_failure
mark_message "Puma is not running"
end
if stats[:backlog] < threshold
mark_message "Backlog ok"
else
mark_failure
mark_message "Backlog congested"
end
end
def stats
return nil unless applicable?
server = Puma::Server.current
return nil if server.nil?
{
backlog: server.backlog || 0,
running: server.running || 0,
pool_capacity: server.pool_capacity || 0,
max_threads: server.max_threads || 0
}
end
def applicable?
return @applicable unless @applicable.nil?
@applicable = Object.const_defined?("Puma::Server") && !Puma::Server.current.nil?
end
end
# Register delayed_job backed up test # Register delayed_job backed up test
dj_max = OpenProject::Configuration.health_checks_jobs_queue_count_threshold dj_max = OpenProject::Configuration.health_checks_jobs_queue_count_threshold
OkComputer::Registry.register "delayed_jobs_backed_up", OkComputer::Registry.register "delayed_jobs_backed_up",
@ -28,8 +75,11 @@ dj_never_ran_max = OpenProject::Configuration.health_checks_jobs_never_ran_minut
OkComputer::Registry.register "delayed_jobs_never_ran", OkComputer::Registry.register "delayed_jobs_never_ran",
DelayedJobNeverRanCheck.new(dj_never_ran_max) DelayedJobNeverRanCheck.new(dj_never_ran_max)
backlog_threshold = OpenProject::Configuration.health_checks_backlog_threshold
OkComputer::Registry.register "puma", PumaCheck.new(backlog_threshold)
# Make dj backed up optional due to bursts # Make dj backed up optional due to bursts
OkComputer.make_optional %w(delayed_jobs_backed_up) OkComputer.make_optional %w(delayed_jobs_backed_up puma)
# Register web worker check for web + database # Register web worker check for web + database
OkComputer::CheckCollection.new('web').tap do |collection| OkComputer::CheckCollection.new('web').tap do |collection|
@ -45,6 +95,7 @@ OkComputer::CheckCollection.new('full').tap do |collection|
collection.register :mail, OkComputer::ActionMailerCheck.new collection.register :mail, OkComputer::ActionMailerCheck.new
collection.register :delayed_jobs_backed_up, OkComputer::Registry.fetch('delayed_jobs_backed_up') collection.register :delayed_jobs_backed_up, OkComputer::Registry.fetch('delayed_jobs_backed_up')
collection.register :delayed_jobs_never_ran, OkComputer::Registry.fetch('delayed_jobs_never_ran') collection.register :delayed_jobs_never_ran, OkComputer::Registry.fetch('delayed_jobs_never_ran')
collection.register :puma, OkComputer::Registry.fetch('puma')
OkComputer::Registry.default_collection.register 'full', collection OkComputer::Registry.default_collection.register 'full', collection
end end

@ -124,6 +124,8 @@ module OpenProject
'health_checks_jobs_queue_count_threshold' => 50, 'health_checks_jobs_queue_count_threshold' => 50,
# Maximum number of minutes that jobs have not yet run after their designated 'run_at' time # Maximum number of minutes that jobs have not yet run after their designated 'run_at' time
'health_checks_jobs_never_ran_minutes_ago' => 5, 'health_checks_jobs_never_ran_minutes_ago' => 5,
# Maximum number of unprocessed requests in puma's backlog.
'health_checks_backlog_threshold' => 20,
'after_login_default_redirect_url' => nil, 'after_login_default_redirect_url' => nil,
'after_first_login_redirect_url' => nil, 'after_first_login_redirect_url' => nil,

Loading…
Cancel
Save