Sha256: b729e13018816c386f46cb904cf515ea10e4d7c1a1266e3d4db933cec6fbfadf
Contents?: true
Size: 1.1 KB
Versions: 28
Compression:
Stored size: 1.1 KB
Contents
# frozen_string_literal: true module Sentry module Metrics class LocalAggregator # exposed only for testing attr_reader :buckets def initialize @buckets = {} end def add(key, value) if @buckets[key] @buckets[key].add(value) else @buckets[key] = GaugeMetric.new(value) end end def to_hash return nil if @buckets.empty? @buckets.map do |bucket_key, metric| type, key, unit, tags = bucket_key payload_key = "#{type}:#{key}@#{unit}" payload_value = { tags: deserialize_tags(tags), min: metric.min, max: metric.max, count: metric.count, sum: metric.sum } [payload_key, payload_value] end.to_h end private def deserialize_tags(tags) tags.inject({}) do |h, tag| k, v = tag old = h[k] # make it an array if key repeats h[k] = old ? (old.is_a?(Array) ? old << v : [old, v]) : v h end end end end end
Version data entries
28 entries across 28 versions & 2 rubygems