# encoding: utf-8 require 'one_apm/support/event_buffer' require 'one_apm/support/event_buffer/sized_buffer' module OneApm module Agent class SyntheticsEventBuffer < SizedBuffer 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 OA_TIMESTAMP = "timestamp".freeze def timestamp_for(event) main_event, _ = event main_event[OA_TIMESTAMP] end end end end