Class: OneApm::Agent::SyntheticsEventBuffer

Inherits:
SizedBuffer show all
Defined in:
lib/one_apm/support/event_buffer/synthetics_event_buffer.rb

Constant Summary collapse

OA_TIMESTAMP =
"timestamp".freeze

Instance Attribute Summary

Attributes inherited from EventBuffer

#capacity

Instance Method Summary collapse

Methods inherited from SizedBuffer

#append_event

Methods inherited from EventBuffer

#<<, #append, #full?, #initialize, #note_dropped, #num_dropped, #num_seen, #reset!, #sample_rate, #size, #to_a

Constructor Details

This class inherits a constructor from OneApm::Agent::EventBuffer

Instance Method Details

#append_with_reject(x) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/one_apm/support/event_buffer/synthetics_event_buffer.rb', line 10

def append_with_reject(x)
  @seen += 1
  if full?
    timestamp = timestamp_for(x)
    latest_event = @items.max_by do |item|
      timestamp_for(item)
    end

    if timestamp < timestamp_for(latest_event)
      # Make room!
      @items.delete(latest_event)
      return [append_event(x), latest_event]
    else
      return [nil, x]
    end
  else
    return [append_event(x), nil]
  end
end

#timestamp_for(event) ⇒ Object



32
33
34
35
# File 'lib/one_apm/support/event_buffer/synthetics_event_buffer.rb', line 32

def timestamp_for(event)
  main_event, _ = event
  main_event[OA_TIMESTAMP]
end