Class: Speedshop::Cloudwatch::Observations::Rack::HeaderTimestampParser

Inherits:
Object
  • Object
show all
Defined in:
lib/speedshop/cloudwatch/observations/rack.rb

Constant Summary collapse

MIN_EPOCH =
Time.utc(2000, 1, 1).to_f
FUTURE_TOLERANCE =
30.0
DIVISORS =
[1_000_000.0, 1_000.0, 1.0].freeze
NUMBER_RE =
/[+-]?(?:\d+(?:\.\d+)?|\.\d+)/
T_EQUALS_RE =
/t\s*=\s*(#{NUMBER_RE.source})/i

Instance Method Summary collapse

Instance Method Details

#parse(value, now:) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/speedshop/cloudwatch/observations/rack.rb', line 14

def parse(value, now:)
  header_value = value.to_s.split(",", 2).first.to_s.strip
  return if header_value.empty?

  token = header_value[T_EQUALS_RE, 1] || header_value[NUMBER_RE, 0]
  normalize(Float(token), now) if token
rescue ArgumentError, TypeError
end