newrelic_rpm 3.6.8.168 → 3.6.9.171

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +1 -0
  3. data/.yardopts +17 -0
  4. data/CHANGELOG +48 -0
  5. data/README.md +8 -6
  6. data/lib/new_relic/agent.rb +65 -17
  7. data/lib/new_relic/agent/agent.rb +42 -113
  8. data/lib/new_relic/agent/browser_monitoring.rb +9 -1
  9. data/lib/new_relic/agent/configuration/default_source.rb +12 -0
  10. data/lib/new_relic/agent/error_collector.rb +13 -6
  11. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +5 -5
  12. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +15 -0
  13. data/lib/new_relic/agent/instrumentation/curb.rb +2 -2
  14. data/lib/new_relic/agent/instrumentation/metric_frame.rb +2 -2
  15. data/lib/new_relic/agent/instrumentation/rack.rb +2 -0
  16. data/lib/new_relic/agent/instrumentation/resque.rb +9 -3
  17. data/lib/new_relic/agent/instrumentation/sidekiq.rb +5 -0
  18. data/lib/new_relic/agent/method_tracer.rb +45 -27
  19. data/lib/new_relic/agent/new_relic_service.rb +14 -6
  20. data/lib/new_relic/agent/pipe_service.rb +1 -1
  21. data/lib/new_relic/agent/request_sampler.rb +10 -7
  22. data/lib/new_relic/agent/rules_engine.rb +5 -0
  23. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  24. data/lib/new_relic/agent/sql_sampler.rb +4 -2
  25. data/lib/new_relic/agent/stats_engine.rb +3 -0
  26. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +17 -7
  27. data/lib/new_relic/agent/stats_engine/metric_stats.rb +5 -7
  28. data/lib/new_relic/agent/stats_engine/stats_hash.rb +2 -0
  29. data/lib/new_relic/agent/supported_versions.rb +247 -0
  30. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
  31. data/lib/new_relic/agent/threading/thread_profile.rb +2 -1
  32. data/lib/new_relic/agent/transaction.rb +7 -6
  33. data/lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb +11 -5
  34. data/lib/new_relic/agent/transaction/force_persist_sample_buffer.rb +3 -3
  35. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +3 -3
  36. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +23 -4
  37. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +4 -4
  38. data/lib/new_relic/agent/transaction_sampler.rb +14 -18
  39. data/lib/new_relic/agent/worker_loop.rb +1 -0
  40. data/lib/new_relic/control.rb +1 -0
  41. data/lib/new_relic/control/instance_methods.rb +0 -1
  42. data/lib/new_relic/helper.rb +1 -2
  43. data/lib/new_relic/language_support.rb +12 -2
  44. data/lib/new_relic/local_environment.rb +12 -11
  45. data/lib/new_relic/rack.rb +9 -0
  46. data/lib/new_relic/rack/agent_hooks.rb +6 -0
  47. data/lib/new_relic/rack/browser_monitoring.rb +9 -2
  48. data/lib/new_relic/rack/developer_mode.rb +15 -1
  49. data/lib/new_relic/rack/error_collector.rb +7 -0
  50. data/lib/new_relic/recipes.rb +2 -0
  51. data/lib/new_relic/transaction_sample.rb +39 -48
  52. data/lib/new_relic/version.rb +1 -1
  53. data/lib/tasks/install.rake +44 -2
  54. data/lib/tasks/versions.html.erb +31 -0
  55. data/lib/tasks/versions.rake +52 -0
  56. data/lib/tasks/versions.txt.erb +14 -0
  57. data/newrelic_rpm.gemspec +4 -2
  58. data/test/agent_helper.rb +21 -1
  59. data/test/environments/lib/environments/runner.rb +19 -5
  60. data/test/environments/norails/Gemfile +4 -1
  61. data/test/environments/rails21/Gemfile +4 -6
  62. data/test/environments/rails21/Rakefile +4 -0
  63. data/test/environments/rails21/config/database.yml +2 -7
  64. data/test/environments/rails22/Gemfile +6 -13
  65. data/test/environments/rails22/Rakefile +4 -0
  66. data/test/environments/rails22/config/database.yml +2 -7
  67. data/test/environments/rails22/config/environment.rb +1 -1
  68. data/test/environments/rails23/Gemfile +3 -4
  69. data/test/environments/rails23/Rakefile +4 -0
  70. data/test/environments/rails23/config/database.yml +2 -7
  71. data/test/environments/rails30/Gemfile +2 -4
  72. data/test/environments/rails30/Rakefile +2 -0
  73. data/test/environments/rails30/config/database.yml +2 -7
  74. data/test/environments/rails31/Gemfile +2 -4
  75. data/test/environments/rails31/Rakefile +2 -0
  76. data/test/environments/rails31/config/database.yml +2 -7
  77. data/test/environments/rails32/Gemfile +2 -5
  78. data/test/environments/rails32/Rakefile +2 -0
  79. data/test/environments/rails32/config/database.yml +1 -1
  80. data/test/environments/rails40/Gemfile +7 -4
  81. data/test/environments/rails40/Rakefile +2 -0
  82. data/test/environments/rails40/config/database.yml +2 -7
  83. data/test/helpers/runtime_detection.rb +17 -0
  84. data/test/multiverse/lib/multiverse/suite.rb +20 -4
  85. data/test/multiverse/suites/agent_only/key_transactions_test.rb +1 -1
  86. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  87. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +32 -7
  88. data/test/multiverse/suites/agent_only/xray_sessions_test.rb +1 -0
  89. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +4 -3
  90. data/test/multiverse/suites/curb/curb_test.rb +8 -0
  91. data/test/multiverse/suites/excon/excon_test.rb +8 -0
  92. data/test/multiverse/suites/httpclient/httpclient_test.rb +8 -0
  93. data/test/multiverse/suites/net_http/net_http_test.rb +8 -0
  94. data/test/multiverse/suites/padrino/Envfile +3 -2
  95. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +17 -8
  96. data/test/multiverse/suites/resque/Envfile +3 -3
  97. data/test/multiverse/suites/resque/instrumentation_test.rb +47 -5
  98. data/test/multiverse/suites/sequel/Envfile +0 -3
  99. data/test/multiverse/suites/sequel/database.rb +53 -0
  100. data/test/{new_relic/agent/instrumentation/sequel_test.rb → multiverse/suites/sequel/sequel_instrumentation_test.rb} +12 -53
  101. data/test/multiverse/suites/sequel/{sequel_test.rb → sequel_safety_test.rb} +2 -17
  102. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +50 -5
  103. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +15 -2
  104. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +8 -0
  105. data/test/new_relic/agent/agent/connect_test.rb +3 -2
  106. data/test/new_relic/agent/agent_test.rb +89 -82
  107. data/test/new_relic/agent/browser_monitoring_test.rb +44 -1
  108. data/test/new_relic/agent/error_collector_test.rb +17 -20
  109. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +13 -10
  110. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +16 -1
  111. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
  112. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  113. data/test/new_relic/agent/new_relic_service_test.rb +78 -9
  114. data/test/new_relic/agent/pipe_channel_manager_test.rb +7 -9
  115. data/test/new_relic/agent/pipe_service_test.rb +4 -4
  116. data/test/new_relic/agent/request_sampler_test.rb +2 -2
  117. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +15 -35
  118. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +15 -7
  119. data/test/new_relic/agent/stats_engine_test.rb +4 -3
  120. data/test/new_relic/agent/threading/backtrace_service_test.rb +2 -0
  121. data/test/new_relic/agent/threading/thread_profile_test.rb +19 -0
  122. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +4 -4
  123. data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +1 -1
  124. data/test/new_relic/agent/transaction_sampler_test.rb +60 -45
  125. data/test/new_relic/fake_collector.rb +37 -2
  126. data/test/new_relic/http_client_test_cases.rb +26 -1
  127. data/test/new_relic/language_support_test.rb +12 -31
  128. data/test/new_relic/local_environment_test.rb +6 -2
  129. data/test/new_relic/multiverse_helpers.rb +2 -5
  130. data/test/new_relic/transaction_sample_test.rb +57 -36
  131. data/test/performance/suites/config.rb +76 -0
  132. data/test/rum/no_html_and_no_header.result.html +3 -0
  133. data/test/rum/no_html_and_no_header.source.html +3 -0
  134. data/test/script/ci.sh +0 -2
  135. data/test/test_helper.rb +5 -0
  136. metadata +43 -26
  137. metadata.gz.sig +0 -0
