Module: GoodData::Rest::Aggregator
- Included in:
- GdLogger
- Defined in:
- lib/gooddata/rest/rest_aggregator.rb
Overview
class is responsible for storage and aggregation of REST calls information
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #clear_store ⇒ Object
- #initialize_store ⇒ Object
- #update_store(domain, method, duration, endpoint) ⇒ Object
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
9 10 11 |
# File 'lib/gooddata/rest/rest_aggregator.rb', line 9 def store @store end |
Instance Method Details
#clear_store ⇒ Object
15 16 17 |
# File 'lib/gooddata/rest/rest_aggregator.rb', line 15 def clear_store @store.clear end |
#initialize_store ⇒ Object
11 12 13 |
# File 'lib/gooddata/rest/rest_aggregator.rb', line 11 def initialize_store @store = {} end |
#update_store(domain, method, duration, endpoint) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gooddata/rest/rest_aggregator.rb', line 19 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 |