newrelic_rpm 3.3.5 → 3.4.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +8 -5
- data/lib/new_relic/agent.rb +11 -3
- data/lib/new_relic/agent/agent.rb +68 -223
- data/lib/new_relic/agent/error_collector.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +2 -0
- data/lib/new_relic/agent/new_relic_service.rb +221 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +151 -0
- data/lib/new_relic/agent/pipe_service.rb +57 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +4 -34
- data/lib/new_relic/agent/sql_sampler.rb +1 -5
- data/lib/new_relic/agent/stats_engine/transactions.rb +2 -2
- data/lib/new_relic/agent/transaction_sampler.rb +0 -2
- data/lib/new_relic/control/configuration.rb +1 -1
- data/lib/new_relic/control/instance_methods.rb +2 -1
- data/lib/new_relic/language_support.rb +26 -0
- data/lib/new_relic/transaction_sample.rb +2 -6
- data/lib/new_relic/version.rb +3 -3
- data/newrelic_rpm.gemspec +16 -5
- data/test/new_relic/agent/agent/connect_test.rb +39 -23
- data/test/new_relic/agent/agent_test.rb +25 -4
- data/test/new_relic/agent/database_test.rb +12 -0
- data/test/new_relic/agent/new_relic_service_test.rb +151 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +114 -0
- data/test/new_relic/agent/pipe_service_test.rb +113 -0
- data/test/new_relic/agent/rpm_agent_test.rb +3 -30
- data/test/new_relic/agent/transaction_sample_builder_test.rb +0 -1
- data/test/new_relic/agent/transaction_sampler_test.rb +6 -6
- data/test/new_relic/agent/worker_loop_test.rb +2 -2
- data/test/new_relic/agent_test.rb +73 -3
- data/test/new_relic/control/configuration_test.rb +0 -7
- data/test/new_relic/control_test.rb +3 -3
- data/test/new_relic/delayed_job_injection_test.rb +6 -1
- data/test/new_relic/fake_collector.rb +210 -0
- data/test/new_relic/fake_service.rb +44 -0
- data/test/script/ci.sh +6 -6
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_multiverse_runner.sh +35 -0
- data/test/test_contexts.rb +1 -0
- data/test/test_helper.rb +3 -1
- metadata +359 -324
@@ -0,0 +1,57 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Agent
|
3
|
+
class PipeService
|
4
|
+
attr_reader :channel_id, :buffer, :stats_engine
|
5
|
+
attr_accessor :request_timeout, :agent_id, :collector
|
6
|
+
|
7
|
+
def initialize(channel_id)
|
8
|
+
@channel_id = channel_id
|
9
|
+
@collector = NewRelic::Control::Server.new(:name => 'parent',
|
10
|
+
:port => 0)
|
11
|
+
@stats_engine = NewRelic::Agent::StatsEngine.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def connect(config)
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def metric_data(last_harvest_time, now, unsent_timeslice_data)
|
19
|
+
@stats_engine.merge_data(hash_from_metric_data(unsent_timeslice_data))
|
20
|
+
stats = @stats_engine.harvest_timeslice_data({}, {})
|
21
|
+
write_to_pipe(:stats => stats) if stats
|
22
|
+
{}
|
23
|
+
end
|
24
|
+
|
25
|
+
def transaction_sample_data(transactions)
|
26
|
+
write_to_pipe(:transaction_traces => transactions) if transactions
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_data(errors)
|
30
|
+
write_to_pipe(:error_traces => errors) if errors
|
31
|
+
end
|
32
|
+
|
33
|
+
def sql_trace_data(sql)
|
34
|
+
write_to_pipe(:sql_traces => sql) if sql
|
35
|
+
end
|
36
|
+
|
37
|
+
def shutdown(time)
|
38
|
+
write_to_pipe('EOF')
|
39
|
+
NewRelic::Agent::PipeChannelManager.channels[@channel_id].close
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def hash_from_metric_data(metric_data)
|
45
|
+
metric_hash = {}
|
46
|
+
metric_data.each do |metric_entry|
|
47
|
+
metric_hash[metric_entry.metric_spec] = metric_entry
|
48
|
+
end
|
49
|
+
metric_hash
|
50
|
+
end
|
51
|
+
|
52
|
+
def write_to_pipe(data)
|
53
|
+
NewRelic::Agent::PipeChannelManager.channels[@channel_id].write(data)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -4,13 +4,6 @@ require 'new_relic/delayed_job_injection'
|
|
4
4
|
module NewRelic
|
5
5
|
module Agent
|
6
6
|
module Samplers
|
7
|
-
# This sampler records the status of your delayed job table once a minute.
|
8
|
-
# It assumes jobs are cleared after being run, and failed jobs are not (otherwise
|
9
|
-
# the failed job metric is useless).
|
10
|
-
#
|
11
|
-
# In earlier versions it will break out the queue length by priority. In later
|
12
|
-
# versions of DJ where distinct queues are supported, it breaks it out by queue name.
|
13
|
-
#
|
14
7
|
class DelayedJobSampler < NewRelic::Agent::Sampler
|
15
8
|
def initialize
|
16
9
|
super :delayed_job_queue
|
@@ -18,6 +11,9 @@ module NewRelic
|
|
18
11
|
raise Unsupported, "No DJ worker present" unless NewRelic::DelayedJobInjection.worker_name
|
19
12
|
end
|
20
13
|
|
14
|
+
def queue_stats
|
15
|
+
stats_engine.get_stats("Workers/DelayedJob/queue_length", false)
|
16
|
+
end
|
21
17
|
def error_stats
|
22
18
|
stats_engine.get_stats("Workers/DelayedJob/failed_jobs", false)
|
23
19
|
end
|
@@ -48,38 +44,12 @@ module NewRelic
|
|
48
44
|
end
|
49
45
|
|
50
46
|
def poll
|
47
|
+
record queue_stats, queued_jobs
|
51
48
|
record error_stats, failed_jobs
|
52
49
|
record locked_job_stats, locked_jobs
|
53
|
-
|
54
|
-
if @queue
|
55
|
-
record_queue_length_across_dimension('queue')
|
56
|
-
else
|
57
|
-
record_queue_length_across_dimension('priority')
|
58
|
-
end
|
59
50
|
end
|
60
51
|
|
61
52
|
private
|
62
|
-
|
63
|
-
def record_queue_length_across_dimension(column)
|
64
|
-
all_count = 0
|
65
|
-
Delayed::Job.count(:group => column).each do | column_val, count |
|
66
|
-
all_count += count
|
67
|
-
record stats_engine.get_stats("Workers/DelayedJob/queue_length/#{column == 'queue' ? 'name' : column}/#{column_val}", false), count
|
68
|
-
end
|
69
|
-
record(stats_engine.get_stats("Workers/DelayedJob/queue_length/all", false), all_count)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Figure out if we get the queues.
|
73
|
-
def setup
|
74
|
-
return unless @queue.nil?
|
75
|
-
@setup = true
|
76
|
-
columns = Delayed::Job.columns
|
77
|
-
columns.each do | c |
|
78
|
-
@queue = true if c.name.to_s == 'priority'
|
79
|
-
end
|
80
|
-
@queue ||= false
|
81
|
-
end
|
82
|
-
|
83
53
|
def record(stat, size)
|
84
54
|
stat.record_data_point size
|
85
55
|
end
|
@@ -245,11 +245,7 @@ module NewRelic
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def prepare_to_send
|
248
|
-
|
249
|
-
params[:explain_plan] = @slow_sql.explain if need_to_explain?
|
250
|
-
ensure
|
251
|
-
NewRelic::Agent::Database.close_connections
|
252
|
-
end
|
248
|
+
params[:explain_plan] = @slow_sql.explain if need_to_explain?
|
253
249
|
@sql = @slow_sql.obfuscate if need_to_obfuscate?
|
254
250
|
end
|
255
251
|
|
@@ -46,7 +46,6 @@ module Agent
|
|
46
46
|
# TransactionSample::Segment at the end of transaction execution
|
47
47
|
def push_scope(metric, time = Time.now.to_f, deduct_call_time_from_parent = true)
|
48
48
|
stack = scope_stack
|
49
|
-
stack.empty? ? GCProfiler.init : GCProfiler.capture
|
50
49
|
@transaction_sampler.notice_push_scope metric, time if @transaction_sampler
|
51
50
|
scope = ScopeStackElement.new(metric, deduct_call_time_from_parent)
|
52
51
|
stack.push scope
|
@@ -56,7 +55,6 @@ module Agent
|
|
56
55
|
# Pops a scope off the transaction stack - this updates the
|
57
56
|
# transaction sampler that we've finished execution of a traced method
|
58
57
|
def pop_scope(expected_scope, duration, time=Time.now.to_f)
|
59
|
-
GCProfiler.capture
|
60
58
|
stack = scope_stack
|
61
59
|
scope = stack.pop
|
62
60
|
fail "unbalanced pop from blame stack, got #{scope ? scope.name : 'nil'}, expected #{expected_scope ? expected_scope.name : 'nil'}" if scope != expected_scope
|
@@ -98,6 +96,7 @@ module Agent
|
|
98
96
|
def start_transaction(name = nil)
|
99
97
|
Thread::current[:newrelic_scope_stack] ||= []
|
100
98
|
self.scope_name = name if name
|
99
|
+
GCProfiler.init
|
101
100
|
end
|
102
101
|
|
103
102
|
# Try to clean up gracefully, otherwise we leave things hanging around on thread locals.
|
@@ -105,6 +104,7 @@ module Agent
|
|
105
104
|
# and is ignored.
|
106
105
|
#
|
107
106
|
def end_transaction
|
107
|
+
GCProfiler.capture
|
108
108
|
stack = scope_stack
|
109
109
|
|
110
110
|
if stack && stack.empty?
|
@@ -166,7 +166,6 @@ module NewRelic
|
|
166
166
|
# It sets various instance variables to the finished sample,
|
167
167
|
# depending on which settings are active. See `store_sample`
|
168
168
|
def notice_scope_empty(time=Time.now)
|
169
|
-
|
170
169
|
last_builder = builder
|
171
170
|
return unless last_builder
|
172
171
|
|
@@ -363,7 +362,6 @@ module NewRelic
|
|
363
362
|
# sample returned will be the slowest sample among those
|
364
363
|
# available during this harvest
|
365
364
|
def add_samples_to(result, slow_threshold)
|
366
|
-
|
367
365
|
# pull out force persist
|
368
366
|
force_persist = result.select {|sample| sample.force_persist} || []
|
369
367
|
result.reject! {|sample| sample.force_persist}
|
@@ -119,7 +119,7 @@ module NewRelic
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def disable_serialization?
|
122
|
-
fetch('disable_serialization',
|
122
|
+
fetch('disable_serialization', true)
|
123
123
|
end
|
124
124
|
def disable_serialization=(b)
|
125
125
|
self['disable_serialization'] = b
|
@@ -52,7 +52,8 @@ module NewRelic
|
|
52
52
|
environment_name = options.delete(:env) and self.env = environment_name
|
53
53
|
dispatcher = options.delete(:dispatcher) and @local_env.dispatcher = dispatcher
|
54
54
|
dispatcher_instance_id = options.delete(:dispatcher_instance_id) and @local_env.dispatcher_instance_id = dispatcher_instance_id
|
55
|
-
|
55
|
+
|
56
|
+
NewRelic::Agent::PipeChannelManager.listener.start if options.delete(:start_channel_listener)
|
56
57
|
|
57
58
|
# Clear out the settings, if they've already been loaded. It may be that
|
58
59
|
# between calling init_plugin the first time and the second time, the env
|
@@ -58,6 +58,22 @@ module NewRelic::LanguageSupport
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
@@forkable = nil
|
62
|
+
|
63
|
+
def can_fork?
|
64
|
+
# this is expensive to check, so we should only check once
|
65
|
+
return @@forkable if @@forkable != nil
|
66
|
+
|
67
|
+
if Process.respond_to?(:fork)
|
68
|
+
# if this is not 1.9.2 or higher, we have to make sure
|
69
|
+
@@forkable = ::RUBY_VERSION < '1.9.2' ? test_forkability : true
|
70
|
+
else
|
71
|
+
@@forkable = false
|
72
|
+
end
|
73
|
+
|
74
|
+
@@forkable
|
75
|
+
end
|
76
|
+
|
61
77
|
def using_engine?(engine)
|
62
78
|
if defined?(::RUBY_ENGINE)
|
63
79
|
::RUBY_ENGINE == engine
|
@@ -70,4 +86,14 @@ module NewRelic::LanguageSupport
|
|
70
86
|
numbers = version.split('.')
|
71
87
|
numbers == ::RUBY_VERSION.split('.')[0, numbers.size]
|
72
88
|
end
|
89
|
+
|
90
|
+
def test_forkability
|
91
|
+
child = Process.fork { exit! }
|
92
|
+
# calling wait here doesn't seem like it should necessary, but it seems to
|
93
|
+
# resolve some weird edge cases with resque forking.
|
94
|
+
Process.wait child
|
95
|
+
true
|
96
|
+
rescue NotImplementedError
|
97
|
+
false
|
98
|
+
end
|
73
99
|
end
|
@@ -159,12 +159,8 @@ module NewRelic
|
|
159
159
|
sample.guid = self.guid
|
160
160
|
sample.force_persist = self.force_persist if self.force_persist
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
ensure
|
165
|
-
NewRelic::Agent::Database.close_connections
|
166
|
-
end
|
167
|
-
|
162
|
+
build_segment_for_transfer(sample, @root_segment, sample.root_segment, options)
|
163
|
+
|
168
164
|
sample.root_segment.end_trace(@root_segment.exit_timestamp)
|
169
165
|
sample
|
170
166
|
end
|
data/lib/new_relic/version.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
module NewRelic
|
3
3
|
module VERSION #:nodoc:
|
4
4
|
MAJOR = 3
|
5
|
-
MINOR =
|
6
|
-
TINY =
|
7
|
-
BUILD =
|
5
|
+
MINOR = 4
|
6
|
+
TINY = 0
|
7
|
+
BUILD = 'beta1' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
|
8
8
|
STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
|
9
9
|
end
|
10
10
|
|
data/newrelic_rpm.gemspec
CHANGED
@@ -5,14 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "newrelic_rpm"
|
8
|
-
s.version = "3.
|
8
|
+
s.version = "3.4.0.beta1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bill Kayser", "Jon Guymon", "Justin George", "Darin Swanson"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-25"
|
13
13
|
s.description = "New Relic is a performance management system, developed by New Relic,\nInc (http://www.newrelic.com). New Relic provides you with deep\ninformation about the performance of your web application as it runs\nin production. The New Relic Ruby Agent is dual-purposed as a either a\nGem or plugin, hosted on\nhttp://github.com/newrelic/rpm/\n"
|
14
14
|
s.email = "support@newrelic.com"
|
15
|
-
s.executables = ["
|
15
|
+
s.executables = ["newrelic", "mongrel_rpm", "newrelic_cmd"]
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"CHANGELOG",
|
18
18
|
"LICENSE",
|
@@ -62,10 +62,14 @@ Gem::Specification.new do |s|
|
|
62
62
|
"lib/new_relic/agent/instrumentation/rails/errors.rb",
|
63
63
|
"lib/new_relic/agent/instrumentation/rails3/action_controller.rb",
|
64
64
|
"lib/new_relic/agent/instrumentation/rails3/errors.rb",
|
65
|
+
"lib/new_relic/agent/instrumentation/resque.rb",
|
65
66
|
"lib/new_relic/agent/instrumentation/sinatra.rb",
|
66
67
|
"lib/new_relic/agent/instrumentation/sunspot.rb",
|
67
68
|
"lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb",
|
68
69
|
"lib/new_relic/agent/method_tracer.rb",
|
70
|
+
"lib/new_relic/agent/new_relic_service.rb",
|
71
|
+
"lib/new_relic/agent/pipe_channel_manager.rb",
|
72
|
+
"lib/new_relic/agent/pipe_service.rb",
|
69
73
|
"lib/new_relic/agent/sampler.rb",
|
70
74
|
"lib/new_relic/agent/samplers/cpu_sampler.rb",
|
71
75
|
"lib/new_relic/agent/samplers/delayed_job_sampler.rb",
|
@@ -163,6 +167,9 @@ Gem::Specification.new do |s|
|
|
163
167
|
"test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb",
|
164
168
|
"test/new_relic/agent/method_tracer_test.rb",
|
165
169
|
"test/new_relic/agent/mock_scope_listener.rb",
|
170
|
+
"test/new_relic/agent/new_relic_service_test.rb",
|
171
|
+
"test/new_relic/agent/pipe_channel_manager_test.rb",
|
172
|
+
"test/new_relic/agent/pipe_service_test.rb",
|
166
173
|
"test/new_relic/agent/rpm_agent_test.rb",
|
167
174
|
"test/new_relic/agent/sampler_test.rb",
|
168
175
|
"test/new_relic/agent/shim_agent_test.rb",
|
@@ -184,6 +191,8 @@ Gem::Specification.new do |s|
|
|
184
191
|
"test/new_relic/control_test.rb",
|
185
192
|
"test/new_relic/data_serialization_test.rb",
|
186
193
|
"test/new_relic/delayed_job_injection_test.rb",
|
194
|
+
"test/new_relic/fake_collector.rb",
|
195
|
+
"test/new_relic/fake_service.rb",
|
187
196
|
"test/new_relic/local_environment_test.rb",
|
188
197
|
"test/new_relic/metric_data_test.rb",
|
189
198
|
"test/new_relic/metric_parser/metric_parser_test.rb",
|
@@ -204,7 +213,9 @@ Gem::Specification.new do |s|
|
|
204
213
|
"test/new_relic/version_number_test.rb",
|
205
214
|
"test/script/build_test_gem.sh",
|
206
215
|
"test/script/ci.sh",
|
216
|
+
"test/script/ci_agent-tests_runner.sh",
|
207
217
|
"test/script/ci_bench.sh",
|
218
|
+
"test/script/ci_multiverse_runner.sh",
|
208
219
|
"test/test_contexts.rb",
|
209
220
|
"test/test_helper.rb",
|
210
221
|
"ui/helpers/developer_mode_helper.rb",
|
@@ -286,7 +297,7 @@ Gem::Specification.new do |s|
|
|
286
297
|
"vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb"
|
287
298
|
]
|
288
299
|
s.homepage = "http://www.github.com/newrelic/rpm"
|
289
|
-
s.post_install_message = "\nPLEASE NOTE:\n\nDeveloper Mode is now a Rack middleware.\n\nDeveloper Mode is no longer available in Rails 2.1 and earlier.\nHowever, starting in version 2.12 you can use Developer Mode in any\nRack based framework, in addition to Rails. To install developer mode\nin a non-Rails application, just add NewRelic::Rack::DeveloperMode to\nyour middleware stack.\n\nIf you are using JRuby, we recommend using at least version 1.4 or \nlater because of issues with the implementation of the timeout library.\n\nRefer to the README.md file for more information.\n\nPlease see http://github.com/newrelic/rpm/blob/master/CHANGELOG\nfor a complete description of the features and enhancements available\nin version 3.
|
300
|
+
s.post_install_message = "\nPLEASE NOTE:\n\nDeveloper Mode is now a Rack middleware.\n\nDeveloper Mode is no longer available in Rails 2.1 and earlier.\nHowever, starting in version 2.12 you can use Developer Mode in any\nRack based framework, in addition to Rails. To install developer mode\nin a non-Rails application, just add NewRelic::Rack::DeveloperMode to\nyour middleware stack.\n\nIf you are using JRuby, we recommend using at least version 1.4 or \nlater because of issues with the implementation of the timeout library.\n\nRefer to the README.md file for more information.\n\nPlease see http://github.com/newrelic/rpm/blob/master/CHANGELOG\nfor a complete description of the features and enhancements available\nin version 3.4 of the Ruby Agent.\n \n"
|
290
301
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "New Relic Ruby Agent"]
|
291
302
|
s.require_paths = ["lib"]
|
292
303
|
s.summary = "New Relic Ruby Agent"
|
@@ -1,17 +1,30 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..', '..', '..','test_helper'))
|
2
|
+
require 'new_relic/agent/agent'
|
3
|
+
require 'ostruct'
|
4
|
+
|
2
5
|
class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
3
|
-
require 'new_relic/agent/agent'
|
4
|
-
|
5
|
-
# I don't like this, we should be testing a third party, not ourselves -Jon
|
6
6
|
include NewRelic::Agent::Agent::Connect
|
7
|
-
|
7
|
+
|
8
8
|
def setup
|
9
9
|
@connected = nil
|
10
10
|
@keep_retrying = nil
|
11
11
|
@connect_attempts = 1
|
12
12
|
@connect_retry_period = 0
|
13
13
|
@transaction_sampler = NewRelic::Agent::TransactionSampler.new
|
14
|
-
@sql_sampler = NewRelic::Agent::SqlSampler.new
|
14
|
+
@sql_sampler = NewRelic::Agent::SqlSampler.new
|
15
|
+
server = NewRelic::Control::Server.new('localhost', 30303)
|
16
|
+
@service = NewRelic::Agent::NewRelicService.new('abcdef', server)
|
17
|
+
end
|
18
|
+
|
19
|
+
def control
|
20
|
+
fake_control = OpenStruct.new('validate_seed' => false,
|
21
|
+
'local_env' => OpenStruct.new('snapshot' => []))
|
22
|
+
fake_control.instance_eval do
|
23
|
+
def [](key)
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
fake_control
|
15
28
|
end
|
16
29
|
|
17
30
|
def test_tried_to_connect?
|
@@ -324,29 +337,26 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
324
337
|
log_sql_transmission_warning?
|
325
338
|
end
|
326
339
|
|
327
|
-
def test_set_collector_host_positive
|
328
|
-
control = mocked_control
|
329
|
-
self.expects(:invoke_remote).with(:get_redirect_host).returns('collector-deux.newrelic.com')
|
330
|
-
control.expects(:server_from_host).with('collector-deux.newrelic.com').returns('correct')
|
331
|
-
set_collector_host!
|
332
|
-
assert_equal 'correct', @collector
|
333
|
-
end
|
334
|
-
|
335
|
-
def test_set_collector_host_negative
|
336
|
-
@collector = 'initial value'
|
337
|
-
control = mocked_control
|
338
|
-
self.expects(:invoke_remote).with(:get_redirect_host).returns(nil)
|
339
|
-
set_collector_host!
|
340
|
-
assert_equal 'initial value', @collector, "should not modify collector value"
|
341
|
-
end
|
342
|
-
|
343
340
|
def test_query_server_for_configuration
|
344
|
-
self.expects(:set_collector_host!)
|
345
341
|
self.expects(:connect_to_server).returns("so happy")
|
346
342
|
self.expects(:finish_setup).with("so happy")
|
347
343
|
query_server_for_configuration
|
348
344
|
end
|
349
345
|
|
346
|
+
def test_connect_to_server_gets_config_from_collector
|
347
|
+
service = NewRelic::FakeService.new
|
348
|
+
NewRelic::Agent::Agent.instance.service = service
|
349
|
+
NewRelic::Agent.manual_start
|
350
|
+
service.mock['connect'] = {'agent_run_id' => 23, 'config' => 'a lot'}
|
351
|
+
|
352
|
+
response = NewRelic::Agent.agent.connect_to_server
|
353
|
+
|
354
|
+
assert_equal 23, response['agent_run_id']
|
355
|
+
assert_equal 'a lot', response['config']
|
356
|
+
|
357
|
+
NewRelic::Agent.shutdown
|
358
|
+
end
|
359
|
+
|
350
360
|
def test_finish_setup
|
351
361
|
config = {
|
352
362
|
'agent_run_id' => 'fishsticks',
|
@@ -364,11 +374,17 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
364
374
|
:config => {})
|
365
375
|
@sql_sampler = stub('sql sampler', :configure! => true)
|
366
376
|
finish_setup(config)
|
367
|
-
assert_equal 'fishsticks', @agent_id
|
377
|
+
assert_equal 'fishsticks', @service.agent_id
|
368
378
|
assert_equal 'pasta sauce', @report_period
|
369
379
|
assert_equal 'tamales', @url_rules
|
370
380
|
end
|
371
381
|
|
382
|
+
def test_finish_setup_without_config
|
383
|
+
@service.agent_id = 'blah'
|
384
|
+
finish_setup(nil)
|
385
|
+
assert_equal 'blah', @service.agent_id
|
386
|
+
end
|
387
|
+
|
372
388
|
private
|
373
389
|
|
374
390
|
def mocked_control
|
@@ -2,12 +2,18 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
|
|
2
2
|
module NewRelic
|
3
3
|
module Agent
|
4
4
|
class AgentTest < Test::Unit::TestCase
|
5
|
-
|
6
5
|
def setup
|
7
6
|
super
|
8
7
|
@agent = NewRelic::Agent::Agent.new
|
9
8
|
end
|
10
9
|
|
10
|
+
def test_after_fork_reporting_to_channel
|
11
|
+
@agent.after_fork(:report_to_channel => 123)
|
12
|
+
assert(@agent.service.kind_of?(NewRelic::Agent::PipeService),
|
13
|
+
'Agent should use PipeService when directed to report to pipe channel')
|
14
|
+
assert_equal 123, @agent.service.channel_id
|
15
|
+
end
|
16
|
+
|
11
17
|
def test_save_or_transmit_data_should_save
|
12
18
|
NewRelic::Agent.expects(:save_data).once
|
13
19
|
@agent.expects(:harvest_and_send_timeslice_data).never
|
@@ -24,7 +30,22 @@ module NewRelic
|
|
24
30
|
NewRelic::DataSerialization.expects(:should_send_data?).returns(true)
|
25
31
|
@agent.instance_eval { save_or_transmit_data }
|
26
32
|
end
|
33
|
+
|
34
|
+
def test_save_or_transmit_data_should_close_explain_db_connections
|
35
|
+
NewRelic::Agent.stubs(:save_data)
|
36
|
+
NewRelic::DataSerialization.expects(:should_send_data?).returns(false)
|
37
|
+
NewRelic::Agent::Database.expects(:close_connections)
|
38
|
+
@agent.instance_eval { save_or_transmit_data }
|
39
|
+
end
|
27
40
|
|
41
|
+
def test_save_or_transmit_data_should_not_close_db_connections_if_forked
|
42
|
+
NewRelic::Agent.stubs(:save_data)
|
43
|
+
NewRelic::DataSerialization.expects(:should_send_data?).returns(false)
|
44
|
+
NewRelic::Agent::Database.expects(:close_connections).never
|
45
|
+
@agent.after_fork
|
46
|
+
@agent.instance_eval { save_or_transmit_data }
|
47
|
+
end
|
48
|
+
|
28
49
|
def test_serialize
|
29
50
|
assert_equal([{}, [], []], @agent.send(:serialize), "should return nil when shut down")
|
30
51
|
end
|
@@ -125,9 +146,9 @@ module NewRelic
|
|
125
146
|
@unsent_timeslice_data = unsent_timeslice_data
|
126
147
|
@traces = unsent_traces
|
127
148
|
}
|
128
|
-
|
129
|
-
|
130
|
-
@agent.merge_data_from([{}, [], []])
|
149
|
+
unsent_traces.expects(:+).with([1,2,3])
|
150
|
+
unsent_errors.expects(:+).with([4,5,6])
|
151
|
+
@agent.merge_data_from([{}, [1,2,3], [4,5,6]])
|
131
152
|
end
|
132
153
|
|
133
154
|
def test_should_not_log_log_file_location_if_no_log_file
|