Sha256: 9873bc3f2c1ad31784c07963fb1f38b37ffea1a793ea1d00d540248c62ec957d

Contents?: true

Size: 1.69 KB

Versions: 10

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module WaterDrop
  module Instrumentation
    # Namespace for handlers of callbacks emitted by the kafka client lib
    module Callbacks
      # Statistics callback handler
      # @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
      class Statistics
        # @param producer_id [String] id of the current producer
        # @param client_name [String] rdkafka client name
        # @param monitor [WaterDrop::Instrumentation::Monitor] monitor we are using
        def initialize(producer_id, client_name, monitor)
          @producer_id = producer_id
          @client_name = client_name
          @monitor = monitor
          @statistics_decorator = StatisticsDecorator.new
        end

        # Emits decorated statistics to the monitor
        # @param statistics [Hash] rdkafka statistics
        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
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
waterdrop-2.4.0 lib/waterdrop/instrumentation/callbacks/statistics.rb
waterdrop-2.3.3 lib/waterdrop/instrumentation/callbacks/statistics.rb
waterdrop-2.3.2 lib/waterdrop/instrumentation/callbacks/statistics.rb
waterdrop-2.3.1 lib/waterdrop/instrumentation/callbacks/statistics.rb
waterdrop-2.3.0 lib/waterdrop/instrumentation/callbacks/statistics.rb
waterdrop-2.2.0 lib/waterdrop/instrumentation/callbacks/statistics.rb
waterdrop-2.1.0 lib/water_drop/instrumentation/callbacks/statistics.rb
waterdrop-2.0.7 lib/water_drop/instrumentation/callbacks/statistics.rb
waterdrop-2.0.6 lib/water_drop/instrumentation/callbacks/statistics.rb
waterdrop-2.0.5 lib/water_drop/instrumentation/callbacks/statistics.rb