Class: Karafka::Web::Tracking::Helpers::Ttls::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/karafka/web/tracking/helpers/ttls/hash.rb

Overview

Hash that accumulates data that has an expiration date (ttl) Used to keep track of metrics in a window

Instance Method Summary collapse

Constructor Details

#initialize(ttl) ⇒ Hash

Returns a new instance of Hash.

Parameters:

  • ttl (Integer)

    milliseconds ttl



12
13
14
15
# File 'lib/karafka/web/tracking/helpers/ttls/hash.rb', line 12

def initialize(ttl)
  @ttl = ttl
  super() { |k, v| k[v] = Ttls::Array.new(@ttl) }
end

Instance Method Details

#inspectString

Returns thread-safe inspect of the ttls hash.

Returns:

  • (String)

    thread-safe inspect of the ttls hash



31
32
33
# File 'lib/karafka/web/tracking/helpers/ttls/hash.rb', line 31

def inspect
  "#<#{self.class.name}:#{format('%#x', object_id)} size=#{size} ttl=#{@ttl}ms>"
end

#stats_from {|key, samples| ... } ⇒ Stats

Takes a block where we provide a hash select filtering to select keys we are interested in using for aggregated stats. Once filtered, builds a Stats object out of the candidates

Yield Parameters:

Returns:



24
25
26
27
28
# File 'lib/karafka/web/tracking/helpers/ttls/hash.rb', line 24

def stats_from(&)
  Stats.new(
    select(&)
  )
end