Sha256: cadc5a8f9e14ab137c08197d63f1351af9fd041911ef6764ed9fd75807b394a3

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Karafka
  module Web
    module Tracking
      # Namespace for all the things related to tracking producers
      module Producers
        # Samples for collecting producers related data we're interested in
        class Sampler < Tracking::Sampler
          include ::Karafka::Core::Helpers::Time

          attr_reader :errors

          # Current schema version
          # This can be used in the future for detecting incompatible changes and writing
          # migrations
          SCHEMA_VERSION = '1.0.0'

          def initialize
            super

            @errors = []
            @started_at = float_now
          end

          # We cannot report and track the same time, that is why we use mutex here. To make sure
          # that samples aggregations and counting does not interact with reporter flushing.
          def track
            # Prevents deadlocks when something producer related fails in the Web UI reporter
            return yield(self) if Reporter::MUTEX.owned?

            Reporter::MUTEX.synchronize do
              yield(self)
            end
          end

          # Clears the sampler (for use after data dispatch)
          def clear
            @errors.clear
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
karafka-web-0.8.2 lib/karafka/web/tracking/producers/sampler.rb
karafka-web-0.8.1 lib/karafka/web/tracking/producers/sampler.rb
karafka-web-0.8.0 lib/karafka/web/tracking/producers/sampler.rb
karafka-web-0.8.0.rc1 lib/karafka/web/tracking/producers/sampler.rb
karafka-web-0.7.10 lib/karafka/web/tracking/producers/sampler.rb
karafka-web-0.7.9 lib/karafka/web/tracking/producers/sampler.rb
karafka-web-0.7.8 lib/karafka/web/tracking/producers/sampler.rb