Commit ce46ad53 authored by Michael Kozono's avatar Michael Kozono

Merge branch '202040-geo-failed-to-identify-runtime-for-process-x-geo_log_cursor' into 'master'

Resolve "Geo: Failed to identify runtime for process X (./geo_log_cursor)"

Closes #202040

See merge request gitlab-org/gitlab!24509
parents 93666f4f edf09e3c
......@@ -8,15 +8,19 @@ module Gitlab
AmbiguousProcessError = Class.new(IdentificationError)
UnknownProcessError = Class.new(IdentificationError)
AVAILABLE_RUNTIMES = [
:console,
:geo_log_cursor,
:puma,
:rake,
:sidekiq,
:test_suite,
:unicorn
].freeze
class << self
def identify
matches = []
matches << :puma if puma?
matches << :unicorn if unicorn?
matches << :console if console?
matches << :sidekiq if sidekiq?
matches << :rake if rake?
matches << :test_suite if test_suite?
matches = AVAILABLE_RUNTIMES.select { |runtime| public_send("#{runtime}?") } # rubocop:disable GitlabSecurity/PublicSend
if matches.one?
matches.first
......@@ -56,6 +60,10 @@ module Gitlab
!!defined?(::Rails::Console)
end
def geo_log_cursor?
!!defined?(::GeoLogCursorOptionParser)
end
def web_server?
puma? || unicorn?
end
......
......@@ -3,6 +3,23 @@
require 'spec_helper'
describe Gitlab::Runtime do
shared_examples "valid runtime" do |runtime, max_threads|
it "identifies itself" do
expect(subject.identify).to eq(runtime)
expect(subject.public_send("#{runtime}?")).to be(true)
end
it "does not identify as others" do
(described_class::AVAILABLE_RUNTIMES - [runtime]).each do |runtime|
expect(subject.public_send("#{runtime}?")).to eq(false)
end
end
it "reports its maximum concurrency" do
expect(subject.max_threads).to eq(max_threads)
end
end
before do
allow(described_class).to receive(:process_name).and_return('ruby')
stub_rails_env('production')
......@@ -27,117 +44,42 @@ describe Gitlab::Runtime do
context "puma" do
let(:puma_type) { double('::Puma') }
let(:options) do
{
max_threads: 2
}
end
before do
stub_const('::Puma', puma_type)
allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(options)
end
it "identifies itself" do
expect(subject.identify).to eq(:puma)
expect(subject.puma?).to be(true)
allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(max_threads: 2)
end
it "does not identify as others" do
expect(subject.unicorn?).to be(false)
expect(subject.sidekiq?).to be(false)
expect(subject.console?).to be(false)
expect(subject.rake?).to be(false)
expect(subject.test_suite?).to be(false)
end
it "reports its maximum concurrency" do
expect(subject.max_threads).to eq(2)
end
it_behaves_like "valid runtime", :puma, 2
end
context "unicorn" do
let(:unicorn_type) { Module.new }
let(:unicorn_server_type) { Class.new }
before do
stub_const('::Unicorn', unicorn_type)
stub_const('::Unicorn::HttpServer', unicorn_server_type)
stub_const('::Unicorn', Module.new)
stub_const('::Unicorn::HttpServer', Class.new)
end
it "identifies itself" do
expect(subject.identify).to eq(:unicorn)
expect(subject.unicorn?).to be(true)
end
it "does not identify as others" do
expect(subject.puma?).to be(false)
expect(subject.sidekiq?).to be(false)
expect(subject.console?).to be(false)
expect(subject.rake?).to be(false)
expect(subject.test_suite?).to be(false)
end
it "reports its maximum concurrency" do
expect(subject.max_threads).to eq(1)
end
it_behaves_like "valid runtime", :unicorn, 1
end
context "sidekiq" do
let(:sidekiq_type) { double('::Sidekiq') }
let(:options) do
{
concurrency: 2
}
end
before do
stub_const('::Sidekiq', sidekiq_type)
allow(sidekiq_type).to receive(:server?).and_return(true)
allow(sidekiq_type).to receive(:options).and_return(options)
allow(sidekiq_type).to receive(:options).and_return(concurrency: 2)
end
it "identifies itself" do
expect(subject.identify).to eq(:sidekiq)
expect(subject.sidekiq?).to be(true)
end
it "does not identify as others" do
expect(subject.unicorn?).to be(false)
expect(subject.puma?).to be(false)
expect(subject.console?).to be(false)
expect(subject.rake?).to be(false)
expect(subject.test_suite?).to be(false)
end
it "reports its maximum concurrency" do
expect(subject.max_threads).to eq(2)
end
it_behaves_like "valid runtime", :sidekiq, 2
end
context "console" do
let(:console_type) { double('::Rails::Console') }
before do
stub_const('::Rails::Console', console_type)
end
it "identifies itself" do
expect(subject.identify).to eq(:console)
expect(subject.console?).to be(true)
end
it "does not identify as others" do
expect(subject.unicorn?).to be(false)
expect(subject.sidekiq?).to be(false)
expect(subject.puma?).to be(false)
expect(subject.rake?).to be(false)
expect(subject.test_suite?).to be(false)
stub_const('::Rails::Console', double('::Rails::Console'))
end
it "reports its maximum concurrency" do
expect(subject.max_threads).to eq(1)
end
it_behaves_like "valid runtime", :console, 1
end
context "test suite" do
......@@ -145,20 +87,14 @@ describe Gitlab::Runtime do
stub_rails_env('test')
end
it "identifies itself" do
expect(subject.identify).to eq(:test_suite)
expect(subject.test_suite?).to be(true)
end
it_behaves_like "valid runtime", :test_suite, 1
end
it "does not identify as others" do
expect(subject.unicorn?).to be(false)
expect(subject.sidekiq?).to be(false)
expect(subject.rake?).to be(false)
expect(subject.puma?).to be(false)
context "geo log cursor" do
before do
stub_const('::GeoLogCursorOptionParser', double('::GeoLogCursorOptionParser'))
end
it "reports its maximum concurrency" do
expect(subject.max_threads).to eq(1)
end
it_behaves_like "valid runtime", :geo_log_cursor, 1
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment