Class: Gitlab::Middleware::RailsQueueDuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/middleware/rails_queue_duration.rb

Constant Summary collapse

GITLAB_RAILS_QUEUE_DURATION_KEY =
'GITLAB_RAILS_QUEUE_DURATION'

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RailsQueueDuration

Returns a new instance of RailsQueueDuration.


12
13
14
# File 'lib/gitlab/middleware/rails_queue_duration.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/middleware/rails_queue_duration.rb', line 16

def call(env)
  trans = Gitlab::Metrics.current_transaction
  proxy_start = env['HTTP_GITLAB_WORKHORSE_PROXY_START'].presence
  if trans && proxy_start
    # Time in milliseconds since gitlab-workhorse started the request
    duration = Time.now.to_f * 1_000 - proxy_start.to_f / 1_000_000
    trans.set(:gitlab_transaction_rails_queue_duration_total, duration) do
      multiprocess_mode :livesum
    end

    duration_s = Gitlab::Utils.ms_to_round_sec(duration)
    trans.observe(:gitlab_rails_queue_duration_seconds, duration_s) do
      docstring 'Measures latency between GitLab Workhorse forwarding a request to Rails'
    end
    env[GITLAB_RAILS_QUEUE_DURATION_KEY] = duration_s
  end

  @app.call(env)
end