lib/new_relic/agent/agent.rb in newrelic_rpm-6.8.0.360 vs lib/new_relic/agent/agent.rb in newrelic_rpm-6.9.0.363

- old
+ new

@@ -6,23 +6,23 @@ require 'net/https' require 'net/http' require 'logger' require 'zlib' require 'stringio' +require 'new_relic/constants' +require 'new_relic/coerce' require 'new_relic/agent/autostart' require 'new_relic/agent/harvester' require 'new_relic/agent/hostname' require 'new_relic/agent/new_relic_service' require 'new_relic/agent/pipe_service' require 'new_relic/agent/configuration/manager' require 'new_relic/agent/database' require 'new_relic/agent/commands/agent_command_router' require 'new_relic/agent/event_listener' -require 'new_relic/agent/cross_app_monitor' -require 'new_relic/agent/distributed_trace_monitor' -require 'new_relic/agent/trace_context_request_monitor' -require 'new_relic/agent/synthetics_monitor' +require 'new_relic/agent/distributed_tracing' +require 'new_relic/agent/monitors' require 'new_relic/agent/transaction_event_recorder' require 'new_relic/agent/custom_event_aggregator' require 'new_relic/agent/span_event_aggregator' require 'new_relic/agent/sampler_collection' require 'new_relic/agent/javascript_instrumentor' @@ -47,36 +47,34 @@ end def initialize @started = false @event_loop = nil + @worker_thread = nil @service = NewRelicService.new - @events = NewRelic::Agent::EventListener.new - @stats_engine = NewRelic::Agent::StatsEngine.new - @transaction_sampler = NewRelic::Agent::TransactionSampler.new - @sql_sampler = NewRelic::Agent::SqlSampler.new - @agent_command_router = NewRelic::Agent::Commands::AgentCommandRouter.new(@events) - @cross_app_monitor = NewRelic::Agent::CrossAppMonitor.new(@events) - @distributed_trace_monitor = NewRelic::Agent::DistributedTraceMonitor.new(@events) - @trace_context_monitor = NewRelic::Agent::TraceContextRequestMonitor.new(@events) - @synthetics_monitor = NewRelic::Agent::SyntheticsMonitor.new(@events) - @error_collector = NewRelic::Agent::ErrorCollector.new @events - @transaction_rules = NewRelic::Agent::RulesEngine.new - @harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events) - @monotonic_gc_profiler = NewRelic::Agent::VM::MonotonicGCProfiler.new - @javascript_instrumentor = NewRelic::Agent::JavascriptInstrumentor.new(@events) - @adaptive_sampler = NewRelic::Agent::AdaptiveSampler.new(self.class.config[:sampling_target], - self.class.config[:sampling_target_period_in_seconds]) + @events = EventListener.new + @stats_engine = StatsEngine.new + @transaction_sampler = TransactionSampler.new + @sql_sampler = SqlSampler.new + @agent_command_router = Commands::AgentCommandRouter.new @events + @monitors = Monitors.new @events + @error_collector = ErrorCollector.new @events + @transaction_rules = RulesEngine.new + @harvest_samplers = SamplerCollection.new @events + @monotonic_gc_profiler = VM::MonotonicGCProfiler.new + @javascript_instrumentor = JavascriptInstrumentor.new @events + @adaptive_sampler = AdaptiveSampler.new(Agent.config[:sampling_target], + Agent.config[:sampling_target_period_in_seconds]) - @harvester = NewRelic::Agent::Harvester.new(@events) + @harvester = Harvester.new @events @after_fork_lock = Mutex.new - @transaction_event_recorder = NewRelic::Agent::TransactionEventRecorder.new @events - @custom_event_aggregator = NewRelic::Agent::CustomEventAggregator.new @events - @span_event_aggregator = NewRelic::Agent::SpanEventAggregator.new @events + @transaction_event_recorder = TransactionEventRecorder.new @events + @custom_event_aggregator = CustomEventAggregator.new @events + @span_event_aggregator = SpanEventAggregator.new @events @connect_state = :pending @connect_attempts = 0 @waited_on_connect = nil @connected_pid = nil @@ -94,11 +92,11 @@ refresh_attribute_filter end end def refresh_attribute_filter - @attribute_filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config) + @attribute_filter = AttributeFilter.new(Agent.config) end # contains all the class-level methods for NewRelic::Agent::Agent module ClassMethods # Should only be called by NewRelic::Control - returns a @@ -127,17 +125,20 @@ # builder for JS agent scripts to inject attr_reader :javascript_instrumentor # cross application tracing ids and encoding attr_reader :cross_process_id attr_reader :cross_app_encoding_bytes - attr_reader :cross_app_monitor # service for communicating with collector attr_accessor :service # Global events dispatcher. This will provides our primary mechanism # for agent-wide events, such as finishing configuration, error notification # and request before/after from Rack. attr_reader :events + + # listens and responds to events that need to process headers + # for synthetics and distributed tracing + attr_reader :monitors # Transaction and metric renaming rules as provided by the # collector on connect. The former are applied during txns, # the latter during harvest. attr_accessor :transaction_rules # Responsbile for restarting the harvest thread @@ -206,11 +207,11 @@ setup_and_start_agent(options) end def install_pipe_service(channel_id) - @service = NewRelic::Agent::PipeService.new(channel_id) + @service = PipeService.new(channel_id) if connected? @connected_pid = Process.pid else ::NewRelic::Agent.logger.debug("Child process #{Process.pid} not reporting to non-connected parent (process #{Process.ppid}).") @service.shutdown(Time.now) @@ -237,16 +238,22 @@ @started = nil Control.reset end def revert_to_default_configuration - NewRelic::Agent.config.remove_config_type(:manual) - NewRelic::Agent.config.remove_config_type(:server) + Agent.config.remove_config_type(:manual) + Agent.config.remove_config_type(:server) end def stop_event_loop @event_loop.stop if @event_loop + # Wait the end of the event loop thread. + if @worker_thread + unless @worker_thread.join(3) + ::NewRelic::Agent.logger.error "Event loop thread did not stop within 3 seconds" + end + end end def trap_signals_for_litespeed # if litespeed, then ignore all future SIGUSR1 - it's # litespeed trying to shut us down @@ -457,15 +464,15 @@ # daemonize itself. This avoids hanging when there's a Thread started # before Resque calls Process.daemon (Jira RUBY-857) def defer_for_resque? NewRelic::Agent.config[:dispatcher] == :resque && NewRelic::LanguageSupport.can_fork? && - !NewRelic::Agent::PipeChannelManager.listener.started? + !PipeChannelManager.listener.started? end def in_resque_child_process? - defined?(@service) && @service.is_a?(NewRelic::Agent::PipeService) + defined?(@service) && @service.is_a?(PipeService) end # Sanity-check the agent configuration and start the agent, # setting up the worker thread and the exit handler to shut # down the agent @@ -557,15 +564,15 @@ # Clear out state for any objects that we know lock from our parents # This is necessary for cases where we're in a forked child and Ruby # might be holding locks for background thread that aren't there anymore. def reset_objects_with_locks - @stats_engine = NewRelic::Agent::StatsEngine.new + @stats_engine = StatsEngine.new end def flush_pipe_data - if connected? && @service.is_a?(::NewRelic::Agent::PipeService) + if connected? && @service.is_a?(PipeService) transmit_data transmit_analytic_event_data transmit_custom_event_data transmit_error_event_data transmit_span_event_data @@ -705,11 +712,11 @@ NewRelic::Agent.logger.info "Not starting Ruby Agent worker thread because :disable_harvest_thread is #{disable}" return end ::NewRelic::Agent.logger.debug "Creating Ruby Agent worker thread." - @worker_thread = NewRelic::Agent::Threading::AgentThread.create('Worker Loop') do + @worker_thread = Threading::AgentThread.create('Worker Loop') do deferred_work!(connection_options) end end # A shorthand for NewRelic::Control.instance @@ -1022,10 +1029,10 @@ container.merge!(payload) end end def harvest_and_send_timeslice_data - NewRelic::Agent::TransactionTimeAggregator.harvest! + TransactionTimeAggregator.harvest! harvest_and_send_from_container(@stats_engine, :metric_data) end def harvest_and_send_slowest_sql harvest_and_send_from_container(@sql_sampler, :sql_trace_data)