debian-mirror-gitlab/lib/prometheus/pid_provider.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
808 B
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
module Prometheus
module PidProvider
extend self
def worker_id
2020-03-13 15:44:24 +05:30
if Gitlab::Runtime.sidekiq?
2019-12-26 22:10:19 +05:30
sidekiq_worker_id
2020-03-13 15:44:24 +05:30
elsif Gitlab::Runtime.puma?
2019-10-12 21:52:04 +05:30
puma_worker_id
else
unknown_process_id
end
end
private
2019-12-26 22:10:19 +05:30
def sidekiq_worker_id
if worker = ENV['SIDEKIQ_WORKER_ID']
"sidekiq_#{worker}"
else
'sidekiq'
end
end
2019-10-12 21:52:04 +05:30
def puma_worker_id
if matches = process_name.match(/puma.*cluster worker ([0-9]+):/)
"puma_#{matches[1]}"
2023-04-23 21:23:45 +05:30
elsif process_name.include?('puma')
2019-10-12 21:52:04 +05:30
"puma_master"
else
unknown_process_id
end
end
def unknown_process_id
"process_#{Process.pid}"
end
def process_name
2022-11-25 23:54:43 +05:30
$PROGRAM_NAME
2019-10-12 21:52:04 +05:30
end
end
end