Class: LaunchDarkly::Impl::EventSummarizer

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/impl/event_summarizer.rb

Overview

Manages the state of summarizable information for the EventProcessor, including the event counters and context deduplication. Note that the methods of this class are deliberately not thread-safe; the EventProcessor is responsible for enforcing synchronization across both the summarizer and the event queue.

Since:

  • 5.5.0

Defined Under Namespace

Classes: Counter

Instance Method Summary collapse

Constructor Details

#initializeEventSummarizer

Returns a new instance of EventSummarizer.

Since:

  • 5.5.0



20
21
22
# File 'lib/ldclient-rb/impl/event_summarizer.rb', line 20

def initialize
  clear
end

Instance Method Details

#clearObject

Since:

  • 5.5.0



61
62
63
64
65
# File 'lib/ldclient-rb/impl/event_summarizer.rb', line 61

def clear
  @start_date = 0
  @end_date = 0
  @counters = {}
end

#snapshotObject

Returns a snapshot of the current summarized event data, and resets this state.

Since:

  • 5.5.0



57
58
59
# File 'lib/ldclient-rb/impl/event_summarizer.rb', line 57

def snapshot
  EventSummary.new(@start_date, @end_date, @counters)
end

#summarize_event(event) ⇒ Object

Adds this event to our counters, if it is a type of event we need to count.

Since:

  • 5.5.0



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ldclient-rb/impl/event_summarizer.rb', line 25

def summarize_event(event)
  return unless event.is_a?(LaunchDarkly::Impl::EvalEvent)

  counters_for_flag = @counters[event.key]
  if counters_for_flag.nil?
    counters_for_flag = EventSummaryFlagInfo.new(event.default, Hash.new, Set.new)
    @counters[event.key] = counters_for_flag
  end

  counters_for_flag_version = counters_for_flag.versions[event.version]
  if counters_for_flag_version.nil?
    counters_for_flag_version = Hash.new
    counters_for_flag.versions[event.version] = counters_for_flag_version
  end

  counters_for_flag.context_kinds.merge(event.context.kinds)

  variation_counter = counters_for_flag_version[event.variation]
  if variation_counter.nil?
    counters_for_flag_version[event.variation] = EventSummaryFlagVariationCounter.new(event.value, 1)
  else
    variation_counter.count = variation_counter.count + 1
  end

  time = event.timestamp
  unless time.nil?
    @start_date = time if @start_date == 0 || time < @start_date
    @end_date = time if time > @end_date
  end
end