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 ...@@ -8,15 +8,19 @@ module Gitlab
AmbiguousProcessError = Class.new(IdentificationError) AmbiguousProcessError = Class.new(IdentificationError)
UnknownProcessError = Class.new(IdentificationError) UnknownProcessError = Class.new(IdentificationError)
AVAILABLE_RUNTIMES = [
:console,
:geo_log_cursor,
:puma,
:rake,
:sidekiq,
:test_suite,
:unicorn
].freeze
class << self class << self
def identify def identify
matches = [] matches = AVAILABLE_RUNTIMES.select { |runtime| public_send("#{runtime}?") } # rubocop:disable GitlabSecurity/PublicSend
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?
if matches.one? if matches.one?
matches.first matches.first
...@@ -56,6 +60,10 @@ module Gitlab ...@@ -56,6 +60,10 @@ module Gitlab
!!defined?(::Rails::Console) !!defined?(::Rails::Console)
end end
def geo_log_cursor?
!!defined?(::GeoLogCursorOptionParser)
end
def web_server? def web_server?
puma? || unicorn? puma? || unicorn?
end end
......
...@@ -3,6 +3,23 @@ ...@@ -3,6 +3,23 @@
require 'spec_helper' require 'spec_helper'
describe Gitlab::Runtime do 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 before do
allow(described_class).to receive(:process_name).and_return('ruby') allow(described_class).to receive(:process_name).and_return('ruby')
stub_rails_env('production') stub_rails_env('production')
...@@ -27,117 +44,42 @@ describe Gitlab::Runtime do ...@@ -27,117 +44,42 @@ describe Gitlab::Runtime do
context "puma" do context "puma" do
let(:puma_type) { double('::Puma') } let(:puma_type) { double('::Puma') }
let(:options) do
{
max_threads: 2
}
end
before do before do
stub_const('::Puma', puma_type) stub_const('::Puma', puma_type)
allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(options) allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(max_threads: 2)
end
it "identifies itself" do
expect(subject.identify).to eq(:puma)
expect(subject.puma?).to be(true)
end end
it "does not identify as others" do it_behaves_like "valid runtime", :puma, 2
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
end end
context "unicorn" do context "unicorn" do
let(:unicorn_type) { Module.new }
let(:unicorn_server_type) { Class.new }
before do before do
stub_const('::Unicorn', unicorn_type) stub_const('::Unicorn', Module.new)
stub_const('::Unicorn::HttpServer', unicorn_server_type) 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 end
it "reports its maximum concurrency" do it_behaves_like "valid runtime", :unicorn, 1
expect(subject.max_threads).to eq(1)
end
end end
context "sidekiq" do context "sidekiq" do
let(:sidekiq_type) { double('::Sidekiq') } let(:sidekiq_type) { double('::Sidekiq') }
let(:options) do
{
concurrency: 2
}
end
before do before do
stub_const('::Sidekiq', sidekiq_type) stub_const('::Sidekiq', sidekiq_type)
allow(sidekiq_type).to receive(:server?).and_return(true) 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 end
it "identifies itself" do it_behaves_like "valid runtime", :sidekiq, 2
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
end end
context "console" do context "console" do
let(:console_type) { double('::Rails::Console') }
before do before do
stub_const('::Rails::Console', console_type) stub_const('::Rails::Console', double('::Rails::Console'))
end end
it "identifies itself" do it_behaves_like "valid runtime", :console, 1
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)
end
it "reports its maximum concurrency" do
expect(subject.max_threads).to eq(1)
end
end end
context "test suite" do context "test suite" do
...@@ -145,20 +87,14 @@ describe Gitlab::Runtime do ...@@ -145,20 +87,14 @@ describe Gitlab::Runtime do
stub_rails_env('test') stub_rails_env('test')
end end
it "identifies itself" do it_behaves_like "valid runtime", :test_suite, 1
expect(subject.identify).to eq(:test_suite)
expect(subject.test_suite?).to be(true)
end end
it "does not identify as others" do context "geo log cursor" do
expect(subject.unicorn?).to be(false) before do
expect(subject.sidekiq?).to be(false) stub_const('::GeoLogCursorOptionParser', double('::GeoLogCursorOptionParser'))
expect(subject.rake?).to be(false)
expect(subject.puma?).to be(false)
end end
it "reports its maximum concurrency" do it_behaves_like "valid runtime", :geo_log_cursor, 1
expect(subject.max_threads).to eq(1)
end
end end
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