debian-mirror-gitlab/lib/gitlab/middleware/rails_queue_duration.rb

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

38 lines
1.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
# This Rack middleware is intended to measure the latency between
# gitlab-workhorse forwarding a request to the Rails application and the
# time this middleware is reached.
module Gitlab
module Middleware
class RailsQueueDuration
2019-07-07 11:18:12 +05:30
GITLAB_RAILS_QUEUE_DURATION_KEY = 'GITLAB_RAILS_QUEUE_DURATION'
def initialize(app)
@app = app
end
2018-03-17 18:26:18 +05:30
def call(env)
trans = Gitlab::Metrics.current_transaction
2016-09-13 17:45:13 +05:30
proxy_start = env['HTTP_GITLAB_WORKHORSE_PROXY_START'].presence
if trans && proxy_start
# Time in milliseconds since gitlab-workhorse started the request
2018-03-17 18:26:18 +05:30
duration = Time.now.to_f * 1_000 - proxy_start.to_f / 1_000_000
2020-10-24 23:57:45 +05:30
trans.set(:gitlab_transaction_rails_queue_duration_total, duration) do
multiprocess_mode :livesum
end
2020-04-22 19:07:51 +05:30
duration_s = Gitlab::Utils.ms_to_round_sec(duration)
2020-10-24 23:57:45 +05:30
trans.observe(:gitlab_rails_queue_duration_seconds, duration_s) do
docstring 'Measures latency between GitLab Workhorse forwarding a request to Rails'
end
2020-04-22 19:07:51 +05:30
env[GITLAB_RAILS_QUEUE_DURATION_KEY] = duration_s
end
@app.call(env)
end
end
end
end