Module: Speedshop::Cloudwatch::Observations::Rack

Defined in:
lib/speedshop/cloudwatch/observations/rack.rb

Defined Under Namespace

Classes: HeaderTimestampParser

Class Method Summary collapse

Class Method Details

.current_time_msObject



46
47
48
# File 'lib/speedshop/cloudwatch/observations/rack.rb', line 46

def current_time_ms
  Time.now.to_f * 1_000.0
end

.header_timestamp_parserObject



50
51
52
# File 'lib/speedshop/cloudwatch/observations/rack.rb', line 50

def header_timestamp_parser
  @header_timestamp_parser ||= HeaderTimestampParser.new
end

.request_body_wait_ms(env) ⇒ Object



54
55
56
57
58
# File 'lib/speedshop/cloudwatch/observations/rack.rb', line 54

def request_body_wait_ms(env)
  wait_ms = Float(env["puma.request_body_wait"])
  wait_ms if wait_ms.finite? && !wait_ms.negative?
rescue ArgumentError, TypeError
end

.request_queue_time(env, now_ms: current_time_ms) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/speedshop/cloudwatch/observations/rack.rb', line 34

def request_queue_time(env, now_ms: current_time_ms)
  now = now_ms / 1_000.0
  request_start = header_timestamp_parser.parse(env["HTTP_X_REQUEST_START"], now: now) ||
    header_timestamp_parser.parse(env["HTTP_X_QUEUE_START"], now: now)
  return unless request_start

  queue_time_ms = (now - request_start) * 1_000.0
  return if queue_time_ms.negative?

  [queue_time_ms - (request_body_wait_ms(env) || 0), 0.0].max
end