2018-12-23 12:14:25 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
# 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
|
|
|
|
def initialize(app)
|
|
|
|
@app = app
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2016-06-16 23:09:34 +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
|
2016-06-16 23:09:34 +05:30
|
|
|
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
|
|
|
|
trans.set(:rails_queue_duration, duration)
|
|
|
|
metric_rails_queue_duration_seconds.observe(trans.labels, duration / 1_000)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def metric_rails_queue_duration_seconds
|
|
|
|
@metric_rails_queue_duration_seconds ||= Gitlab::Metrics.histogram(
|
|
|
|
:gitlab_rails_queue_duration_seconds,
|
|
|
|
Gitlab::Metrics::Transaction::BASE_LABELS
|
|
|
|
)
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|