diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2016-05-26 17:53:21 +0200 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2016-05-26 17:53:21 +0200 |
commit | 5771114f9b5dba9c17b273a5dec0ef6900f6da9d (patch) | |
tree | 9843861e9e98ea40ce33a2e0f02b5b28b3fffcf4 /lib/gitlab/middleware/rails_queue_duration.rb | |
parent | 6ec2730fb371dbfdf84f98e2061431367c3927d1 (diff) | |
download | gitlab-ce-5771114f9b5dba9c17b273a5dec0ef6900f6da9d.tar.gz |
Rename metric to 'rails queue duration'
Diffstat (limited to 'lib/gitlab/middleware/rails_queue_duration.rb')
-rw-r--r-- | lib/gitlab/middleware/rails_queue_duration.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/gitlab/middleware/rails_queue_duration.rb b/lib/gitlab/middleware/rails_queue_duration.rb new file mode 100644 index 00000000000..56608b1b276 --- /dev/null +++ b/lib/gitlab/middleware/rails_queue_duration.rb @@ -0,0 +1,24 @@ +# 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 + + def call(env) + trans = Gitlab::Metrics.current_transaction + proxy_start = env['HTTP_GITLAB_WORHORSE_PROXY_START'].presence + if trans && proxy_start + # Time in milliseconds since gitlab-workhorse started the request + trans.set(:rails_queue_duration, Time.now.to_f * 1_000 - proxy_start.to_f / 1_000_000) + end + + @app.call(env) + end + end + end +end |