@@ -386,11 +386,11 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
386
386
  assert_not_nil sql_segment, sample.to_s
387
387
  assert_match /^SELECT /, sql_segment.params[:sql]
388
388
  assert sql_segment.duration > 0.0, "Segment duration must be greater than zero."
389
- sample = sample.prepare_to_send(:record_sql => :raw, :explain_sql => 0.0)
389
+ sample = sample.prepare_to_send!(:record_sql => :raw, :explain_sql => 0.0)
390
390
  sql_segment = last_segment(sample)
391
391
  assert_match /^SELECT /, sql_segment.params[:sql]
392
392
  explanations = sql_segment.params[:explain_plan]
393
- if isMysql? || isPostgres?
393
+ if (isMysql? || isPostgres?) && !NewRelic::LanguageSupport.using_engine?('jruby')
394
394
  assert_not_nil explanations, "No explains in segment: #{sql_segment}"
395
395
  assert_equal(2, explanations.size,
396
396
  "No explains in segment: #{sql_segment}")
@@ -408,7 +408,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
408
408
  end
409
409
 
410
410
  sample = NewRelic::Agent.instance.transaction_sampler.last_sample
411
- sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
411
+ sample = sample.prepare_to_send!(:record_sql => :obfuscated, :explain_sql => 0.0)
412
412
  segment = last_segment(sample)
