Class: WaterDrop::Instrumentation::Callbacks::Statistics

Inherits:
Object
  • Object
show all
Defined in:
lib/water_drop/instrumentation/callbacks/statistics.rb

Overview

Note:

We decorate the statistics with our own decorator because some of the metrics from rdkafka are absolute. For example number of sent messages increases not in reference to previous statistics emit but from the beginning of the process. We decorate it with diff of all the numeric values against the data from the previous callback emit

Statistics callback handler

Instance Method Summary collapse

Constructor Details

#initialize(producer_id, client_name, monitor) ⇒ Statistics

Returns a new instance of Statistics.

Parameters:



16
17
18
19
20
21
# File 'lib/water_drop/instrumentation/callbacks/statistics.rb', line 16

def initialize(producer_id, client_name, monitor)
  @producer_id = producer_id
  @client_name = client_name
  @monitor = monitor
  @statistics_decorator = StatisticsDecorator.new
end

Instance Method Details

#call(statistics) ⇒ Object

Emits decorated statistics to the monitor

Parameters:

  • statistics (Hash)

    rdkafka statistics



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/water_drop/instrumentation/callbacks/statistics.rb', line 25

def call(statistics)
  # Emit only statistics related to our client
  # rdkafka does not have per-instance statistics hook, thus we need to make sure that we
  # emit only stats that are related to current producer. Otherwise we would emit all of
  # all the time.
  return unless @client_name == statistics['name']

  @monitor.instrument(
    'statistics.emitted',
    producer_id: @producer_id,
    statistics: @statistics_decorator.call(statistics)
  )
end