Class: Yabeda::TestAdapter

Inherits:
BaseAdapter show all
Includes:
Singleton
Defined in:
lib/yabeda/test_adapter.rb

Overview

Fake monitoring system adapter that collects latest metric values for later inspection

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAdapter

#debug!, #register!

Constructor Details

#initializeTestAdapter

rubocop:disable Metrics/AbcSize



15
16
17
18
19
20
21
# File 'lib/yabeda/test_adapter.rb', line 15

def initialize
  super
  @counters   = Hash.new { |ch, ck| ch[ck] = Hash.new { |th, tk| th[tk] = 0 } }
  @gauges     = Hash.new { |gh, gk| gh[gk] = Hash.new { |th, tk| th[tk] = nil } }
  @histograms = Hash.new { |hh, hk| hh[hk] = Hash.new { |th, tk| th[tk] = nil } }
  @summaries  = Hash.new { |sh, sk| sh[sk] = Hash.new { |th, tk| th[tk] = nil } }
end

Instance Attribute Details

#countersObject (readonly)

Returns the value of attribute counters.



12
13
14
# File 'lib/yabeda/test_adapter.rb', line 12

def counters
  @counters
end

#gaugesObject (readonly)

Returns the value of attribute gauges.



12
13
14
# File 'lib/yabeda/test_adapter.rb', line 12

def gauges
  @gauges
end

#histogramsObject (readonly)

Returns the value of attribute histograms.



12
13
14
# File 'lib/yabeda/test_adapter.rb', line 12

def histograms
  @histograms
end

#summariesObject (readonly)

Returns the value of attribute summaries.



12
13
14
# File 'lib/yabeda/test_adapter.rb', line 12

def summaries
  @summaries
end

Instance Method Details

#perform_counter_increment!(counter, tags, increment) ⇒ Object



47
48
49
# File 'lib/yabeda/test_adapter.rb', line 47

def perform_counter_increment!(counter, tags, increment)
  @counters[counter][tags] += increment
end

#perform_gauge_set!(gauge, tags, value) ⇒ Object



51
52
53
# File 'lib/yabeda/test_adapter.rb', line 51

def perform_gauge_set!(gauge, tags, value)
  @gauges[gauge][tags] = value
end

#perform_histogram_measure!(histogram, tags, value) ⇒ Object



55
56
57
# File 'lib/yabeda/test_adapter.rb', line 55

def perform_histogram_measure!(histogram, tags, value)
  @histograms[histogram][tags] = value
end

#perform_summary_observe!(summary, tags, value) ⇒ Object



59
60
61
# File 'lib/yabeda/test_adapter.rb', line 59

def perform_summary_observe!(summary, tags, value)
  @summaries[summary][tags] = value
end

#register_counter!(metric) ⇒ Object



31
32
33
# File 'lib/yabeda/test_adapter.rb', line 31

def register_counter!(metric)
  @counters[metric]
end

#register_gauge!(metric) ⇒ Object



35
36
37
# File 'lib/yabeda/test_adapter.rb', line 35

def register_gauge!(metric)
  @gauges[metric]
end

#register_histogram!(metric) ⇒ Object



39
40
41
# File 'lib/yabeda/test_adapter.rb', line 39

def register_histogram!(metric)
  @histograms[metric]
end

#register_summary!(metric) ⇒ Object



43
44
45
# File 'lib/yabeda/test_adapter.rb', line 43

def register_summary!(metric)
  @summaries[metric]
end

#reset!Object

Call this method after every test example to quickly get blank state for the next test example



25
26
27
28
29
# File 'lib/yabeda/test_adapter.rb', line 25

def reset!
  [@counters, @gauges, @histograms, @summaries].each do |collection|
    collection.each_value(&:clear) # Reset tag-values hash to be empty
  end
end