Class: Promenade::Client::Rack::QueueTimeDuration

Inherits:
Object
  • Object
show all
Defined in:
lib/promenade/client/rack/queue_time_duration.rb

Constant Summary collapse

REQUEST_START_HEADER =
"HTTP_X_REQUEST_START".freeze
QUEUE_START_HEADER =
"HTTP_X_QUEUE_START".freeze
HEADER_VALUE_MATCHER =
/^(?:t=)(?<timestamp>\d{10}(?:\.\d+))$/

Instance Method Summary collapse

Constructor Details

#initialize(env:, request_received_time:) ⇒ QueueTimeDuration

Returns a new instance of QueueTimeDuration.



11
12
13
14
15
16
17
18
# File 'lib/promenade/client/rack/queue_time_duration.rb', line 11

def initialize(env:, request_received_time:)
  @env = env
  @request_queued_time_ms = extract_request_queued_time_from_env(env)
  @valid_header_present = @request_queued_time_ms.is_a?(Float)
  @request_received_time_ms = request_received_time.utc.to_f

  freeze
end

Instance Method Details

#queue_time_secondsObject



24
25
26
27
28
# File 'lib/promenade/client/rack/queue_time_duration.rb', line 24

def queue_time_seconds
  return unless valid_header_present?

  queue_time.round(3)
end

#valid_header_present?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/promenade/client/rack/queue_time_duration.rb', line 20

def valid_header_present?
  @valid_header_present
end