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



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

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

#stats_from(&block) {|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

Parameters:

  • block (Proc)

    block for selection of elements for stats

Yield Parameters:

Returns:



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

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