2016-05-24 15:07:41 +00:00
|
|
|
# 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
|
2016-05-26 15:53:21 +00:00
|
|
|
class RailsQueueDuration
|
2016-05-24 15:07:41 +00:00
|
|
|
def initialize(app)
|
|
|
|
@app = app
|
|
|
|
end
|
2017-08-15 17:44:37 +00:00
|
|
|
|
2016-05-24 15:07:41 +00:00
|
|
|
def call(env)
|
2016-05-25 12:28:21 +00:00
|
|
|
trans = Gitlab::Metrics.current_transaction
|
2016-08-19 10:25:52 +00:00
|
|
|
proxy_start = env['HTTP_GITLAB_WORKHORSE_PROXY_START'].presence
|
2016-05-25 12:28:21 +00:00
|
|
|
if trans && proxy_start
|
|
|
|
# Time in milliseconds since gitlab-workhorse started the request
|
2017-09-07 19:36:51 +00:00
|
|
|
duration = Time.now.to_f * 1_000 - proxy_start.to_f / 1_000_000
|
|
|
|
trans.set(:rails_queue_duration, duration)
|
2017-10-24 07:09:13 +00:00
|
|
|
metric_rails_queue_duration_seconds.observe(trans.labels, duration / 1_000)
|
2016-05-24 15:07:41 +00:00
|
|
|
end
|
2016-05-25 12:28:21 +00:00
|
|
|
|
2016-05-24 15:07:41 +00:00
|
|
|
@app.call(env)
|
|
|
|
end
|
2017-10-24 07:09:13 +00:00
|
|
|
|
|
|
|
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-05-24 15:07:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|