Sha256: 694563ec111ae1984fcd9399d1c93ac5851697e6fc65d26b30690b4d8e0eb8a6

Contents?: true

Size: 1.44 KB

Versions: 46

Compression:

Stored size: 1.44 KB

Contents

# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

module GoodData
  module Rest
    # class is responsible for storage and aggregation of REST calls information
    module Aggregator
      attr_reader :store

      def initialize_store
        @store = {}
      end

      def clear_store
        @store.clear
      end

      def update_store(domain, method, duration, endpoint)
        domain = domain.to_sym
        method = method.to_sym
        endpoint = endpoint.to_sym
        @store[domain] = {} unless @store.key?(domain)
        @store[domain][method] = {} unless @store[domain].key?(method)
        if @store[domain][method].key?(endpoint)
          record = @store[domain][method][endpoint]
          record[:min] = [duration, record[:min]].min
          record[:max] = [duration, record[:max]].max
          record[:avg] = (record[:avg] * record[:count] + duration).to_f / (record[:count] + 1)
          record[:count] += 1
          @store[domain][method][endpoint] = record
        else
          @store[domain][method][endpoint] = {
            :min => duration,
            :max => duration,
            :avg => duration,
            :count => 1,
            :method => method.to_s,
            :endpoint => endpoint.to_s,
            :domain => domain.to_s
          }
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
gooddata-2.3.1-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.3.1 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.3.0-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.3.0 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.2.0-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.2.0 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.19-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.19 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.17-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.17 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.15-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.15 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.14-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.14 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.13-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.13 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.12-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.12 lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.11-java lib/gooddata/rest/rest_aggregator.rb
gooddata-2.1.11 lib/gooddata/rest/rest_aggregator.rb