Sha256: 762316a909f33696fc558f85a1fea65fb040cc2aa208a42894aa8b670cf1cb50

Contents?: true

Size: 1.49 KB

Versions: 37

Compression:

Stored size: 1.49 KB

Contents

module LaunchDarkly
  # @private
  EventSummary = Struct.new(:start_date, :end_date, :counters)

  # Manages the state of summarizable information for the EventProcessor, including the
  # event counters and user 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.
  #
  # @private
  class EventSummarizer
    def initialize
      clear
    end

    # Adds this event to our counters, if it is a type of event we need to count.
    def summarize_event(event)
      if event[:kind] == "feature"
        counter_key = {
          key: event[:key],
          version: event[:version],
          variation: event[:variation]
        }
        c = @counters[counter_key]
        if c.nil?
          @counters[counter_key] = {
            value: event[:value],
            default: event[:default],
            count: 1
          }
        else
          c[:count] = c[:count] + 1
        end
        time = event[:creationDate]
        if !time.nil?
          @start_date = time if @start_date == 0 || time < @start_date
          @end_date = time if time > @end_date
        end
      end
    end

    # Returns a snapshot of the current summarized event data, and resets this state.
    def snapshot
      ret = EventSummary.new(@start_date, @end_date, @counters)
      ret
    end

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

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
launchdarkly-server-sdk-5.7.0 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.6.2 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.6.1 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.6.0 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.5.12 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.5.11 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.5.10 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.5.9 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.5.8 lib/ldclient-rb/event_summarizer.rb
launchdarkly-server-sdk-5.5.7 lib/ldclient-rb/event_summarizer.rb
ldclient-rb-5.5.6 lib/ldclient-rb/event_summarizer.rb
ldclient-rb-5.5.5 lib/ldclient-rb/event_summarizer.rb
ldclient-rb-5.5.4 lib/ldclient-rb/event_summarizer.rb
ldclient-rb-5.5.3 lib/ldclient-rb/event_summarizer.rb
ldclient-rb-5.5.2 lib/ldclient-rb/event_summarizer.rb
ldclient-rb-5.5.1 lib/ldclient-rb/event_summarizer.rb
ldclient-rb-5.5.0 lib/ldclient-rb/event_summarizer.rb