2019-07-18 09:54:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Prometheus
|
|
|
|
module PidProvider
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def worker_id
|
2019-12-22 04:07:51 -05:00
|
|
|
if Gitlab::Runtime.sidekiq?
|
2019-10-22 08:06:20 -04:00
|
|
|
sidekiq_worker_id
|
2019-12-22 04:07:51 -05:00
|
|
|
elsif Gitlab::Runtime.puma?
|
2019-07-26 11:02:21 -04:00
|
|
|
puma_worker_id
|
2019-07-18 09:54:11 -04:00
|
|
|
else
|
2019-07-26 11:02:21 -04:00
|
|
|
unknown_process_id
|
2019-07-18 09:54:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-10-22 08:06:20 -04:00
|
|
|
def sidekiq_worker_id
|
|
|
|
if worker = ENV['SIDEKIQ_WORKER_ID']
|
|
|
|
"sidekiq_#{worker}"
|
|
|
|
else
|
|
|
|
'sidekiq'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-18 09:54:11 -04:00
|
|
|
def puma_worker_id
|
2019-07-26 11:02:21 -04:00
|
|
|
if matches = process_name.match(/puma.*cluster worker ([0-9]+):/)
|
|
|
|
"puma_#{matches[1]}"
|
|
|
|
elsif process_name =~ /puma/
|
|
|
|
"puma_master"
|
|
|
|
else
|
|
|
|
unknown_process_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unknown_process_id
|
|
|
|
"process_#{Process.pid}"
|
2019-07-18 09:54:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_name
|
2022-10-14 17:09:20 -04:00
|
|
|
$PROGRAM_NAME
|
2019-07-18 09:54:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|