Module: Speedshop::Cloudwatch::RequestSize

Defined in:
lib/speedshop/cloudwatch/request_size.rb

Constant Summary collapse

LIMIT =
1024 * 1024

Class Method Summary collapse

Class Method Details

.bound(value) ⇒ Object

Upper bound for uncompressed PutMetricData Query bodies, not Ruby object size. Every supported leaf's full Query key (including MetricData.member.20, Dimensions/Values/Counts indices), '=' and '&' fits within 128 bytes. Percent encoding expands each UTF-8 byte by at most 3. The 64-byte floor covers SDK numeric/timestamp formatting independently of Ruby's to_s. Container overhead is deliberately overcounted, including empty lists.



14
15
16
17
18
19
20
21
22
23
# File 'lib/speedshop/cloudwatch/request_size.rb', line 14

def self.bound(value)
  case value
  when Hash
    128 + value.values.sum { |item| bound(item) }
  when Array
    128 + value.sum { |item| bound(item) }
  else
    128 + 3 * [value.to_s.bytesize, 64].max
  end
end

.request_overhead(namespace) ⇒ Object



25
26
27
28
# File 'lib/speedshop/cloudwatch/request_size.rb', line 25

def self.request_overhead(namespace)
  # Action, Version, Namespace key, and separators.
  512 + bound(namespace)
end