Exception: SplitIoClient::Metrics

Inherits:
NoMethodError
  • Object
show all
Defined in:
lib/engine/metrics/metrics.rb

Overview

class to handle cached metrics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_size) ⇒ Metrics

Returns a new instance of Metrics.



35
36
37
38
39
40
41
# File 'lib/engine/metrics/metrics.rb', line 35

def initialize(queue_size)
  @latencies = []
  @counts = []
  @gauges = []
  @queue_size = queue_size
  @binary_search = SplitIoClient::BinarySearchLatencyTracker.new
end

Instance Attribute Details

#countsobject

cached counts

Returns:

  • (object)

    array of counts



21
22
23
# File 'lib/engine/metrics/metrics.rb', line 21

def counts
  @counts
end

#gaugesobject

cached gauges

Returns:

  • (object)

    array of gauges



27
28
29
# File 'lib/engine/metrics/metrics.rb', line 27

def gauges
  @gauges
end

#latenciesobject

cached latencies

Returns:

  • (object)

    array of latencies



15
16
17
# File 'lib/engine/metrics/metrics.rb', line 15

def latencies
  @latencies
end

#queue_sizeint

quese size for cached arrays

Returns:

  • (int)

    queue size



33
34
35
# File 'lib/engine/metrics/metrics.rb', line 33

def queue_size
  @queue_size
end

Instance Method Details

#count(counter, delta) ⇒ Object

creates a new entry in the array for cached counts

Parameters:

  • counter (string)

    name of the counter

Returns:

  • void



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/engine/metrics/metrics.rb', line 50

def count(counter, delta)
  return if delta <= 0

  return if (counter.nil? || counter.strip.empty?)

  counter_hash = @counts.find { |c| c[:name] == counter }
  if counter_hash.nil?
    counter_delta = SumAndCount.new
    counter_delta.add_delta(delta)
    @counts << {name: counter, delta: counter_delta}
  else
    counter_hash[:delta].add_delta(delta)
  end
end

#gauge(gauge, value) ⇒ Object

creates a new entry in the array for cached gauges

Parameters:

  • gauge (string)

    name of the gauge

Returns:

  • void



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/engine/metrics/metrics.rb', line 94

def gauge(gauge, value)
  if gauge.nil? || gauge.empty?
    return
  end

  gauge_hash = @gauges.find { |g| g[:name] == gauge }
  if gauge_hash.nil?
    gauge_value = ValueAndCount.new
    gauge_value.set_value(value)
    @gauges << {name: gauge, value: gauge_value}
  else
    gauge_hash[:value].set_value(value)
  end
end

#time(operation, time_in_ms) ⇒ Object

creates a new entry in the array for cached time metrics

Parameters:

  • operation (string)

    name of the operation

Returns:

  • void



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/engine/metrics/metrics.rb', line 72

def time(operation, time_in_ms)

  if operation.nil? || operation.empty? || time_in_ms < 0
    return;
  end

  operation_hash = @latencies.find { |l| l[:operation] == operation }
  if operation_hash.nil?
    latencies_for_op = (operation == 'sdk.get_treatment') ? @binary_search.add_latency_millis(time_in_ms) : [time_in_ms]
    @latencies << {operation: operation, latencies: latencies_for_op}
  else
    latencies_for_op = (operation == 'sdk.get_treatment') ? @binary_search.add_latency_millis(time_in_ms) : operation_hash[:latencies].push(time_in_ms)
  end
end