413
413
  explanation = segment.params[:explain_plan]
414
414
  assert_not_nil explanation, "No explains in segment: #{segment}"
@@ -438,7 +438,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
438
438
 
439
439
  sample = NewRelic::Agent.instance.transaction_sampler.last_sample
440
440
 
441
- sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
441
+ sample = sample.prepare_to_send!(:record_sql => :obfuscated, :explain_sql => 0.0)
442
442
  segment = last_segment(sample)
443
443
  explanations = segment.params[:explain_plan]
444
444
 
@@ -463,7 +463,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
463
463
 
464
464
  sample = NewRelic::Agent.instance.transaction_sampler.last_sample
465
465
 
466
- sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
466
+ sample = sample.prepare_to_send!(:record_sql => :obfuscated, :explain_sql => 0.0)
467
467
  segment = last_segment(sample)
468
468
 
469
469
  s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
@@ -517,9 +517,12 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
517
517
 
518
518
  assert_metrics_recorded(
519
519
  'ActiveRecord/all' => { :call_count => 1 },
520
- 'Database/SQL/select' => { :call_count => 1 },
521
- "RemoteService/sql/#{adapter}/localhost" => { :call_count => 1 }
520
+ 'Database/SQL/select' => { :call_count => 1 }
522
521
  )
522
+
523
+ if !NewRelic::LanguageSupport.using_engine?('jruby')
524
+ assert_metrics_recorded("RemoteService/sql/#{adapter}/localhost" => { :call_count => 1 })
525
+ end
523
526
  end
524
527
 
525
528
  def test_rescue_handling
@@ -536,17 +539,17 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
536
539
  end
537
540
 
538
541
  def test_remote_service_metric_respects_dynamic_connection_config
539
- return unless isMysql?
542
+ return unless isMysql? && !NewRelic::LanguageSupport.using_engine?('jruby')
540
543
 
541
544
  ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
542
- assert(NewRelic::Agent.get_stats("RemoteService/sql/#{adapter}/localhost").call_count != 0)
545
+ assert_metrics_recorded(["RemoteService/sql/#{adapter}/localhost"])
543
546
 
544
547
  config = ActiveRecordFixtures::Shipment.connection.instance_eval { @config }
