Class: Prefab::EvaluationSummaryAggregator

Inherits:
Object
  • Object
show all
Includes:
PeriodicSync
Defined in:
lib/prefab/evaluation_summary_aggregator.rb

Overview

This class aggregates the number of times each config is evaluated, and details about how the config is evaluated This data is reported to the server at a regular interval defined by ‘sync_interval`.

Constant Summary collapse

LOG =
Prefab::InternalLogger.new(EvaluationSummaryAggregator)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PeriodicSync

#on_prepare_data, #pool, #post, #prepare_data, #start_periodic_sync, #sync

Constructor Details

#initialize(client:, max_keys:, sync_interval:) ⇒ EvaluationSummaryAggregator

Returns a new instance of EvaluationSummaryAggregator.



16
17
18
19
20
21
22
23
24
# File 'lib/prefab/evaluation_summary_aggregator.rb', line 16

def initialize(client:, max_keys:, sync_interval:)
  @client = client
  @max_keys = max_keys
  @name = 'evaluation_summary_aggregator'

  @data = Concurrent::Hash.new

  start_periodic_sync(sync_interval)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



14
15
16
# File 'lib/prefab/evaluation_summary_aggregator.rb', line 14

def data
  @data
end

Instance Method Details

#record(config_key:, config_type:, counter:) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/prefab/evaluation_summary_aggregator.rb', line 26

def record(config_key:, config_type:, counter:)
  return if @data.size >= @max_keys

  key = [config_key, config_type]
  @data[key] ||= Concurrent::Hash.new

  @data[key][counter] ||= 0
  @data[key][counter] += 1
end