2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Module to support correlation_id and additional job details.
|
|
|
|
module Gitlab
|
|
|
|
module Marginalia
|
|
|
|
module Comment
|
|
|
|
private
|
|
|
|
|
|
|
|
def jid
|
|
|
|
bg_job["jid"] if bg_job.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def job_class
|
|
|
|
bg_job["class"] if bg_job.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def correlation_id
|
|
|
|
if bg_job.present?
|
|
|
|
bg_job["correlation_id"]
|
|
|
|
else
|
|
|
|
Labkit::Correlation::CorrelationId.current_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bg_job
|
|
|
|
job = ::Marginalia::Comment.marginalia_job
|
|
|
|
|
|
|
|
# We are using 'Marginalia::SidekiqInstrumentation' which does not support 'ActiveJob::Base'.
|
2020-07-28 23:09:34 +05:30
|
|
|
# Gitlab also uses 'ActionMailer::MailDeliveryJob' which inherits from ActiveJob::Base.
|
2020-01-01 13:55:28 +05:30
|
|
|
# So below condition is used to return metadata for such jobs.
|
2020-11-24 15:15:51 +05:30
|
|
|
if job.is_a?(ActionMailer::MailDeliveryJob)
|
2020-01-01 13:55:28 +05:30
|
|
|
{
|
|
|
|
"class" => job.arguments.first,
|
2022-10-11 01:57:18 +05:30
|
|
|
"jid" => job.job_id
|
2020-01-01 13:55:28 +05:30
|
|
|
}
|
|
|
|
else
|
|
|
|
job
|
|
|
|
end
|
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
def endpoint_id
|
|
|
|
Labkit::Context.current&.get_attribute(:caller_id)
|
|
|
|
end
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
def db_config_name
|
|
|
|
::Gitlab::Database.db_config_name(marginalia_adapter)
|
|
|
|
end
|
2023-01-13 00:05:48 +05:30
|
|
|
|
|
|
|
def console_hostname
|
|
|
|
return unless ::Gitlab::Runtime.console?
|
|
|
|
|
|
|
|
@cached_console_hostname ||= Socket.gethostname # rubocop:disable Gitlab/ModuleWithInstanceVariables
|
|
|
|
end
|
|
|
|
|
|
|
|
def console_username
|
|
|
|
return unless ::Gitlab::Runtime.console?
|
|
|
|
|
|
|
|
ENV['SUDO_USER'] || ENV['USER']
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|