class Mmtrix::Agent::CustomEventAggregator
Constants
- DEFAULT_CAPACITY_KEY
- EVENT_TYPE_REGEX
- TIMESTAMP
- TYPE
Public Class Methods
new()
click to toggle source
# File lib/mmtrix/agent/custom_event_aggregator.rb, line 19 def initialize @lock = Mutex.new @buffer = SampledBuffer.new(Mmtrix::Agent.config[DEFAULT_CAPACITY_KEY]) @type_strings = Hash.new { |hash, key| hash[key] = key.to_s.freeze } register_config_callbacks end
Public Instance Methods
harvest!()
click to toggle source
# File lib/mmtrix/agent/custom_event_aggregator.rb, line 57 def harvest! results = [] drop_count = 0 @lock.synchronize do results.concat(@buffer.to_a) drop_count += @buffer.num_dropped @buffer.reset! end note_dropped_events(results.size, drop_count) results end
merge!(events)
click to toggle source
# File lib/mmtrix/agent/custom_event_aggregator.rb, line 80 def merge!(events) @lock.synchronize do events.each do |event| @buffer.append(event) end end end
note_dropped_event(type)
click to toggle source
# File lib/mmtrix/agent/custom_event_aggregator.rb, line 92 def note_dropped_event(type) ::Mmtrix::Agent.logger.log_once(:warn, "dropping_event_of_type:#{type}", "Invalid event type name '#{type}', not recording.") @buffer.note_dropped end
note_dropped_events(captured_count, dropped_count)
click to toggle source
# File lib/mmtrix/agent/custom_event_aggregator.rb, line 69 def note_dropped_events(captured_count, dropped_count) total_count = captured_count + dropped_count if dropped_count > 0 Mmtrix::Agent.logger.warn("Dropped #{dropped_count} custom events out of #{total_count}.") end engine = Mmtrix::Agent.instance.stats_engine engine.tl_record_supportability_metric_count("Events/Customer/Seen" , total_count) engine.tl_record_supportability_metric_count("Events/Customer/Sent" , captured_count) engine.tl_record_supportability_metric_count("Events/Customer/Dropped", dropped_count) end
record(type, attributes)
click to toggle source
# File lib/mmtrix/agent/custom_event_aggregator.rb, line 35 def record(type, attributes) unless attributes.is_a? Hash raise ArgumentError, "Expected Hash but got #{attributes.class}" end type = @type_strings[type] unless type =~ EVENT_TYPE_REGEX note_dropped_event(type) return false end event = [ { TYPE => type, TIMESTAMP => Time.now.to_i }, AttributeProcessing.flatten_and_coerce(attributes) ] stored = @lock.synchronize do @buffer.append(event) end stored end
register_config_callbacks()
click to toggle source
# File lib/mmtrix/agent/custom_event_aggregator.rb, line 26 def register_config_callbacks Mmtrix::Agent.config.register_callback(DEFAULT_CAPACITY_KEY) do |max_samples| Mmtrix::Agent.logger.debug "CustomEventAggregator max_samples set to #{max_samples}" @lock.synchronize do @buffer.capacity = max_samples end end end
reset!()
click to toggle source
# File lib/mmtrix/agent/custom_event_aggregator.rb, line 88 def reset! @lock.synchronize { @buffer.reset! } end