Module: RorVsWild::Plugin::Middleware::RequestQueueTime

Included in:
RorVsWild::Plugin::Middleware
Defined in:
lib/rorvswild/plugin/middleware.rb

Constant Summary collapse

ACCEPTABLE_HEADERS =
[
  'HTTP_X_REQUEST_START',
  'HTTP_X_QUEUE_START',
  'HTTP_X_MIDDLEWARE_START'
].freeze
MINIMUM_TIMESTAMP =

2020/01/01 UTC

1577836800.freeze
DIVISORS =
[1_000_000, 1_000, 1].freeze

Instance Method Summary collapse

Instance Method Details

#parse_queue_time_header(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rorvswild/plugin/middleware.rb', line 17

def parse_queue_time_header(env)
  return unless env

  earliest = nil

  ACCEPTABLE_HEADERS.each do |header|
    if (header_value = env[header])
      timestamp = parse_timestamp(header_value.delete_prefix("t="))
      if timestamp && (!earliest || timestamp < earliest)
        earliest = timestamp
      end
    end
  end

  [earliest, Time.now.to_f].min if earliest
end