debian-mirror-gitlab/lib/gitlab/metrics/sidekiq_middleware.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Gitlab
module Metrics
# Sidekiq middleware for tracking jobs.
#
# This middleware is intended to be used as a server-side middleware.
class SidekiqMiddleware
2020-06-23 00:09:42 +05:30
def call(worker, payload, queue)
2018-03-17 18:26:18 +05:30
trans = BackgroundTransaction.new(worker.class)
begin
2016-08-24 12:49:21 +05:30
# Old gitlad-shell messages don't provide enqueued_at/created_at attributes
2020-06-23 00:09:42 +05:30
enqueued_at = payload['enqueued_at'] || payload['created_at'] || 0
2020-10-24 23:57:45 +05:30
trans.set(:gitlab_transaction_sidekiq_queue_duration_total, Time.current.to_f - enqueued_at) do
multiprocess_mode :livesum
end
trans.run { yield }
2016-09-13 17:45:13 +05:30
rescue Exception => error # rubocop: disable Lint/RescueException
trans.add_event(:sidekiq_exception)
raise error
2020-06-23 00:09:42 +05:30
ensure
add_info_to_payload(payload, trans)
end
end
2020-06-23 00:09:42 +05:30
private
def add_info_to_payload(payload, trans)
2020-07-28 23:09:34 +05:30
payload.merge!(::Gitlab::Metrics::Subscribers::ActiveRecord.db_counter_payload)
2020-06-23 00:09:42 +05:30
end
end
end
end