545
548
  config[:host] = '127.0.0.1'
546
549
  connection = ActiveRecordFixtures::Shipment.establish_connection(config)
547
550
 
548
551
  ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
549
- assert(NewRelic::Agent.get_stats("RemoteService/sql/#{adapter}/127.0.0.1").call_count != 0)
552
+ assert_metrics_recorded(["RemoteService/sql/#{adapter}/127.0.0.1"])
550
553
 
551
554
  config[:host] = 'localhost'
552
555
  ActiveRecordFixtures::Shipment.establish_connection(config)
@@ -16,7 +16,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
16
16
  @config = { :adapter => 'mysql', :host => 'server' }
17
17
  @connection = Object.new
18
18
  @connection.instance_variable_set(:@config, @config)
19
- Order.stubs(:connection_pool).returns(stub(:connections => [ @connection ]))
19
+
20
20
 
21
21
  @params = {
22
22
  :name => 'NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order Load',
@@ -73,6 +73,10 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
73
73
  end
74
74
 
75
75
  def test_records_remote_service_metric
76
+ connection_pool = stub(:connections => [ @connection ])
77
+ connection_pool_list = [connection_pool]
78
+ ::ActiveRecord::Base.connection_handler.stubs(:connection_pool_list).returns(connection_pool_list)
79
+
76
80
  freeze_time
77
81
 
78
82
  simulate_query(2)
@@ -128,6 +132,17 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
128
132
  advance_time(duration) if duration
129
133
  @subscriber.finish('sql.active_record', :id, @params)
130
134
  end
135
+
136
+ def test_active_record_config_for_event
137
+ target_connection = ActiveRecord::Base.connection_handler.connection_pool_list.first.connections.first
138
+ expected_config = target_connection.instance_variable_get(:@config)
139
+
140
+ event = mock('event')
141
+ event.stubs(:payload).returns({ :connection_id => target_connection.object_id })
142
+
143
+ result = @subscriber.active_record_config_for_event(event)
144
+ assert_equal expected_config, result
145
+ end
131
146
  end
132
147
 
133
148
  else
@@ -147,9 +147,9 @@ class NewRelic::Agent::Instrumentation::TaskInstrumentationTest < Test::Unit::Te
147
147
  end
148
148
 
149
149
  def test_error_collector_captures_custom_params
150
- @agent.error_collector.harvest_errors([])
150
+ @agent.error_collector.harvest_errors
151
151
  run_task_exception rescue nil
152
- errors = @agent.error_collector.harvest_errors([])
152
+ errors = @agent.error_collector.harvest_errors
153
153
 
154
154
  assert_equal(1, errors.size)
155
155
  error = errors.first
@@ -5,7 +5,7 @@
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
6
6
  class NewRelic::Agent::MethodTracer::TraceExecutionScopedTest < Test::Unit::TestCase
7
7
  require 'new_relic/agent/method_tracer'
8
- include NewRelic::Agent::MethodTracer::TraceExecutionScoped
8
+ include NewRelic::Agent::MethodTracer
9
9
 
10
10
  def setup
11
11
  NewRelic::Agent.agent.stats_engine.clear_stats
@@ -2,6 +2,7 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
+ require 'cgi'
5
6
  require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
6
7
  require 'new_relic/agent/commands/thread_profiler_session'
7
8
 
@@ -190,11 +191,37 @@ class NewRelicServiceTest < Test::Unit::TestCase
190
191
  dummy_rsp = 'met rick date uhh'
191
192
  @http_handle.respond_to(:metric_data, dummy_rsp)
192
193
  stats_hash = NewRelic::Agent::StatsHash.new
194
+ stats_hash.harvested_at = Time.now
193
195
  @service.expects(:fill_metric_id_cache).with(dummy_rsp)
194
- response = @service.metric_data((Time.now - 60).to_f, Time.now.to_f, stats_hash)
196
+ response = @service.metric_data(stats_hash)
197
+
198
+ assert_equal 4, @http_handle.last_request_payload.size
195
199
  assert_equal dummy_rsp, response
196
200
  end
197
201
 
202
+ def test_metric_data_sends_harvest_timestamps
203
+ @http_handle.respond_to(:metric_data, 'foo')
204
+ @service.stubs(:fill_metric_id_cache)
205
+
206
+ t0 = freeze_time
207
+ stats_hash = NewRelic::Agent::StatsHash.new
208
+ stats_hash.harvested_at = Time.now
209
+
210
+ @service.metric_data(stats_hash)
211
+ payload = @http_handle.last_request_payload
212
+ _, last_harvest_timestamp, harvest_timestamp, _ = payload
213
+ assert_equal(t0.to_f, harvest_timestamp)
214
+
215
+ t1 = advance_time(10)
216
+ stats_hash.harvested_at = t1
217
+
218
+ @service.metric_data(stats_hash)
219
+ payload = @http_handle.last_request_payload
220
+ _, last_harvest_timestamp, harvest_timestamp, _ = payload
221
+ assert_equal(t1.to_f, harvest_timestamp)
222
+ assert_equal(t0.to_f, last_harvest_timestamp)
223
+ end
224
+
198
225
  def test_fill_metric_id_cache_from_collect_response
199
226
  response = [[{"scope"=>"Controller/blogs/index", "name"=>"Database/SQL/other"}, 1328],
200
227
  [{"scope"=>"", "name"=>"WebFrontend/QueueTime"}, 10],
@@ -212,13 +239,11 @@ class NewRelicServiceTest < Test::Unit::TestCase
212
239
  dummy_rsp = [[{ 'name' => 'a', 'scope' => '' }, 42]]
213
240
  @http_handle.respond_to(:metric_data, dummy_rsp)
214
241
 
215
- hash = NewRelic::Agent::StatsHash.new
216
- hash.record(NewRelic::MetricSpec.new('a'), 1)
242
+ hash = build_stats_hash('a' => 1)
217
243
 
218
- @service.metric_data((Time.now - 60).to_f, Time.now.to_f, hash)
244
+ @service.metric_data(hash)
219
245
 
220
- hash = NewRelic::Agent::StatsHash.new
221
- hash.record(NewRelic::MetricSpec.new('a'), 1)
246
+ hash = build_stats_hash('a' => 1)
222
247
  stats = hash[NewRelic::MetricSpec.new('a')]
223
248
 
224
249
  results = @service.build_metric_data_array(hash)
@@ -227,6 +252,22 @@ class NewRelicServiceTest < Test::Unit::TestCase
227
252
  assert_equal(42, results.first.metric_id)
228
253
  end
229
254
 
255
+ def test_metric_data_tracks_last_harvest_time
256
+ t0 = freeze_time
257
+
258
+ @http_handle.respond_to(:metric_data, [])
259
+
260
+ hash = build_stats_hash('a' => 1)
261
+ advance_time(1)
262
+ @service.metric_data(hash)
263
+ assert_equal(t0, @service.last_metric_harvest_time)
264
+
265
+ t1 = advance_time(60)
266
+ hash = build_stats_hash('a' => 1)
267
+ @service.metric_data(hash)
268
+ assert_equal(t1, @service.last_metric_harvest_time)
269
+ end
270
+
230
271
  def test_error_data
231
272
  @http_handle.respond_to(:error_data, 'too human')
232
273
  response = @service.error_data([])
@@ -301,7 +342,8 @@ class NewRelicServiceTest < Test::Unit::TestCase
301
342
  @http_handle.respond_to(:metric_data, 0)
302
343
  @service.stubs(:fill_metric_id_cache)
303
344
  stats_hash = NewRelic::Agent::StatsHash.new
304
- @service.metric_data((Time.now - 60).to_f, Time.now.to_f, stats_hash)
345
+ stats_hash.harvested_at = Time.now
346
+ @service.metric_data(stats_hash)
305
347
 
306
348
  @http_handle.respond_to(:transaction_sample_data, 1)
307
349
  @service.transaction_sample_data([])
@@ -324,7 +366,7 @@ class NewRelicServiceTest < Test::Unit::TestCase
324
366
  @http_handle.respond_to(:metric_data, 'too big', :code => 413)
325
367
  assert_raise NewRelic::Agent::UnrecoverableServerException do
326
368
  stats_hash = NewRelic::Agent::StatsHash.new
327
- @service.metric_data((Time.now - 60).to_f, Time.now.to_f, stats_hash)
369
+ @service.metric_data(stats_hash)
328
370
  end
329
371
  end
330
372
 
@@ -333,7 +375,7 @@ class NewRelicServiceTest < Test::Unit::TestCase
333
375
  @http_handle.respond_to(:metric_data, 'too big', :code => 415)
334
376
  assert_raise NewRelic::Agent::UnrecoverableServerException do
335
377
  stats_hash = NewRelic::Agent::StatsHash.new
336
- @service.metric_data((Time.now - 60).to_f, Time.now.to_f, stats_hash)
378
+ @service.metric_data(stats_hash)
337
379
  end
338
380
  end
339
381
 
@@ -482,6 +524,15 @@ class NewRelicServiceTest < Test::Unit::TestCase
482
524
  assert_equal(spec1, metric_data.metric_spec)
483
525
  end
484
526
 
527
+ def build_stats_hash(items={})
528
+ hash = NewRelic::Agent::StatsHash.new
529
+ items.each do |key, value|
530
+ hash.record(NewRelic::MetricSpec.new(key), value)
531
+ end
532
+ hash.harvested_at = Time.now
533
+ hash
534
+ end
535
+
485
536
  class HTTPHandle
486
537
  attr_accessor :read_timeout, :route_table
487
538
 
@@ -529,6 +580,7 @@ class NewRelicServiceTest < Test::Unit::TestCase
529
580
  end
530
581
 
531
582
  def request(*args)
583
+ @last_request = args.first
532
584
  @route_table.each_pair do |condition, response|
533
585
  if condition.call(args[0])
534
586
  return response
@@ -539,6 +591,23 @@ class NewRelicServiceTest < Test::Unit::TestCase
539
591
 
540
592
  def reset
541
593
  @route_table = {}
594
+ @last_request = nil
595
+ end
596
+
597
+ def last_request
598
+ @last_request
599
+ end
600
+
601
+ def last_request_payload
602
+ return nil unless @last_request && @last_request.body
603
+ uri = URI.parse(@last_request.path)
604
+ params = CGI.parse(uri.query)
605
+ format = params['marshal_format'].first
606
+ if format == 'json'
607
+ JSON.load(@last_request.body)
608
+ else
609
+ Marshal.load(@last_request.body)
610
+ end
542
611
  end
543
612
  end
544
613
 
@@ -11,6 +11,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
11
11
 
12
12
  def setup
13
13
  @test_config = { :developer_mode => true }
14
+ NewRelic::Agent.agent.reset_stats
14
15
  NewRelic::Agent.config.apply_config(@test_config)
15
16
  NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
16
17
  NewRelic::Agent.manual_start
@@ -46,7 +47,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
46
47
  NewRelic::Agent.after_fork
47
48
  new_engine = NewRelic::Agent::StatsEngine.new
48
49
  new_engine.get_stats_no_scope(metric).record_data_point(2.0)
49
- listener.pipes[666].write(:stats => new_engine.harvest_timeslice_data({}))
50
+ listener.pipes[666].write(:stats => new_engine.harvest)
50
51
  end
51
52
  Process.wait(pid)
52
53
  listener.stop
@@ -57,24 +58,21 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
57
58
 
58
59
  def test_listener_merges_transaction_traces
59
60
  sampler = NewRelic::Agent.agent.transaction_sampler
60
- run_sample_trace_on(sampler)
61
- NewRelic::Agent.agent.merge_data_from([nil, [[sampler.last_sample]], nil])
62
-
63
- assert_equal(1, NewRelic::Agent.agent.unsent_traces_size)
61
+ sample = run_sample_trace_on(sampler)
62
+ assert_equal(1, sampler.count)
64
63
 
65
64
  listener = start_listener_with_pipe(667)
66
-
67
65
  pid = Process.fork do
68
66
  NewRelic::Agent.after_fork
69
67
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
70
68
  sample = run_sample_trace_on(sampler)
71
- listener.pipes[667].write(:transaction_traces => sampler.harvest([]))
69
+ listener.pipes[667].write(:transaction_traces => sampler.harvest)
72
70
  end
73
71
  end
74
72
  Process.wait(pid)
75
73
  listener.stop
76
74
 
77
- assert_equal(2, NewRelic::Agent.agent.unsent_traces_size)
75
+ assert_equal(2, sampler.count)
78
76
  end
79
77
 
80
78
  def test_listener_merges_error_traces
@@ -95,7 +93,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
95
93
  new_sampler.notice_error(Exception.new("new message"), :uri => '/myurl/',
96
94
  :metric => 'path', :referer => 'test_referer',
97
95
  :request_params => {:x => 'y'})
98
- listener.pipes[668].write(:error_traces => new_sampler.harvest_errors([]))
96
+ listener.pipes[668].write(:error_traces => new_sampler.harvest_errors)
99
97
  end
100
98
  Process.wait(pid)
101
99
  listener.stop
@@ -34,7 +34,7 @@ class PipeServiceTest < Test::Unit::TestCase
34
34
  .with(regexp_matches(/No communication channel to parent process/)).once
35
35
  service = NewRelic::Agent::PipeService.new(:non_existant)
36
36
  assert_nothing_raised do
37
- service.metric_data(Time.now, Time.now, {})
37
+ service.metric_data({})
38
38
  end
39
39
  end
40
40
 
@@ -44,7 +44,7 @@ class PipeServiceTest < Test::Unit::TestCase
44
44
  def test_metric_data
45
45
  received_data = data_from_forked_process do
46
46
  metric_data0 = generate_metric_data('Custom/something')
47
- @service.metric_data(0.0, 0.1, metric_data0)
47
+ @service.metric_data(metric_data0)
48
48
  end
49
49
 
50
50
  assert_equal 'Custom/something', received_data[:stats].keys.sort[0].name
@@ -75,7 +75,7 @@ class PipeServiceTest < Test::Unit::TestCase
75
75
  def test_multiple_writes_to_pipe
76
76
  pid = Process.fork do
77
77
  metric_data0 = generate_metric_data('Custom/something')
78
- @service.metric_data(0.0, 0.1, metric_data0)
78
+ @service.metric_data(metric_data0)
79
79
  @service.transaction_sample_data(['txn0'])
80
80
  @service.error_data(['err0'])
81
81
  @service.sql_trace_data(['sql0'])
@@ -102,7 +102,7 @@ class PipeServiceTest < Test::Unit::TestCase
102
102
  def generate_metric_data(metric_name, data=1.0)
103
103
  engine = NewRelic::Agent::StatsEngine.new
104
104
  engine.get_stats_no_scope(metric_name).record_data_point(data)
105
- engine.harvest_timeslice_data({})
105
+ engine.harvest
106
106
  end
107
107
 
108
108
  def read_from_pipe
@@ -59,7 +59,7 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
59
59
  old_samples = @sampler.harvest
60
60
  5.times { generate_request }
61
61
 
62
- @sampler.merge(old_samples)
62
+ @sampler.merge!(old_samples)
63
63
  assert_equal(10, @sampler.samples.size)
64
64
  end
65
65
  end
@@ -70,7 +70,7 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
70
70
  old_samples = @sampler.harvest
71
71
  4.times { generate_request }
72
72
 
73
- @sampler.merge(old_samples)
73
+ @sampler.merge!(old_samples)
74
74
  assert_equal(5, @sampler.samples.size)
75
75
  end
76
76
  end
@@ -6,57 +6,39 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_h
6
6
 
7
7
  class NewRelic::Agent::StatsEngine::GCProfilerTest < Test::Unit::TestCase
8
8
  def test_init_profiler_for_rails_bench
9
+ return unless defined?(::GC) && ::GC.respond_to?(:collections)
10
+
9
11
  ::GC.stubs(:time)
10
12
  ::GC.stubs(:collections)
11
13
 
12
- assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::RailsBench,
14
+ assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::RailsBenchProfiler,
13
15
  NewRelic::Agent::StatsEngine::GCProfiler.init.class)
14
16
  end
15
17
 
16
- def test_init_profiler_for_ruby_19
17
- defined = defined?(::GC::Profiler)
18
- if !defined
19
- ::GC.const_set(:Profiler, Module.new)
20
- end
18
+ def test_init_profiler_for_ruby_19_and_greater
19
+ return unless defined?(::GC::Profiler)
20
+ return if NewRelic::LanguageSupport.using_engine?('jruby')
21
+
21
22
  ::GC::Profiler.stubs(:enabled?).returns(true)
22
23
  ::GC::Profiler.stubs(:total_time).returns(0)
23
24
  ::GC.stubs(:count).returns(0)
24
25
 
25
- assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::Ruby19,
26
+ assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::CoreGCProfiler,
26
27
  NewRelic::Agent::StatsEngine::GCProfiler.init.class)
