ghazel-newrelic_rpm 3.1.0.1 → 3.4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +120 -35
- data/LICENSE +29 -2
- data/README.rdoc +2 -2
- data/bin/mongrel_rpm +0 -0
- data/bin/newrelic +0 -0
- data/bin/newrelic_cmd +0 -0
- data/lib/new_relic/agent.rb +50 -38
- data/lib/new_relic/agent/agent.rb +459 -337
- data/lib/new_relic/agent/beacon_configuration.rb +71 -11
- data/lib/new_relic/agent/browser_monitoring.rb +73 -14
- data/lib/new_relic/agent/busy_calculator.rb +11 -3
- data/lib/new_relic/agent/chained_call.rb +2 -2
- data/lib/new_relic/agent/database.rb +223 -0
- data/lib/new_relic/agent/error_collector.rb +231 -183
- data/lib/new_relic/agent/instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +10 -2
- data/lib/new_relic/agent/instrumentation/active_record.rb +138 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +7 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +6 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +46 -14
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +11 -3
- data/lib/new_relic/agent/instrumentation/memcache.rb +49 -25
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +7 -2
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +31 -4
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -5
- data/lib/new_relic/agent/instrumentation/net.rb +8 -2
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -2
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +66 -35
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +121 -1
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +21 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -20
- data/lib/new_relic/agent/instrumentation/sunspot.rb +6 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +7 -2
- data/lib/new_relic/agent/method_tracer.rb +205 -99
- data/lib/new_relic/agent/new_relic_service.rb +221 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +161 -0
- data/lib/new_relic/agent/pipe_service.rb +54 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +89 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -7
- data/lib/new_relic/agent/shim_agent.rb +5 -5
- data/lib/new_relic/agent/sql_sampler.rb +282 -0
- data/lib/new_relic/agent/stats_engine.rb +2 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +35 -30
- data/lib/new_relic/agent/stats_engine/samplers.rb +10 -4
- data/lib/new_relic/agent/stats_engine/transactions.rb +28 -87
- data/lib/new_relic/agent/transaction_info.rb +74 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +18 -3
- data/lib/new_relic/agent/transaction_sampler.rb +108 -20
- data/lib/new_relic/agent/worker_loop.rb +14 -6
- data/lib/new_relic/collection_helper.rb +19 -11
- data/lib/new_relic/command.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +2 -2
- data/lib/new_relic/commands/install.rb +2 -13
- data/lib/new_relic/control.rb +2 -3
- data/lib/new_relic/control/class_methods.rb +12 -6
- data/lib/new_relic/control/configuration.rb +57 -8
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +4 -4
- data/lib/new_relic/control/frameworks/merb.rb +2 -1
- data/lib/new_relic/control/frameworks/rails.rb +35 -22
- data/lib/new_relic/control/frameworks/rails3.rb +12 -7
- data/lib/new_relic/control/frameworks/ruby.rb +5 -5
- data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
- data/lib/new_relic/control/instance_methods.rb +38 -12
- data/lib/new_relic/control/instrumentation.rb +23 -4
- data/lib/new_relic/control/logging_methods.rb +70 -15
- data/lib/new_relic/control/server_methods.rb +22 -9
- data/lib/new_relic/delayed_job_injection.rb +16 -3
- data/lib/new_relic/helper.rb +21 -0
- data/lib/new_relic/language_support.rb +95 -0
- data/lib/new_relic/local_environment.rb +92 -48
- data/lib/new_relic/metric_data.rb +7 -2
- data/lib/new_relic/metric_spec.rb +12 -9
- data/lib/new_relic/noticed_error.rb +6 -1
- data/lib/new_relic/rack/browser_monitoring.rb +18 -19
- data/lib/new_relic/rack/developer_mode.rb +3 -2
- data/lib/new_relic/recipes.rb +8 -4
- data/lib/new_relic/stats.rb +17 -60
- data/lib/new_relic/transaction_analysis.rb +2 -1
- data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
- data/lib/new_relic/transaction_sample.rb +60 -75
- data/lib/new_relic/transaction_sample/segment.rb +31 -79
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +1 -1
- data/newrelic.yml +2 -2
- data/newrelic_rpm.gemspec +46 -54
- data/test/active_record_fixtures.rb +3 -3
- data/test/config/newrelic.yml +1 -1
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/new_relic/agent/agent/connect_test.rb +128 -25
- data/test/new_relic/agent/agent/start_test.rb +9 -94
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -4
- data/test/new_relic/agent/agent_test.rb +51 -78
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +49 -33
- data/test/new_relic/agent/beacon_configuration_test.rb +12 -5
- data/test/new_relic/agent/browser_monitoring_test.rb +99 -50
- data/test/new_relic/agent/database_test.rb +161 -0
- data/test/new_relic/agent/error_collector_test.rb +47 -23
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +96 -42
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -11
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +9 -9
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +6 -11
- data/test/new_relic/agent/memcache_instrumentation_test.rb +54 -18
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
- data/test/new_relic/agent/method_tracer_test.rb +3 -2
- 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 +4 -31
- data/test/new_relic/agent/sql_sampler_test.rb +192 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +19 -18
- data/test/new_relic/agent/stats_engine_test.rb +41 -6
- data/test/new_relic/agent/transaction_info_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +27 -4
- data/test/new_relic/agent/transaction_sampler_test.rb +68 -46
- data/test/new_relic/agent/worker_loop_test.rb +3 -3
- data/test/new_relic/agent_test.rb +242 -0
- data/test/new_relic/collection_helper_test.rb +50 -28
- data/test/new_relic/control/configuration_test.rb +77 -0
- data/test/new_relic/control/logging_methods_test.rb +49 -21
- data/test/new_relic/control_test.rb +115 -54
- data/test/new_relic/delayed_job_injection_test.rb +21 -0
- data/test/new_relic/fake_collector.rb +210 -0
- data/test/new_relic/fake_service.rb +44 -0
- data/test/new_relic/local_environment_test.rb +14 -1
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +84 -23
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +31 -0
- data/test/new_relic/stats_test.rb +3 -18
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
- data/test/new_relic/transaction_analysis_test.rb +3 -3
- data/test/new_relic/transaction_sample/segment_test.rb +15 -80
- data/test/new_relic/transaction_sample_test.rb +25 -18
- data/test/script/build_test_gem.sh +51 -0
- data/test/script/ci.sh +140 -0
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +1 -0
- data/test/test_helper.rb +18 -5
- data/ui/helpers/developer_mode_helper.rb +14 -8
- data/ui/helpers/google_pie_chart.rb +0 -1
- data/ui/views/newrelic/index.rhtml +2 -2
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +10 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +17 -4
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
- metadata +50 -36
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +0 -108
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +0 -112
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
- data/lib/new_relic/data_serialization.rb +0 -84
- data/lib/new_relic/histogram.rb +0 -91
- data/lib/new_relic/rack/metric_app.rb +0 -65
- data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
- data/lib/new_relic/rack/newrelic.yml +0 -27
- data/lib/new_relic/rack_app.rb +0 -6
- data/test/new_relic/data_serialization_test.rb +0 -70
- data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
@@ -1,13 +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
6
|
include NewRelic::Agent::Agent::Connect
|
5
|
-
|
7
|
+
|
6
8
|
def setup
|
7
9
|
@connected = nil
|
8
10
|
@keep_retrying = nil
|
9
11
|
@connect_attempts = 1
|
10
12
|
@connect_retry_period = 0
|
13
|
+
@transaction_sampler = NewRelic::Agent::TransactionSampler.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
|
11
28
|
end
|
12
29
|
|
13
30
|
def test_tried_to_connect?
|
@@ -206,22 +223,40 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
206
223
|
enable_random_samples!(sampling_rate)
|
207
224
|
end
|
208
225
|
|
226
|
+
def test_config_transaction_tracer
|
227
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {
|
228
|
+
'enabled' => true,
|
229
|
+
'random_sample' => false,
|
230
|
+
'explain_threshold' => 0.75,
|
231
|
+
'explain_enabled' => true
|
232
|
+
}
|
233
|
+
|
234
|
+
config_transaction_tracer
|
235
|
+
|
236
|
+
assert @transaction_sampler.enabled?
|
237
|
+
assert_equal 0.75, @transaction_sampler.explain_threshold
|
238
|
+
assert @transaction_sampler.explain_enabled
|
239
|
+
# assert_equal 1.5, @transaction_sampler.transaction_threshold
|
240
|
+
end
|
241
|
+
|
209
242
|
def test_configure_transaction_tracer_with_random_sampling
|
210
243
|
@config_should_send_samples = true
|
211
244
|
@should_send_random_samples = true
|
212
245
|
@slowest_transaction_threshold = 5
|
213
|
-
log.
|
246
|
+
log.stubs(:debug)
|
214
247
|
self.expects(:enable_random_samples!).with(10)
|
215
248
|
configure_transaction_tracer!(true, 10)
|
216
249
|
assert @should_send_samples
|
250
|
+
assert_equal 5, @transaction_sampler.slow_capture_threshold
|
217
251
|
end
|
218
252
|
|
219
253
|
def test_configure_transaction_tracer_positive
|
220
254
|
@config_should_send_samples = true
|
221
255
|
@slowest_transaction_threshold = 5
|
222
|
-
log.
|
256
|
+
log.stubs(:debug)
|
223
257
|
configure_transaction_tracer!(true, 10)
|
224
258
|
assert @should_send_samples
|
259
|
+
assert_equal 5, @transaction_sampler.slow_capture_threshold
|
225
260
|
end
|
226
261
|
|
227
262
|
def test_configure_transaction_tracer_negative
|
@@ -238,38 +273,90 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
238
273
|
assert !@should_send_samples
|
239
274
|
end
|
240
275
|
|
241
|
-
def
|
242
|
-
|
243
|
-
|
244
|
-
control.expects(:server_from_host).with('collector-deux.newrelic.com').returns('correct')
|
245
|
-
set_collector_host!
|
246
|
-
assert_equal 'correct', @collector
|
276
|
+
def test_apdex_f
|
277
|
+
NewRelic::Control.instance.expects(:apdex_t).returns(10)
|
278
|
+
assert_equal 40, apdex_f
|
247
279
|
end
|
248
280
|
|
249
|
-
def
|
250
|
-
|
251
|
-
|
252
|
-
self.expects(:invoke_remote).with(:get_redirect_host).returns(nil)
|
253
|
-
set_collector_host!
|
254
|
-
assert_equal 'initial value', @collector, "should not modify collector value"
|
281
|
+
def test_apdex_f_threshold_positive
|
282
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = { 'transaction_threshold' => 'apdex_f' }
|
283
|
+
assert apdex_f_threshold?
|
255
284
|
end
|
256
285
|
|
257
|
-
def
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
286
|
+
def test_apdex_f_threshold_negative
|
287
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = { 'transaction_threshold' => 'WHEE' }
|
288
|
+
assert !apdex_f_threshold?
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_set_sql_recording_default
|
292
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = { }
|
293
|
+
self.expects(:log_sql_transmission_warning?)
|
294
|
+
set_sql_recording!
|
295
|
+
assert_equal :obfuscated, @record_sql, " should default to :obfuscated, was #{@record_sql}"
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_set_sql_recording_off
|
299
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'off'}
|
300
|
+
self.expects(:log_sql_transmission_warning?)
|
301
|
+
set_sql_recording!
|
302
|
+
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_set_sql_recording_none
|
306
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'none'}
|
307
|
+
self.expects(:log_sql_transmission_warning?)
|
308
|
+
set_sql_recording!
|
309
|
+
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_set_sql_recording_raw
|
313
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'raw'}
|
314
|
+
self.expects(:log_sql_transmission_warning?)
|
315
|
+
set_sql_recording!
|
316
|
+
assert_equal :raw, @record_sql, "should be set to :raw, was #{@record_sql}"
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_set_sql_recording_falsy
|
320
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => false}
|
321
|
+
self.expects(:log_sql_transmission_warning?)
|
322
|
+
set_sql_recording!
|
323
|
+
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_log_sql_transmission_warning_negative
|
327
|
+
log = mocked_log
|
328
|
+
@record_sql = :obfuscated
|
329
|
+
log.expects(:warn).never
|
330
|
+
log_sql_transmission_warning?
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_log_sql_transmission_warning_positive
|
334
|
+
log = mocked_log
|
335
|
+
@record_sql = :raw
|
336
|
+
log.expects(:warn).with('Agent is configured to send raw SQL to the service')
|
337
|
+
log_sql_transmission_warning?
|
264
338
|
end
|
265
339
|
|
266
340
|
def test_query_server_for_configuration
|
267
|
-
self.expects(:set_collector_host!)
|
268
341
|
self.expects(:connect_to_server).returns("so happy")
|
269
342
|
self.expects(:finish_setup).with("so happy")
|
270
343
|
query_server_for_configuration
|
271
344
|
end
|
272
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
|
+
|
273
360
|
def test_finish_setup
|
274
361
|
config = {
|
275
362
|
'agent_run_id' => 'fishsticks',
|
@@ -279,15 +366,25 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
279
366
|
'collect_errors' => true,
|
280
367
|
'sample_rate' => 10
|
281
368
|
}
|
369
|
+
NewRelic::Control.instance.settings['transaction_tracer'] = {'enabled' => true}
|
282
370
|
self.expects(:log_connection!).with(config)
|
283
371
|
self.expects(:configure_transaction_tracer!).with(true, 10)
|
284
372
|
self.expects(:configure_error_collector!).with(true)
|
373
|
+
@transaction_sampler = stub('transaction sampler', :configure! => true,
|
374
|
+
:config => {})
|
375
|
+
@sql_sampler = stub('sql sampler', :configure! => true)
|
285
376
|
finish_setup(config)
|
286
|
-
assert_equal 'fishsticks', @agent_id
|
377
|
+
assert_equal 'fishsticks', @service.agent_id
|
287
378
|
assert_equal 'pasta sauce', @report_period
|
288
379
|
assert_equal 'tamales', @url_rules
|
289
380
|
end
|
290
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
|
+
|
291
388
|
private
|
292
389
|
|
293
390
|
def mocked_control
|
@@ -296,6 +393,12 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
296
393
|
fake_control
|
297
394
|
end
|
298
395
|
|
396
|
+
def mocked_log
|
397
|
+
fake_log = mock('log')
|
398
|
+
self.stubs(:log).returns(fake_log)
|
399
|
+
fake_log
|
400
|
+
end
|
401
|
+
|
299
402
|
def mocked_error_collector
|
300
403
|
fake_collector = mock('error collector')
|
301
404
|
self.stubs(:error_collector).returns(fake_collector)
|
@@ -51,91 +51,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
51
51
|
log_app_names
|
52
52
|
end
|
53
53
|
|
54
|
-
def test_apdex_f
|
55
|
-
NewRelic::Control.instance.expects(:apdex_t).returns(10)
|
56
|
-
assert_equal 40, apdex_f
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_apdex_f_threshold_positive
|
60
|
-
self.expects(:sampler_config).returns({'transaction_threshold' => 'apdex_f'})
|
61
|
-
assert apdex_f_threshold?
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_apdex_f_threshold_negative
|
65
|
-
self.expects(:sampler_config).returns({'transaction_threshold' => 'WHEE'})
|
66
|
-
assert !apdex_f_threshold?
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_set_sql_recording_default
|
70
|
-
self.expects(:sampler_config).returns({})
|
71
|
-
self.expects(:log_sql_transmission_warning?)
|
72
|
-
set_sql_recording!
|
73
|
-
assert_equal :obfuscated, @record_sql, " should default to :obfuscated, was #{@record_sql}"
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_set_sql_recording_off
|
77
|
-
self.expects(:sampler_config).returns({'record_sql' => 'off'})
|
78
|
-
self.expects(:log_sql_transmission_warning?)
|
79
|
-
set_sql_recording!
|
80
|
-
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_set_sql_recording_none
|
84
|
-
self.expects(:sampler_config).returns({'record_sql' => 'none'})
|
85
|
-
self.expects(:log_sql_transmission_warning?)
|
86
|
-
set_sql_recording!
|
87
|
-
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_set_sql_recording_raw
|
91
|
-
self.expects(:sampler_config).returns({'record_sql' => 'raw'})
|
92
|
-
self.expects(:log_sql_transmission_warning?)
|
93
|
-
set_sql_recording!
|
94
|
-
assert_equal :raw, @record_sql, "should be set to :raw, was #{@record_sql}"
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_set_sql_recording_falsy
|
98
|
-
self.expects(:sampler_config).returns({'record_sql' => false})
|
99
|
-
self.expects(:log_sql_transmission_warning?)
|
100
|
-
set_sql_recording!
|
101
|
-
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_log_sql_transmission_warning_negative
|
105
|
-
log = mocked_log
|
106
|
-
@record_sql = :obfuscated
|
107
|
-
log.expects(:warn).never
|
108
|
-
log_sql_transmission_warning?
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_log_sql_transmission_warning_positive
|
112
|
-
log = mocked_log
|
113
|
-
@record_sql = :raw
|
114
|
-
log.expects(:send).with(:warn, 'Agent is configured to send raw SQL to the service')
|
115
|
-
log_sql_transmission_warning?
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_sampler_config
|
119
|
-
control = mocked_control
|
120
|
-
control.expects(:fetch).with('transaction_tracer', {})
|
121
|
-
sampler_config
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_config_transaction_tracer
|
125
|
-
fake_sampler_config = mock('sampler config')
|
126
|
-
self.expects(:sampler_config).times(5).returns(fake_sampler_config)
|
127
|
-
fake_sampler_config.expects(:fetch).with('enabled', true)
|
128
|
-
fake_sampler_config.expects(:fetch).with('random_sample', false)
|
129
|
-
fake_sampler_config.expects(:fetch).with('explain_threshold', 0.5)
|
130
|
-
fake_sampler_config.expects(:fetch).with('explain_enabled', true)
|
131
|
-
self.expects(:set_sql_recording!)
|
132
|
-
|
133
|
-
fake_sampler_config.expects(:fetch).with('transaction_threshold', 2.0)
|
134
|
-
self.expects(:apdex_f_threshold?).returns(true)
|
135
|
-
self.expects(:apdex_f)
|
136
|
-
config_transaction_tracer
|
137
|
-
end
|
138
|
-
|
139
54
|
def test_check_config_and_start_agent_disabled
|
140
55
|
self.expects(:monitoring?).returns(false)
|
141
56
|
check_config_and_start_agent
|
@@ -190,8 +105,8 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
190
105
|
def test_install_exit_handler_positive
|
191
106
|
control = mocked_control
|
192
107
|
control.expects(:send_data_on_exit).returns(true)
|
193
|
-
|
194
|
-
|
108
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
109
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
|
195
110
|
self.expects(:using_sinatra?).returns(false)
|
196
111
|
# we are overriding at_exit above, to immediately return, so we can
|
197
112
|
# test the shutdown logic. It's somewhat unfortunate, but we can't
|
@@ -209,21 +124,21 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
209
124
|
def test_install_exit_handler_weird_ruby
|
210
125
|
control = mocked_control
|
211
126
|
control.expects(:send_data_on_exit).times(3).returns(true)
|
212
|
-
|
213
|
-
|
127
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
128
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
|
214
129
|
self.expects(:using_sinatra?).returns(true)
|
215
130
|
install_exit_handler
|
216
|
-
|
217
|
-
|
131
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
132
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(true)
|
218
133
|
install_exit_handler
|
219
|
-
|
134
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(true)
|
220
135
|
install_exit_handler
|
221
136
|
end
|
222
137
|
|
223
138
|
def test_notify_log_file_location_positive
|
224
139
|
log = mocked_log
|
225
|
-
NewRelic::Control.instance.expects(:log_file).returns('
|
226
|
-
log.expects(:send).with(:info, "Agent Log
|
140
|
+
NewRelic::Control.instance.expects(:log_file).returns('./')
|
141
|
+
log.expects(:send).with(:info, "Agent Log at ./")
|
227
142
|
notify_log_file_location
|
228
143
|
end
|
229
144
|
|
@@ -8,6 +8,7 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
|
|
8
8
|
self.expects(:connect).with('connection_options')
|
9
9
|
@connected = true
|
10
10
|
self.expects(:check_transaction_sampler_status)
|
11
|
+
self.expects(:check_sql_sampler_status)
|
11
12
|
self.expects(:log_worker_loop_start)
|
12
13
|
self.expects(:create_and_run_worker_loop)
|
13
14
|
deferred_work!('connection_options')
|
@@ -63,10 +64,7 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
|
|
63
64
|
wl = mock('worker loop')
|
64
65
|
NewRelic::Agent::WorkerLoop.expects(:new).returns(wl)
|
65
66
|
wl.expects(:run).with(30).yields
|
66
|
-
self.expects(:
|
67
|
-
self.expects(:harvest_and_send_slowest_sample)
|
68
|
-
self.expects(:harvest_and_send_errors)
|
69
|
-
NewRelic::Agent.expects(:load_data)
|
67
|
+
self.expects(:transmit_data)
|
70
68
|
create_and_run_worker_loop
|
71
69
|
end
|
72
70
|
|
@@ -2,10 +2,33 @@ 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
|
8
|
+
@agent.service = NewRelic::FakeService.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_after_fork_reporting_to_channel
|
12
|
+
@agent.after_fork(:report_to_channel => 123)
|
13
|
+
assert(@agent.service.kind_of?(NewRelic::Agent::PipeService),
|
14
|
+
'Agent should use PipeService when directed to report to pipe channel')
|
15
|
+
assert_equal 123, @agent.service.channel_id
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_transmit_data_should_transmit
|
19
|
+
@agent.instance_eval { transmit_data }
|
20
|
+
assert @agent.service.agent_data.any?
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_transmit_data_should_close_explain_db_connections
|
24
|
+
NewRelic::Agent::Database.expects(:close_connections)
|
25
|
+
@agent.instance_eval { transmit_data }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_transmit_data_should_not_close_db_connections_if_forked
|
29
|
+
NewRelic::Agent::Database.expects(:close_connections).never
|
30
|
+
@agent.after_fork
|
31
|
+
@agent.instance_eval { transmit_data }
|
9
32
|
end
|
10
33
|
|
11
34
|
def test_serialize
|
@@ -17,7 +40,26 @@ module NewRelic
|
|
17
40
|
end
|
18
41
|
|
19
42
|
def test_harvest_timeslice_data
|
20
|
-
assert_equal({}, @agent.send(:harvest_timeslice_data),
|
43
|
+
assert_equal({}, @agent.send(:harvest_timeslice_data),
|
44
|
+
'should return timeslice data')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_harvest_timelice_data_should_be_thread_safe
|
48
|
+
2000.times do |i|
|
49
|
+
@agent.stats_engine.stats_hash[i.to_s] = NewRelic::StatsBase.new
|
50
|
+
end
|
51
|
+
|
52
|
+
harvest = Thread.new do
|
53
|
+
@agent.send(:harvest_timeslice_data)
|
54
|
+
end
|
55
|
+
|
56
|
+
app = Thread.new do
|
57
|
+
@agent.stats_engine.stats_hash["a"] = NewRelic::StatsBase.new
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_nothing_raised do
|
61
|
+
[app, harvest].each{|t| t.join}
|
62
|
+
end
|
21
63
|
end
|
22
64
|
|
23
65
|
def test_harvest_errors
|
@@ -89,85 +131,16 @@ module NewRelic
|
|
89
131
|
@unsent_timeslice_data = unsent_timeslice_data
|
90
132
|
@traces = unsent_traces
|
91
133
|
}
|
92
|
-
|
93
|
-
|
94
|
-
@agent.merge_data_from([{}, [], []])
|
134
|
+
unsent_traces.expects(:+).with([1,2,3])
|
135
|
+
unsent_errors.expects(:+).with([4,5,6])
|
136
|
+
@agent.merge_data_from([{}, [1,2,3], [4,5,6]])
|
95
137
|
end
|
96
138
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
@agent.send(:default_sql_obfuscator, "INSERT INTO X values('test',0, 1 , 2)")
|
102
|
-
|
103
|
-
# escaped literals
|
104
|
-
assert_equal "INSERT INTO X values(?, ?,?, ? , ?)",
|
105
|
-
@agent.send(:default_sql_obfuscator, "INSERT INTO X values('', 'jim''s ssn',0, 1 , 'jim''s son''s son')")
|
106
|
-
|
107
|
-
# multiple string literals
|
108
|
-
assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
|
109
|
-
@agent.send(:default_sql_obfuscator, "INSERT INTO X values('jim''s ssn','x',0, 1 , 2)")
|
110
|
-
|
111
|
-
# empty string literal
|
112
|
-
# NOTE: the empty string literal resolves to empty string, which for our purposes is acceptable
|
113
|
-
assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
|
114
|
-
@agent.send(:default_sql_obfuscator, "INSERT INTO X values('','x',0, 1 , 2)")
|
115
|
-
|
116
|
-
# try a select statement
|
117
|
-
assert_equal "select * from table where name=? and ssn=?",
|
118
|
-
@agent.send(:default_sql_obfuscator, "select * from table where name='jim gochee' and ssn=0012211223")
|
119
|
-
|
120
|
-
# number literals embedded in sql - oh well
|
121
|
-
assert_equal "select * from table_? where name=? and ssn=?",
|
122
|
-
@agent.send(:default_sql_obfuscator, "select * from table_007 where name='jim gochee' and ssn=0012211223")
|
139
|
+
def test_should_not_log_log_file_location_if_no_log_file
|
140
|
+
NewRelic::Control.instance.stubs(:log_file).returns('/vasrkjn4b3b4')
|
141
|
+
@agent.expects(:log).never
|
142
|
+
@agent.notify_log_file_location
|
123
143
|
end
|
124
|
-
|
125
|
-
def test_sql_normalization__single_quotes
|
126
|
-
assert_equal "INSERT ? into table",
|
127
|
-
@agent.send(:default_sql_obfuscator, "INSERT 'this isn''t a real value' into table")
|
128
|
-
assert_equal "INSERT ? into table",
|
129
|
-
@agent.send(:default_sql_obfuscator, %q[INSERT '"' into table])
|
130
|
-
assert_equal "INSERT ? into table",
|
131
|
-
@agent.send(:default_sql_obfuscator, %q[INSERT ' "some text" \" ' into table])
|
132
|
-
# could not get this one licked. no biggie
|
133
|
-
# assert_equal "INSERT ? into table",
|
134
|
-
# @agent.send(:default_sql_obfuscator, %q[INSERT '\'' into table])
|
135
|
-
assert_equal "INSERT ? into table",
|
136
|
-
@agent.send(:default_sql_obfuscator, %q[INSERT ''' ' into table])
|
137
|
-
end
|
138
|
-
def test_sql_normalization__double_quotes
|
139
|
-
assert_equal "INSERT ? into table",
|
140
|
-
@agent.send(:default_sql_obfuscator, %q[INSERT "this isn't a real value" into table])
|
141
|
-
assert_equal "INSERT ? into table",
|
142
|
-
@agent.send(:default_sql_obfuscator, %q[INSERT "'" into table])
|
143
|
-
assert_equal "INSERT ? into table",
|
144
|
-
@agent.send(:default_sql_obfuscator, %q[INSERT " \" " into table])
|
145
|
-
assert_equal "INSERT ? into table",
|
146
|
-
@agent.send(:default_sql_obfuscator, %q[INSERT " 'some text' " into table])
|
147
|
-
end
|
148
|
-
def test_sql_obfuscation_filters
|
149
|
-
@agent.set_sql_obfuscator(:replace) do |string|
|
150
|
-
"1" + string
|
151
|
-
end
|
152
|
-
|
153
|
-
sql = "SELECT * FROM TABLE 123 'jim'"
|
154
|
-
|
155
|
-
assert_equal "1" + sql, @agent.obfuscator.call(sql)
|
156
|
-
|
157
|
-
@agent.set_sql_obfuscator(:before) do |string|
|
158
|
-
"2" + string
|
159
|
-
end
|
160
|
-
|
161
|
-
assert_equal "12" + sql, @agent.obfuscator.call(sql)
|
162
|
-
|
163
|
-
@agent.set_sql_obfuscator(:after) do |string|
|
164
|
-
string + "3"
|
165
|
-
end
|
166
|
-
|
167
|
-
assert_equal "12" + sql + "3", @agent.obfuscator.call(sql)
|
168
|
-
end
|
169
|
-
|
170
|
-
|
171
144
|
end
|
172
145
|
end
|
173
146
|
end
|