class NewRelic::Agent::EventAggregator
Public Class Methods
Source
# File lib/new_relic/agent/event_aggregator.rb, line 42 def buffer_class(klass = nil) if klass @buffer_class = klass else @buffer_class ||= PrioritySampledBuffer end end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 15 def capacity_key(key = nil) key ? @capacity_key = key : @capacity_key end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 38 def enabled_fn(fn = nil) fn ? @enabled_fn = fn : @enabled_fn end
This can be used instead of ‘enabled_key(s)` for more fine grained control over whether an aggregator should be enabled. The enabled fn will be reevaluated after configuration changes
Source
# File lib/new_relic/agent/event_aggregator.rb, line 23 def enabled_keys(*keys) if keys.empty? @enabled_keys ||= [] else @enabled_keys = Array(keys) @enabled_fn = ->() { @enabled_keys.all? { |k| Agent.config[k] } } end end
An aggregator can specify one or more keys to check to see if it is enabled. Multiple keys will be &&‘d and the enabled status of the aggregator will be reset when agent configuration changes.
Source
# File lib/new_relic/agent/event_aggregator.rb, line 11 def named(named = nil) named ? @named = named.to_s.freeze : @named end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 51 def initialize(events) @lock = Mutex.new @buffer = self.class.buffer_class.new(NewRelic::Agent.config[self.class.capacity_key]) @enabled = self.class.enabled_fn ? self.class.enabled_fn.call : false @notified_full = false register_capacity_callback register_enabled_callback(events) after_initialize end
Public Instance Methods
Source
# File lib/new_relic/agent/event_aggregator.rb, line 66 def after_harvest(metadata) end
interface method for subclasses to override to provide post harvest functionality
Source
# File lib/new_relic/agent/event_aggregator.rb, line 62 def after_initialize end
interface method for subclasses to override to provide post-initialization setup
Source
# File lib/new_relic/agent/event_aggregator.rb, line 69 def enabled? @enabled end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 77 def harvest! metadata = nil samples = [] @lock.synchronize do samples.concat(@buffer.to_a) metadata = @buffer.metadata reset_buffer! end after_harvest(metadata) [reservoir_metadata(metadata), samples] end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 73 def has_metadata? true end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 93 def merge!(payload, adjust_count = true) @lock.synchronize do _, samples = payload if adjust_count @buffer.decrement_lifetime_counts_by(samples.count) end samples.each { |s| @buffer.append(event: s) } end end
Merges samples from payload back into buffer and optionally adjusts the count of the buffer to ensure accuracy of buffer of metadata. We want to make sure not to double count samples being merged back in from a failed harvest, yet we do not want to under-count samples being merged from the PipeService
.
Source
# File lib/new_relic/agent/event_aggregator.rb, line 105 def reset! @lock.synchronize do reset_buffer! end end
Private Instance Methods
Source
# File lib/new_relic/agent/event_aggregator.rb, line 137 def notify_if_full return unless !@notified_full && @buffer.full? NewRelic::Agent.logger.debug("#{self.class.named} capacity of #{@buffer.capacity} reached, beginning sampling") @notified_full = true end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 120 def register_capacity_callback NewRelic::Agent.config.register_callback(self.class.capacity_key) do |max_samples| NewRelic::Agent.logger.debug("#{self.class.named} max_samples set to #{max_samples}") @lock.synchronize do @buffer.capacity = max_samples end end end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 129 def register_enabled_callback(events) events.subscribe(:server_source_configuration_added) { @enabled = self.class.enabled_fn.call reset! if @enabled == false ::NewRelic::Agent.logger.debug("#{self.class.named} will #{@enabled ? '' : 'not '}be sent to the New Relic service.") } end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 113 def reservoir_metadata(metadata) { :reservoir_size => metadata[:capacity], :events_seen => metadata[:seen] } end
Source
# File lib/new_relic/agent/event_aggregator.rb, line 144 def reset_buffer! @buffer.reset! @notified_full = false end