summaryrefslogtreecommitdiff
path: root/lib/gitlab/health_checks/unicorn_check.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-16 12:06:32 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-16 12:06:32 +0000
commitd2ffc30fd583e86d4122bb5061098f4f3ca7b3f1 (patch)
treecb29c77a3ea49eb8ec732b0e644ed6cfad4770d9 /lib/gitlab/health_checks/unicorn_check.rb
parent914ea32e0efca21436220df2c10e1bfbe4ed3da9 (diff)
downloadgitlab-ce-d2ffc30fd583e86d4122bb5061098f4f3ca7b3f1.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/health_checks/unicorn_check.rb')
-rw-r--r--lib/gitlab/health_checks/unicorn_check.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/gitlab/health_checks/unicorn_check.rb b/lib/gitlab/health_checks/unicorn_check.rb
new file mode 100644
index 00000000000..a30ae015257
--- /dev/null
+++ b/lib/gitlab/health_checks/unicorn_check.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module HealthChecks
+ # This check can only be run on Unicorn `master` process
+ class UnicornCheck
+ extend SimpleAbstractCheck
+
+ class << self
+ include Gitlab::Utils::StrongMemoize
+
+ private
+
+ def metric_prefix
+ 'unicorn_check'
+ end
+
+ def successful?(result)
+ result > 0
+ end
+
+ def check
+ return unless http_servers
+
+ http_servers.sum(&:worker_processes) # rubocop: disable CodeReuse/ActiveRecord
+ end
+
+ # Traversal of ObjectSpace is expensive, on fully loaded application
+ # it takes around 80ms. The instances of HttpServers are not a subject
+ # to change so we can cache the list of servers.
+ def http_servers
+ strong_memoize(:http_servers) do
+ next unless defined?(::Unicorn::HttpServer)
+
+ ObjectSpace.each_object(::Unicorn::HttpServer).to_a
+ end
+ end
+ end
+ end
+ end
+end