diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-16 15:06:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-16 15:06:32 +0300 |
commit | d2ffc30fd583e86d4122bb5061098f4f3ca7b3f1 (patch) | |
tree | cb29c77a3ea49eb8ec732b0e644ed6cfad4770d9 /lib/gitlab/health_checks | |
parent | 914ea32e0efca21436220df2c10e1bfbe4ed3da9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/health_checks')
-rw-r--r-- | lib/gitlab/health_checks/gitaly_check.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/health_checks/probes/readiness.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/health_checks/puma_check.rb | 36 | ||||
-rw-r--r-- | lib/gitlab/health_checks/simple_abstract_check.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/health_checks/unicorn_check.rb | 41 |
5 files changed, 85 insertions, 4 deletions
diff --git a/lib/gitlab/health_checks/gitaly_check.rb b/lib/gitlab/health_checks/gitaly_check.rb index f5f142c251f..e780bf8a986 100644 --- a/lib/gitlab/health_checks/gitaly_check.rb +++ b/lib/gitlab/health_checks/gitaly_check.rb @@ -5,7 +5,7 @@ module Gitlab class GitalyCheck extend BaseAbstractCheck - METRIC_PREFIX = 'gitaly_health_check' + METRIC_PREFIX = 'gitaly_health_check'.freeze class << self def readiness diff --git a/lib/gitlab/health_checks/probes/readiness.rb b/lib/gitlab/health_checks/probes/readiness.rb index b789cbe1ae6..28abf490ffc 100644 --- a/lib/gitlab/health_checks/probes/readiness.rb +++ b/lib/gitlab/health_checks/probes/readiness.rb @@ -6,10 +6,10 @@ module Gitlab class Readiness attr_reader :checks - # This accepts an array of Proc + # This accepts an array of objects implementing `:readiness` # that returns `::Gitlab::HealthChecks::Result` def initialize(*additional_checks) - @checks = ::Gitlab::HealthChecks::CHECKS.map { |check| check.method(:readiness) } + @checks = ::Gitlab::HealthChecks::CHECKS @checks += additional_checks end @@ -43,7 +43,7 @@ module Gitlab def probe_readiness checks - .flat_map(&:call) + .flat_map(&:readiness) .compact .group_by(&:name) end diff --git a/lib/gitlab/health_checks/puma_check.rb b/lib/gitlab/health_checks/puma_check.rb new file mode 100644 index 00000000000..7aafe29fbae --- /dev/null +++ b/lib/gitlab/health_checks/puma_check.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module HealthChecks + # This check can only be run on Puma `master` process + class PumaCheck + extend SimpleAbstractCheck + + class << self + private + + def metric_prefix + 'puma_check' + end + + def successful?(result) + result > 0 + end + + def check + return unless defined?(::Puma) + + stats = Puma.stats + stats = JSON.parse(stats) + + # If `workers` is missing this means that + # Puma server is running in single mode + stats.fetch('workers', 1) + rescue NoMethodError + # server is not ready + 0 + end + end + end + end +end diff --git a/lib/gitlab/health_checks/simple_abstract_check.rb b/lib/gitlab/health_checks/simple_abstract_check.rb index 959f28791c3..4e0b9296819 100644 --- a/lib/gitlab/health_checks/simple_abstract_check.rb +++ b/lib/gitlab/health_checks/simple_abstract_check.rb @@ -7,6 +7,8 @@ module Gitlab def readiness check_result = check + return if check_result.nil? + if successful?(check_result) HealthChecks::Result.new(name, true) elsif check_result.is_a?(Timeout::Error) @@ -20,6 +22,8 @@ module Gitlab def metrics result, elapsed = with_timing(&method(:check)) + return if result.nil? + Rails.logger.error("#{human_name} check returned unexpected result #{result}") unless successful?(result) # rubocop:disable Gitlab/RailsLogger [ metric("#{metric_prefix}_timeout", result.is_a?(Timeout::Error) ? 1 : 0), 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 |