Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

update puma and add puma health check

Markus Kahl1b82908a1db3
diff --git a/Gemfile b/Gemfile
index efc51648f15..0a35bcf979f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -167,7 +167,7 @@ gem 'sprockets', '~> 3.7.0'
# also, better than thin since we can control worker concurrency.
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'
diff --git a/Gemfile.lock b/Gemfile.lock
index 41360f4be34..b18042e3d46 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1080,7 +1080,7 @@ DEPENDENCIES
pry-rescue (~> 1.5.0)
pry-stack_explorer (~> 0.4.9.2)
puffing-billy (~> 2.3.1)
- puma (~> 4.3.1)
+ puma (~> 4.3.5)
rack-attack (~> 6.2.2)
rack-mini-profiler
rack-protection (~> 2.0.8)
diff --git a/config/initializers/health_checks.rb b/config/initializers/health_checks.rb
index bd6ebafea0d..c947dd2c379 100644
--- a/config/initializers/health_checks.rb
+++ b/config/initializers/health_checks.rb
@@ -19,6 +19,53 @@ class DelayedJobNeverRanCheck < OkComputer::Check
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
dj_max = OpenProject::Configuration.health_checks_jobs_queue_count_threshold
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",
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
-OkComputer.make_optional %w(delayed_jobs_backed_up)
+OkComputer.make_optional %w(delayed_jobs_backed_up puma)
# Register web worker check for web + database
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 :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 :puma, OkComputer::Registry.fetch('puma')
OkComputer::Registry.default_collection.register 'full', collection
end
diff --git a/lib/open_project/configuration.rb b/lib/open_project/configuration.rb
index c919b5b9cc4..e0ce82e0bf6 100644
--- a/lib/open_project/configuration.rb
+++ b/lib/open_project/configuration.rb
@@ -124,6 +124,8 @@ module OpenProject
'health_checks_jobs_queue_count_threshold' => 50,
# Maximum number of minutes that jobs have not yet run after their designated 'run_at' time
'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_first_login_redirect_url' => nil,