27
- ensure
28
- ::GC.send(:remove_const, :Profiler) unless defined
29
28
  end
30
29
 
31
- def test_init_profiler_for_rbx
32
- defined = defined?(::Rubinius::GC)
33
- if !defined
34
- Object.const_set(:Rubinius, Module.new)
35
- ::Rubinius.const_set(:GC, Module.new)
36
- end
37
- ::Rubinius::GC.stubs(:count).returns(0)
38
- ::Rubinius::GC.stubs(:time).returns(0)
30
+ def test_init_profiler_for_rbx_uses_stdlib
31
+ return unless defined?(::Rubinius::GC)
39
32
 
40
- assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::Rubinius,
33
+ assert_equal(NewRelic::Agent::StatsEngine::GCProfiler::CoreGCProfiler,
41
34
  NewRelic::Agent::StatsEngine::GCProfiler.init.class)
42
- ensure
43
- Object.send(:remove_const, :Rubinius) unless defined
44
35
  end
45
36
 
46
37
  def test_collect_gc_data
47
- GC.disable unless NewRelic::LanguageSupport.using_engine?('jruby')
48
- if NewRelic::LanguageSupport.using_engine?('rbx')
49
- agent = ::Rubinius::Agent.loopback
50
- agent.stubs(:get).with('system.gc.young.total_wallclock') \
51
- .returns([:value, 1000], [:value, 2500])
52
- agent.stubs(:get).with('system.gc.full.total_wallclock') \
53
- .returns([:value, 2000], [:value, 3500])
54
- agent.stubs(:get).with('system.gc.young.count') \
55
- .returns([:value, 1], [:value, 2])
56
- agent.stubs(:get).with('system.gc.full.count') \
57
- .returns([:value, 1], [:value, 2])
58
- ::Rubinius::Agent.stubs(:loopback).returns(agent)
59
- elsif NewRelic::LanguageSupport.using_version?('1.9')
38
+ return if NewRelic::LanguageSupport.using_engine?('jruby')
39
+
40
+ GC.disable
41
+ if NewRelic::LanguageSupport.using_version?('1.9')
60
42
  ::GC::Profiler.stubs(:enabled?).returns(true)
61
43
  ::GC::Profiler.stubs(:total_time).returns(1.0, 4.0)
62
44
  ::GC.stubs(:count).returns(1, 3)
@@ -80,7 +62,5 @@ class NewRelic::Agent::StatsEngine::GCProfilerTest < Test::Unit::TestCase
80
62
  assert_equal 2, gc_stats.call_count
81
63
  assert_equal 3.0, gc_stats.total_call_time
82
64
  assert_equal(3.0, tracer.last_sample.params[:custom_params][:gc_time])
83
- ensure
84
- GC.enable unless NewRelic::LanguageSupport.using_engine?('jruby')
85
65
  end
86
66
  end