Commit e9c22bee authored by Stan Hu's avatar Stan Hu

Merge branch '330402-remove-unicorn-gitlab-pid-provider' into 'master'

Remove Unicorn detection in Prometheus pid provider

See merge request gitlab-org/gitlab!62377
parents 6db04a82 6d875648
# frozen_string_literal: true
require 'prometheus/client/support/unicorn'
module Gitlab
module Metrics
module Samplers
......
......@@ -7,8 +7,6 @@ module Prometheus
def worker_id
if Gitlab::Runtime.sidekiq?
sidekiq_worker_id
elsif Gitlab::Runtime.unicorn?
unicorn_worker_id
elsif Gitlab::Runtime.puma?
puma_worker_id
else
......@@ -26,16 +24,6 @@ module Prometheus
end
end
def unicorn_worker_id
if matches = process_name.match(/unicorn.*worker\[([0-9]+)\]/)
"unicorn_#{matches[1]}"
elsif process_name =~ /unicorn/
"unicorn_master"
else
unknown_process_id
end
end
def puma_worker_id
if matches = process_name.match(/puma.*cluster worker ([0-9]+):/)
"puma_#{matches[1]}"
......
......@@ -28,66 +28,6 @@ RSpec.describe Prometheus::PidProvider do
end
end
context 'when running in Unicorn mode' do
before do
allow(Gitlab::Runtime).to receive(:unicorn?).and_return(true)
expect(described_class).to receive(:process_name)
.at_least(:once)
.and_return(process_name)
end
context 'when unicorn master is specified in process name' do
context 'when running in Omnibus' do
context 'before the process was renamed' do
let(:process_name) { "/opt/gitlab/embedded/bin/unicorn"}
it { is_expected.to eq 'unicorn_master' }
end
context 'after the process was renamed' do
let(:process_name) { "unicorn master -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru" }
it { is_expected.to eq 'unicorn_master' }
end
end
context 'when in development env' do
context 'before the process was renamed' do
let(:process_name) { "path_to_bindir/bin/unicorn_rails"}
it { is_expected.to eq 'unicorn_master' }
end
context 'after the process was renamed' do
let(:process_name) { "unicorn_rails master -c /gitlab_dir/config/unicorn.rb -E development" }
it { is_expected.to eq 'unicorn_master' }
end
end
end
context 'when unicorn worker id is specified in process name' do
context 'when running in Omnibus' do
let(:process_name) { "unicorn worker[1] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru" }
it { is_expected.to eq 'unicorn_1' }
end
context 'when in development env' do
let(:process_name) { "unicorn_rails worker[1] -c gitlab_dir/config/unicorn.rb -E development" }
it { is_expected.to eq 'unicorn_1' }
end
end
context 'when no specified unicorn master or worker id in process name' do
let(:process_name) { "bin/unknown_process"}
it { is_expected.to eq "process_#{Process.pid}" }
end
end
context 'when running in Puma mode' do
before do
allow(Gitlab::Runtime).to receive(:puma?).and_return(true)
......
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