Sha256: bd1926e9ad60795f375d79146364523e4c58a420a8d674713dcc7d5378555c6b

Contents?: true

Size: 1.84 KB

Versions: 54

Compression:

Stored size: 1.84 KB

Contents

module Appsignal
  class Aggregator
    attr_reader :queue, :slowness_index, :counts

    def initialize(queue=::ThreadSafe::Array.new, slowness_index={})
      @queue = queue
      @slowness_index = slowness_index
      @counts = {:regular_request => 0, :slow_request => 0, :exception => 0}
    end

    # truncates or reduces the size of event values of the transaction, and
    # adds it to the queue.
    #
    # @returns [ Array ] Array with transactions
    def add(transaction)
      case transaction.type
      when :regular_request
        transaction.truncate!
      when :slow_request
        pre_process_slowness!(transaction)
      when :exception
        transaction.convert_values_to_primitives!
      end
      counts[transaction.type] += 1
      queue << transaction
    end

    # Informs whether the queue has any transactions in it or not
    #
    # @returns [ Boolean ]
    def has_transactions?
      queue.any?
    end

    # Post process the queue and return it
    #
    # @returns [ Array ] Array of post processed Appsignal::Transaction objects
    def post_processed_queue!
      Appsignal.logger.debug("Post processing queue: #{counts.inspect}")
      Appsignal::Aggregator::PostProcessor.new(queue).post_processed_queue!
    end

    protected

    def similar_slowest(transaction)
      slowness_index[transaction.action]
    end

    def pre_process_slowness!(transaction)
      similar_slowest = similar_slowest(transaction)
      if similar_slowest
        if transaction.slower?(similar_slowest)
          slowness_index[transaction.action] = transaction
          transaction.convert_values_to_primitives!
          similar_slowest.truncate!
        else
          transaction.truncate!
        end
      else
        slowness_index[transaction.action] = transaction
        transaction.convert_values_to_primitives!
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
appsignal-0.10.6 lib/appsignal/aggregator.rb
appsignal-0.10.5 lib/appsignal/aggregator.rb
appsignal-0.10.4 lib/appsignal/aggregator.rb
appsignal-0.10.3 lib/appsignal/aggregator.rb
appsignal-0.10.2 lib/appsignal/aggregator.rb
appsignal-0.10.1 lib/appsignal/aggregator.rb
appsignal-0.10.0 lib/appsignal/aggregator.rb
appsignal-0.9.6 lib/appsignal/aggregator.rb
appsignal-0.9.5 lib/appsignal/aggregator.rb
appsignal-0.10.0.beta.0 lib/appsignal/aggregator.rb
appsignal-0.9.4 lib/appsignal/aggregator.rb
appsignal-0.9.3 lib/appsignal/aggregator.rb
appsignal-0.9.2 lib/appsignal/aggregator.rb
appsignal-0.9.1 lib/appsignal/aggregator.rb
appsignal-0.9.0 lib/appsignal/aggregator.rb
appsignal-0.8.15 lib/appsignal/aggregator.rb
appsignal-0.9.0.beta.1 lib/appsignal/aggregator.rb
appsignal-0.9.0.alpha.1 lib/appsignal/aggregator.rb
appsignal-0.8.14 lib/appsignal/aggregator.rb
appsignal-0.8.13 lib/appsignal/aggregator.rb