Class: SplitIoClient::Engine::Common::ImpressionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/engine/common/impressions_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, impressions_repository, impression_counter, telemetry_runtime_producer, impression_observer, unique_keys_tracker) ⇒ ImpressionManager

Returns a new instance of ImpressionManager.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/splitclient-rb/engine/common/impressions_manager.rb', line 7

def initialize(config,
               impressions_repository,
               impression_counter,
               telemetry_runtime_producer,
               impression_observer,
               unique_keys_tracker)
  @config = config
  @impressions_repository = impressions_repository
  @impression_counter = impression_counter
  @impression_observer = impression_observer
  @telemetry_runtime_producer = telemetry_runtime_producer
  @unique_keys_tracker = unique_keys_tracker
end

Instance Method Details

#build_impression(matching_key, bucketing_key, split_name, treatment_data, impressions_disabled, params = {}, evaluation_options = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/splitclient-rb/engine/common/impressions_manager.rb', line 21

def build_impression(matching_key, bucketing_key, split_name, treatment_data, impressions_disabled, params = {},
                     evaluation_options = nil)
  properties = get_properties(evaluation_options)
  impression_data = impression_data(matching_key, bucketing_key, split_name, treatment_data, params[:time], properties)
  return impression(impression_data, params[:attributes]) if check_return_conditions(properties)

  begin
    if check_none_mode(impressions_disabled)
      @impression_counter.inc(split_name, impression_data[:m])
      @unique_keys_tracker.track(split_name, matching_key)
    end
    if check_observe_impressions
      # In DEBUG mode we should calculate the pt only.
      impression_data[:pt] = @impression_observer.test_and_set(impression_data)
    end
    if check_impression_counter(impression_data)
      # In OPTIMIZED mode we should track the total amount of evaluations and deduplicate the impressions.
      @impression_counter.inc(split_name, impression_data[:m])
    end
  rescue StandardError => e
    @config.log_found_exception(__method__.to_s, e)
  end

  impression(impression_data, params[:attributes])
end

#track(impressions_decorator) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/splitclient-rb/engine/common/impressions_manager.rb', line 47

def track(impressions_decorator)
  return if impressions_decorator.empty?

  impressions_decorator.each do |impression_decorator|
    impression_router.add_bulk([impression_decorator[:impression]])
    stats = { dropped: 0, queued: 0, dedupe: 0 }
    begin
      next if @config.impressions_mode == :none || impression_decorator[:disabled]

      if @config.impressions_mode == :debug
        track_debug_mode([impression_decorator[:impression]], stats)
      else
        track_optimized_mode([impression_decorator[:impression]], stats)
      end
    rescue StandardError => e
      @config.log_found_exception(__method__.to_s, e)
    ensure
      record_stats(stats)
    end
  end
end