Class: WaterDrop::Instrumentation::Callbacks::StatisticsDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/waterdrop/instrumentation/callbacks/statistics_decorator.rb

Overview

Many of the librdkafka statistics are absolute values instead of a gauge. This means, that for example number of messages sent is an absolute growing value instead of being a value of messages sent from the last statistics report. This decorator calculates the diff against previously emited stats, so we get also the diff together with the original values

Instance Method Summary collapse

Constructor Details

#initializeStatisticsDecorator

Returns a new instance of StatisticsDecorator.



12
13
14
# File 'lib/waterdrop/instrumentation/callbacks/statistics_decorator.rb', line 12

def initialize
  @previous = {}.freeze
end

Instance Method Details

#call(emited_stats) ⇒ Hash

Note:

We modify the emited statistics, instead of creating new. Since we don't expose any API to get raw data, users can just assume that the result of this decoration is the proper raw stats that they can use

Returns emited statistics extended with the diff data.

Parameters:

  • emited_stats (Hash)

    original emited statistics

Returns:

  • (Hash)

    emited statistics extended with the diff data



21
22
23
24
25
26
27
28
29
30
# File 'lib/waterdrop/instrumentation/callbacks/statistics_decorator.rb', line 21

def call(emited_stats)
  diff(
    @previous,
    emited_stats
  )

  @previous = emited_stats

  emited_stats.freeze
end