From 6cc7c1c91dafd3d2830406e99da5c8eb778db48a Mon Sep 17 00:00:00 2001 From: Aleksei Lipniagov Date: Thu, 20 May 2021 16:37:14 +0300 Subject: [PATCH] Remove UnicornCheck service Drops UnicornCheck. Split from https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61888. Changelog: removed --- ...402-remove-unicorn-gitlab-health-check.yml | 5 ++ lib/gitlab/health_checks/unicorn_check.rb | 41 ------------ lib/gitlab/metrics/exporter/web_exporter.rb | 3 +- .../health_checks/unicorn_check_spec.rb | 67 ------------------- 4 files changed, 6 insertions(+), 110 deletions(-) create mode 100644 changelogs/unreleased/330402-remove-unicorn-gitlab-health-check.yml delete mode 100644 lib/gitlab/health_checks/unicorn_check.rb delete mode 100644 spec/lib/gitlab/health_checks/unicorn_check_spec.rb diff --git a/changelogs/unreleased/330402-remove-unicorn-gitlab-health-check.yml b/changelogs/unreleased/330402-remove-unicorn-gitlab-health-check.yml new file mode 100644 index 00000000000000..4867f75652e473 --- /dev/null +++ b/changelogs/unreleased/330402-remove-unicorn-gitlab-health-check.yml @@ -0,0 +1,5 @@ +--- +title: Remove UnicornCheck service +merge_request: 62204 +author: +type: removed diff --git a/lib/gitlab/health_checks/unicorn_check.rb b/lib/gitlab/health_checks/unicorn_check.rb deleted file mode 100644 index f0c6fdab600aa7..00000000000000 --- a/lib/gitlab/health_checks/unicorn_check.rb +++ /dev/null @@ -1,41 +0,0 @@ -# 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) - 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 Gitlab::Runtime.unicorn? - - ObjectSpace.each_object(::Unicorn::HttpServer).to_a - end - end - end - end - end -end diff --git a/lib/gitlab/metrics/exporter/web_exporter.rb b/lib/gitlab/metrics/exporter/web_exporter.rb index 558454eaa1c0f9..756e6b0641a0c1 100644 --- a/lib/gitlab/metrics/exporter/web_exporter.rb +++ b/lib/gitlab/metrics/exporter/web_exporter.rb @@ -30,8 +30,7 @@ def initialize # application: https://gitlab.com/gitlab-org/gitlab/issues/35343 self.readiness_checks = [ WebExporter::ExporterCheck.new(self), - Gitlab::HealthChecks::PumaCheck, - Gitlab::HealthChecks::UnicornCheck + Gitlab::HealthChecks::PumaCheck ] end diff --git a/spec/lib/gitlab/health_checks/unicorn_check_spec.rb b/spec/lib/gitlab/health_checks/unicorn_check_spec.rb deleted file mode 100644 index 1cc44016002fd9..00000000000000 --- a/spec/lib/gitlab/health_checks/unicorn_check_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::HealthChecks::UnicornCheck do - let(:result_class) { Gitlab::HealthChecks::Result } - let(:readiness) { described_class.readiness } - let(:metrics) { described_class.metrics } - - before do - described_class.clear_memoization(:http_servers) - end - - shared_examples 'with state' do |(state, message)| - it "does provide readiness" do - expect(readiness).to eq(result_class.new('unicorn_check', state, message)) - end - - it "does provide metrics" do - expect(metrics).to include( - an_object_having_attributes(name: 'unicorn_check_success', value: state ? 1 : 0)) - expect(metrics).to include( - an_object_having_attributes(name: 'unicorn_check_latency_seconds', value: be >= 0)) - end - end - - context 'when Unicorn is not loaded' do - before do - allow(Gitlab::Runtime).to receive(:unicorn?).and_return(false) - hide_const('Unicorn') - end - - it "does not provide readiness and metrics" do - expect(readiness).to be_nil - expect(metrics).to be_nil - end - end - - context 'when Unicorn is loaded' do - let(:http_server_class) { Struct.new(:worker_processes) } - - before do - allow(Gitlab::Runtime).to receive(:unicorn?).and_return(true) - stub_const('Unicorn::HttpServer', http_server_class) - end - - context 'when no servers are running' do - it_behaves_like 'with state', [false, 'unexpected Unicorn check result: 0'] - end - - context 'when servers without workers are running' do - before do - http_server_class.new(0) - end - - it_behaves_like 'with state', [false, 'unexpected Unicorn check result: 0'] - end - - context 'when servers with workers are running' do - before do - http_server_class.new(1) - end - - it_behaves_like 'with state', true - end - end -end -- GitLab