2019-12-13 16:07:41 -05:00
|
|
|
# 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-14 08:09:14 -04:00
|
|
|
# Gitlab also uses 'ActionMailer::MailDeliveryJob' which inherits from ActiveJob::Base.
|
2019-12-13 16:07:41 -05:00
|
|
|
# So below condition is used to return metadata for such jobs.
|
2020-09-04 14:08:48 -04:00
|
|
|
if job.is_a?(ActionMailer::MailDeliveryJob)
|
2019-12-13 16:07:41 -05:00
|
|
|
{
|
|
|
|
"class" => job.arguments.first,
|
2022-08-23 11:09:40 -04:00
|
|
|
"jid" => job.job_id
|
2019-12-13 16:07:41 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
job
|
|
|
|
end
|
|
|
|
end
|
2021-03-04 07:11:11 -05:00
|
|
|
|
|
|
|
def endpoint_id
|
|
|
|
Labkit::Context.current&.get_attribute(:caller_id)
|
|
|
|
end
|
2021-09-15 08:11:13 -04:00
|
|
|
|
|
|
|
def db_config_name
|
|
|
|
::Gitlab::Database.db_config_name(marginalia_adapter)
|
|
|
|
end
|
2022-10-28 17:10:45 -04:00
|
|
|
|
|
|
|
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
|
2019-12-13 16:07:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|