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.
Files changed (175) hide show
  1. data/CHANGELOG +120 -35
  2. data/LICENSE +29 -2
  3. data/README.rdoc +2 -2
  4. data/bin/mongrel_rpm +0 -0
  5. data/bin/newrelic +0 -0
  6. data/bin/newrelic_cmd +0 -0
  7. data/lib/new_relic/agent.rb +50 -38
  8. data/lib/new_relic/agent/agent.rb +459 -337
  9. data/lib/new_relic/agent/beacon_configuration.rb +71 -11
  10. data/lib/new_relic/agent/browser_monitoring.rb +73 -14
  11. data/lib/new_relic/agent/busy_calculator.rb +11 -3
  12. data/lib/new_relic/agent/chained_call.rb +2 -2
  13. data/lib/new_relic/agent/database.rb +223 -0
  14. data/lib/new_relic/agent/error_collector.rb +231 -183
  15. data/lib/new_relic/agent/instrumentation.rb +2 -2
  16. data/lib/new_relic/agent/instrumentation/active_merchant.rb +10 -2
  17. data/lib/new_relic/agent/instrumentation/active_record.rb +138 -0
  18. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +7 -1
  19. data/lib/new_relic/agent/instrumentation/authlogic.rb +6 -0
  20. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +46 -14
  21. data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -2
  22. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +11 -3
  23. data/lib/new_relic/agent/instrumentation/memcache.rb +49 -25
  24. data/lib/new_relic/agent/instrumentation/merb/controller.rb +7 -2
  25. data/lib/new_relic/agent/instrumentation/merb/errors.rb +7 -1
  26. data/lib/new_relic/agent/instrumentation/metric_frame.rb +31 -4
  27. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -5
  28. data/lib/new_relic/agent/instrumentation/net.rb +8 -2
  29. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -2
  30. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +66 -35
  32. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +7 -1
  33. data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -1
  34. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +121 -1
  35. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +7 -1
  36. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +21 -0
  37. data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
  38. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -20
  39. data/lib/new_relic/agent/instrumentation/sunspot.rb +6 -0
  40. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +7 -2
  41. data/lib/new_relic/agent/method_tracer.rb +205 -99
  42. data/lib/new_relic/agent/new_relic_service.rb +221 -0
  43. data/lib/new_relic/agent/pipe_channel_manager.rb +161 -0
  44. data/lib/new_relic/agent/pipe_service.rb +54 -0
  45. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +89 -0
  46. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -7
  47. data/lib/new_relic/agent/shim_agent.rb +5 -5
  48. data/lib/new_relic/agent/sql_sampler.rb +282 -0
  49. data/lib/new_relic/agent/stats_engine.rb +2 -0
  50. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  51. data/lib/new_relic/agent/stats_engine/metric_stats.rb +35 -30
  52. data/lib/new_relic/agent/stats_engine/samplers.rb +10 -4
  53. data/lib/new_relic/agent/stats_engine/transactions.rb +28 -87
  54. data/lib/new_relic/agent/transaction_info.rb +74 -0
  55. data/lib/new_relic/agent/transaction_sample_builder.rb +18 -3
  56. data/lib/new_relic/agent/transaction_sampler.rb +108 -20
  57. data/lib/new_relic/agent/worker_loop.rb +14 -6
  58. data/lib/new_relic/collection_helper.rb +19 -11
  59. data/lib/new_relic/command.rb +1 -1
  60. data/lib/new_relic/commands/deployments.rb +2 -2
  61. data/lib/new_relic/commands/install.rb +2 -13
  62. data/lib/new_relic/control.rb +2 -3
  63. data/lib/new_relic/control/class_methods.rb +12 -6
  64. data/lib/new_relic/control/configuration.rb +57 -8
  65. data/lib/new_relic/control/frameworks.rb +10 -0
  66. data/lib/new_relic/control/frameworks/external.rb +4 -4
  67. data/lib/new_relic/control/frameworks/merb.rb +2 -1
  68. data/lib/new_relic/control/frameworks/rails.rb +35 -22
  69. data/lib/new_relic/control/frameworks/rails3.rb +12 -7
  70. data/lib/new_relic/control/frameworks/ruby.rb +5 -5
  71. data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
  72. data/lib/new_relic/control/instance_methods.rb +38 -12
  73. data/lib/new_relic/control/instrumentation.rb +23 -4
  74. data/lib/new_relic/control/logging_methods.rb +70 -15
  75. data/lib/new_relic/control/server_methods.rb +22 -9
  76. data/lib/new_relic/delayed_job_injection.rb +16 -3
  77. data/lib/new_relic/helper.rb +21 -0
  78. data/lib/new_relic/language_support.rb +95 -0
  79. data/lib/new_relic/local_environment.rb +92 -48
  80. data/lib/new_relic/metric_data.rb +7 -2
  81. data/lib/new_relic/metric_spec.rb +12 -9
  82. data/lib/new_relic/noticed_error.rb +6 -1
  83. data/lib/new_relic/rack/browser_monitoring.rb +18 -19
  84. data/lib/new_relic/rack/developer_mode.rb +3 -2
  85. data/lib/new_relic/recipes.rb +8 -4
  86. data/lib/new_relic/stats.rb +17 -60
  87. data/lib/new_relic/transaction_analysis.rb +2 -1
  88. data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
  89. data/lib/new_relic/transaction_sample.rb +60 -75
  90. data/lib/new_relic/transaction_sample/segment.rb +31 -79
  91. data/lib/new_relic/version.rb +2 -2
  92. data/lib/newrelic_rpm.rb +1 -1
  93. data/newrelic.yml +2 -2
  94. data/newrelic_rpm.gemspec +46 -54
  95. data/test/active_record_fixtures.rb +3 -3
  96. data/test/config/newrelic.yml +1 -1
  97. data/test/fixtures/proc_cpuinfo.txt +575 -0
  98. data/test/new_relic/agent/agent/connect_test.rb +128 -25
  99. data/test/new_relic/agent/agent/start_test.rb +9 -94
  100. data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -4
  101. data/test/new_relic/agent/agent_test.rb +51 -78
  102. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  103. data/test/new_relic/agent/agent_test_controller_test.rb +49 -33
  104. data/test/new_relic/agent/beacon_configuration_test.rb +12 -5
  105. data/test/new_relic/agent/browser_monitoring_test.rb +99 -50
  106. data/test/new_relic/agent/database_test.rb +161 -0
  107. data/test/new_relic/agent/error_collector_test.rb +47 -23
  108. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +96 -42
  109. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
  110. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
  111. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -11
  112. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +9 -9
  113. data/test/new_relic/agent/instrumentation/queue_time_test.rb +6 -11
  114. data/test/new_relic/agent/memcache_instrumentation_test.rb +54 -18
  115. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
  116. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  117. data/test/new_relic/agent/method_tracer_test.rb +3 -2
  118. data/test/new_relic/agent/new_relic_service_test.rb +151 -0
  119. data/test/new_relic/agent/pipe_channel_manager_test.rb +114 -0
  120. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  121. data/test/new_relic/agent/rpm_agent_test.rb +4 -31
  122. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  123. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +19 -18
  124. data/test/new_relic/agent/stats_engine_test.rb +41 -6
  125. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  126. data/test/new_relic/agent/transaction_sample_builder_test.rb +27 -4
  127. data/test/new_relic/agent/transaction_sampler_test.rb +68 -46
  128. data/test/new_relic/agent/worker_loop_test.rb +3 -3
  129. data/test/new_relic/agent_test.rb +242 -0
  130. data/test/new_relic/collection_helper_test.rb +50 -28
  131. data/test/new_relic/control/configuration_test.rb +77 -0
  132. data/test/new_relic/control/logging_methods_test.rb +49 -21
  133. data/test/new_relic/control_test.rb +115 -54
  134. data/test/new_relic/delayed_job_injection_test.rb +21 -0
  135. data/test/new_relic/fake_collector.rb +210 -0
  136. data/test/new_relic/fake_service.rb +44 -0
  137. data/test/new_relic/local_environment_test.rb +14 -1
  138. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  139. data/test/new_relic/rack/browser_monitoring_test.rb +84 -23
  140. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  141. data/test/new_relic/rack/developer_mode_test.rb +31 -0
  142. data/test/new_relic/stats_test.rb +3 -18
  143. data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
  144. data/test/new_relic/transaction_analysis_test.rb +3 -3
  145. data/test/new_relic/transaction_sample/segment_test.rb +15 -80
  146. data/test/new_relic/transaction_sample_test.rb +25 -18
  147. data/test/script/build_test_gem.sh +51 -0
  148. data/test/script/ci.sh +140 -0
  149. data/test/script/ci_agent-tests_runner.sh +82 -0
  150. data/test/script/ci_bench.sh +52 -0
  151. data/test/script/ci_multiverse_runner.sh +63 -0
  152. data/test/test_contexts.rb +1 -0
  153. data/test/test_helper.rb +18 -5
  154. data/ui/helpers/developer_mode_helper.rb +14 -8
  155. data/ui/helpers/google_pie_chart.rb +0 -1
  156. data/ui/views/newrelic/index.rhtml +2 -2
  157. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
  158. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +10 -0
  159. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
  160. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +17 -4
  161. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
  162. metadata +50 -36
  163. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +0 -108
  164. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +0 -112
  165. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  166. data/lib/new_relic/data_serialization.rb +0 -84
  167. data/lib/new_relic/histogram.rb +0 -91
  168. data/lib/new_relic/rack/metric_app.rb +0 -65
  169. data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
  170. data/lib/new_relic/rack/newrelic.yml +0 -27
  171. data/lib/new_relic/rack_app.rb +0 -6
  172. data/test/new_relic/data_serialization_test.rb +0 -70
  173. data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
  174. data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
  175. data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
@@ -63,6 +63,20 @@ class NewRelic::TransactionAnalysis::SegmentSummaryTest < Test::Unit::TestCase
63
63
  assert_equal 0.5, @ss.total_time_percentage
64
64
  end
65
65
 
66
+ def test_nesting_total_time
67
+ segment = mock('segment')
68
+ segment.expects(:metric_name).twice.returns('Controller/foo')
69
+ segment.expects(:duration).returns(0.1)
70
+ segment.expects(:exclusive_duration).returns(0)
71
+ @ss << segment
72
+ segment.expects(:exclusive_duration).returns(0.1)
73
+ @ss.current_nest_count += 1
74
+ @ss << segment
75
+ assert_equal 0.1, @ss.total_time
76
+ assert_equal 0.1, @ss.exclusive_time
77
+ assert_equal 2, @ss.call_count
78
+ end
79
+
66
80
  def test_ui_name_default
67
81
  @ss.metric_name = 'Remainder'
68
82
  assert_equal 'Remainder', @ss.ui_name
@@ -28,7 +28,7 @@ class NewRelic::TransactionAnalysisTest < Test::Unit::TestCase
28
28
  other_segment.expects(:metric_name).twice.returns('Controller/foo')
29
29
  other_segment.expects(:duration).returns(0.1)
30
30
  other_segment.expects(:exclusive_duration).returns(0.1)
31
- self.expects(:each_segment).multiple_yields(root_segment, other_segment)
31
+ self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment)
32
32
  self.expects(:root_segment).twice.returns(root_segment)
33
33
  self.expects(:duration).returns(0.1)
34
34
  data = breakdown_data
@@ -56,7 +56,7 @@ class NewRelic::TransactionAnalysisTest < Test::Unit::TestCase
56
56
  yet_another.expects(:metric_name).twice.returns('Controller/bar')
57
57
  yet_another.expects(:duration).returns(0.2)
58
58
  yet_another.expects(:exclusive_duration).returns(0.2)
59
- self.expects(:each_segment).multiple_yields(root_segment, other_segment, yet_another)
59
+ self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment, yet_another)
60
60
  self.expects(:root_segment).times(3).returns(root_segment)
61
61
  self.expects(:duration).returns(0.1)
62
62
  data = breakdown_data(1)
@@ -76,7 +76,7 @@ class NewRelic::TransactionAnalysisTest < Test::Unit::TestCase
76
76
  other_segment.expects(:metric_name).twice.returns('Controller/foo')
77
77
  other_segment.expects(:duration).returns(0.1)
78
78
  other_segment.expects(:exclusive_duration).returns(0.1)
79
- self.expects(:each_segment).multiple_yields(root_segment, other_segment)
79
+ self.expects(:each_segment_with_nest_tracking).multiple_yields(root_segment, other_segment)
80
80
  self.expects(:root_segment).twice.returns(root_segment)
81
81
  self.expects(:duration).returns(0.2)
82
82
  data = breakdown_data
@@ -313,6 +313,17 @@ class NewRelic::TransactionSample::SegmentTest < Test::Unit::TestCase
313
313
  assert_equal(2, count)
314
314
  end
315
315
 
316
+ def test_each_segment_with_nest_tracking
317
+ s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
318
+
319
+ summary = mock('summary')
320
+ summary.expects(:current_nest_count).twice.returns(0).then.returns(1)
321
+ summary.expects(:current_nest_count=).twice
322
+ s.each_segment_with_nest_tracking do |x|
323
+ summary
324
+ end
325
+ end
326
+
316
327
  def test_find_segment_default
317
328
  s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
318
329
  id_to_find = s.segment_id
@@ -332,75 +343,12 @@ class NewRelic::TransactionSample::SegmentTest < Test::Unit::TestCase
332
343
  assert_equal(s, s.find_segment(id_to_find))
333
344
  end
334
345
 
335
- def test_explain_sql_no_sql
336
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
337
- s.params = {:sql => nil}
338
- assert_equal(nil, s.explain_sql)
339
- end
340
-
341
- def test_explain_sql_no_connection_config
342
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
343
- s.params = {:sql => 'foo', :connection_config => nil}
344
- assert_equal(nil, s.explain_sql)
345
- end
346
-
347
- def test_explain_sql_non_select
348
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
349
- s.params = {:sql => 'foo', :connection_config => mock('config')}
350
- assert_equal([], s.explain_sql)
351
- end
352
-
353
- def test_explain_sql_one_select_no_connection
354
- # NB this test raises an error in the log, much as it might if a
355
- # user supplied a config that was not valid. This is generally
356
- # expected behavior - the get_connection method shouldn't allow
357
- # errors to percolate up.
358
- config = mock('config')
359
- config.stubs(:[]).returns(nil)
360
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
361
- s.params = {:sql => 'SELECT', :connection_config => config}
362
- assert_equal([], s.explain_sql)
363
- end
364
-
365
- def test_explain_sql_one_select_with_connection
366
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
367
- config = mock('config')
368
- s.params = {:sql => 'SELECT', :connection_config => config}
369
- connection = mock('connection')
370
- # two rows, two columns
371
- connection.expects(:execute).with('EXPLAIN SELECT').returns([["string", "string"], ["string", "string"]])
372
- NewRelic::TransactionSample.expects(:get_connection).with(config).returns(connection)
373
- assert_equal([[['string', 'string'], ['string', 'string']]], s.explain_sql)
374
- end
375
-
376
- # this basically casts the resultset to an array of rows, which are
377
- # arrays of columns
378
- def test_process_resultset
379
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
380
- items = mock('bar')
381
- row = ["column"]
382
- items.expects(:respond_to?).with(:each).returns(true)
383
- items.expects(:each).yields(row)
384
- assert_equal([["column"]], s.process_resultset(items))
385
- end
386
-
387
- def test_explain_sql_two_selects_with_connection
388
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
389
- config = mock('config')
390
- s.params = {:sql => "SELECT true();\nSELECT false()", :connection_config => config}
391
- connection = mock('connection')
392
- # two rows, two columns
393
- connection.expects(:execute).returns([["string", "string"], ["string", "string"]]).twice
394
- NewRelic::TransactionSample.expects(:get_connection).with(config).returns(connection).twice
395
- assert_equal([[['string', 'string'], ['string', 'string']], [['string', 'string'], ['string', 'string']]], s.explain_sql)
396
- end
397
-
398
346
  def test_explain_sql_raising_an_error
399
347
  s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
400
348
  config = mock('config')
401
349
  s.params = {:sql => 'SELECT', :connection_config => config}
402
350
  connection = mock('connection')
403
- NewRelic::TransactionSample.expects(:get_connection).with(config).raises(RuntimeError.new("whee"))
351
+ NewRelic::Agent::Database.expects(:get_connection).with(config).raises(RuntimeError.new("whee"))
404
352
  assert_nothing_raised do
405
353
  s.explain_sql
406
354
  end
@@ -415,25 +363,12 @@ class NewRelic::TransactionSample::SegmentTest < Test::Unit::TestCase
415
363
  s.params = params
416
364
  assert_equal(params, s.instance_eval { @params })
417
365
  end
418
-
419
- def test_handle_exception_in_explain
420
- s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
421
- fake_error = Exception.new
422
- fake_error.expects(:message).returns('a message')
423
- NewRelic::Control.instance.log.expects(:error).with('Error getting explain plan: a message')
424
- # backtrace can be basically any string, just should get logged
425
- NewRelic::Control.instance.log.expects(:debug).with(instance_of(String))
426
- s.handle_exception_in_explain do
427
- raise(fake_error)
428
- end
429
- end
430
-
366
+
431
367
  def test_obfuscated_sql
432
- sql = 'some sql'
368
+ sql = 'select * from table where id = 1'
433
369
  s = NewRelic::TransactionSample::Segment.new(Time.now, 'Custom/test/metric', nil)
434
370
  s[:sql] = sql
435
- NewRelic::TransactionSample.expects(:obfuscate_sql).with(sql)
436
- s.obfuscated_sql
371
+ assert_equal('select * from table where id = ?', s.obfuscated_sql)
437
372
  end
438
373
 
439
374
  def test_called_segments_equals
@@ -6,9 +6,9 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
6
6
 
7
7
  def setup
8
8
  @connection_stub = Mocha::Mockery.instance.named_mock('connection')
9
- @connection_stub.stubs(:execute).returns('QUERY RESULT')
9
+ @connection_stub.stubs(:execute).returns([['QUERY RESULT']])
10
10
 
11
- NewRelic::TransactionSample.stubs(:get_connection).returns @connection_stub
11
+ NewRelic::Agent::Database.stubs(:get_connection).returns @connection_stub
12
12
  @t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
13
13
  end
14
14
 
@@ -19,7 +19,7 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
19
19
  def test_not_record_sql_when_record_sql_off
20
20
  s = @t.prepare_to_send(:explain_sql => 0.00000001)
21
21
  s.each_segment do |segment|
22
- assert_nil segment.params[:explanation]
22
+ assert_nil segment.params[:explain_plan]
23
23
  assert_nil segment.params[:sql]
24
24
  end
25
25
  end
@@ -29,7 +29,7 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
29
29
  got_one = false
30
30
  s.each_segment do |segment|
31
31
  fail if segment.params[:obfuscated_sql]
32
- got_one = got_one || segment.params[:explanation] || segment.params[:sql]
32
+ got_one = got_one || segment.params[:explain_plan] || segment.params[:sql]
33
33
  end
34
34
  assert got_one
35
35
  end
@@ -40,7 +40,7 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
40
40
 
41
41
  got_one = false
42
42
  s.each_segment do |segment|
43
- got_one = got_one || segment.params[:explanation] || segment.params[:sql]
43
+ got_one = got_one || segment.params[:explain_plan] || segment.params[:sql]
44
44
  end
45
45
 
46
46
  assert got_one
@@ -77,22 +77,16 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
77
77
  end
78
78
 
79
79
  def test_have_explains
80
-
81
80
  s = @t.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.00000001)
82
-
83
- explain_count = 0
81
+
84
82
  s.each_segment do |segment|
85
- if segment.params[:explanation]
86
- explanations = segment.params[:explanation]
87
-
88
- explanations.each do |explanation|
89
- assert_kind_of Array, explanation
90
- assert_equal "QUERY RESULT", explanation.join('')
91
- explain_count += 1
92
- end
83
+ if segment.params[:explain_plan]
84
+ explanation = segment.params[:explain_plan]
85
+
86
+ assert_kind_of Array, explanation
87
+ assert_equal([nil, [["QUERY RESULT"]]], explanation)
93
88
  end
94
89
  end
95
- assert_equal 2, explain_count
96
90
  end
97
91
 
98
92
  def test_not_record_sql_without_record_sql_option
@@ -104,7 +98,7 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
104
98
  s = t.prepare_to_send(:explain_sql => 0.00000001)
105
99
 
106
100
  s.each_segment do |segment|
107
- assert_nil segment.params[:explanation]
101
+ assert_nil segment.params[:explain_plan]
108
102
  assert_nil segment.params[:sql]
109
103
  end
110
104
  end
@@ -167,4 +161,17 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
167
161
  s = @t.prepare_to_send(:explain_sql => 0.1)
168
162
  assert(s.timestamp.instance_of?(Float), "s.timestamp should be a Float, but is #{s.timestamp.class.inspect}")
169
163
  end
164
+
165
+ def test_count_segments
166
+ transaction = run_sample_trace_on(NewRelic::Agent::TransactionSampler.new) do |sampler|
167
+ sampler.notice_push_scope "level0"
168
+ sampler.notice_push_scope "level-1"
169
+ sampler.notice_push_scope "level-2"
170
+ sampler.notice_sql(::SQL_STATEMENT, nil, 0)
171
+ sampler.notice_pop_scope "level-2"
172
+ sampler.notice_pop_scope "level-1"
173
+ sampler.notice_pop_scope "level0"
174
+ end
175
+ assert_equal 6, transaction.count_segments
176
+ end
170
177
  end
@@ -0,0 +1,51 @@
1
+ #!/bin/bash
2
+
3
+ # print commands in this script as they're invoked
4
+ set -x
5
+ # fail if any command fails
6
+ set -e
7
+
8
+ if [ "x$BUILD_NUMBER" == "x" ]; then
9
+ echo '$BUILD_NUMBER is undefined'
10
+ echo 'setting $BUILD_NUMBER to alpha'
11
+ BUILD_NUMBER=alpha
12
+ fi
13
+
14
+ SHA1=`git log --pretty=format:'%h' -n 1`
15
+ echo "building gem for commit $SHA"
16
+
17
+ if [[ `gem list jeweler | grep [j]eweler | wc -l` -eq 1 ]]; then
18
+ echo "detected jeweler. skipping install"
19
+ else
20
+ gem install jeweler --no-ri --no-rdoc
21
+ fi
22
+
23
+ # setup a gems directory as a work area for artifacts
24
+ rm -rf gems/
25
+ mkdir gems
26
+
27
+ # an identifier including the hudson build number and the git sha1
28
+
29
+ # FIXME: don't include the $SHA1 since some of our builds systems are confused
30
+ # by this.
31
+ BUILD_ID=$BUILD_NUMBER #.$SHA1
32
+
33
+ # rewrite the version file, setting the patch identifier to include the
34
+ # BUILD_ID
35
+ perl -p -i -e "s#BUILD *= *.*\$#BUILD = '$BUILD_ID'#" lib/new_relic/version.rb
36
+
37
+ # generate the gemspec
38
+ rake gemspec
39
+
40
+ # build the gem
41
+ gem build *.gemspec
42
+
43
+ # move artifacts to the gems directory
44
+ cp *.gemspec gems/
45
+ mv *.gem gems/
46
+
47
+ cd gems
48
+
49
+ # create a tarfile including the gem and the gemspec
50
+ gem_version=`ls *.gem | sed 's/\.gem$//' | sed 's/newrelic_rpm-//'`
51
+ tar czvf newrelic_rpm_agent-${gem_version}.tar.gz *
data/test/script/ci.sh ADDED
@@ -0,0 +1,140 @@
1
+ #!/bin/bash
2
+
3
+ # Script to run test suites in CI or in development mode. This script handles
4
+ # checking out test dependencies (currently rpm_test_app and it's dependencies)
5
+ # and executing them.
6
+ #
7
+ # It relies on 2 environment variables:
8
+ #
9
+ # RUBY - The rvm ruby you want to use (e.g. 1.8.7, ree, jruby)
10
+ #
11
+ # BRANCH - The rpm_test_app branch you want to use (e.g. rails20, rails31)
12
+ #
13
+ # Example usage:
14
+ # RUBY=ree BRANCH=rails20 test/script/ci.sh
15
+ #
16
+ # RUBY=ree BRANCH=rails20 test/script/ci.sh
17
+ #
18
+ # RUBY=jruby BRANCH=rails22 test/script/ci.sh
19
+
20
+ echo "Executing $0"
21
+ echo "Running in $(pwd)"
22
+
23
+ # print commands in this script as they're invoked
24
+ #set -x
25
+ # fail if any command fails
26
+ set -e
27
+
28
+ # check for require environment variables
29
+ if [ "x$RUBY" == "x" ]; then
30
+ echo '$RUBY is undefined'
31
+ echo 'defaulting to 1.9.3'
32
+ RUBY=1.9.3
33
+ fi
34
+ if [ "x$BRANCH" == "x" ]; then
35
+ echo '$BRANCH is undefined'
36
+ echo 'defaulting to rails31'
37
+ BRANCH=rails31
38
+ fi
39
+
40
+ . "$HOME/.rvm/scripts/rvm"
41
+ rvm use $RUBY || rvm install $RUBY
42
+ echo `which ruby`
43
+
44
+ # make sure that we're in the project root
45
+ script_dirname=`dirname $0`
46
+ cd "$script_dirname/../../"
47
+ pwd
48
+
49
+ rm -rf tmp
50
+ mkdir -p tmp
51
+ cd tmp
52
+
53
+
54
+ #rpm_test_app_cache=~/.rpm_test_app_cache
55
+ rpm_test_app_cache=~/workspace/.rpm_test_app_cache
56
+ (
57
+ echo "updating local cache of rpm_test_app in $rpm_test_app_cache"
58
+ git clone --mirror git://github.com/newrelic/rpm_test_app.git $rpm_test_app_cache || true
59
+ cd $rpm_test_app_cache
60
+ )
61
+
62
+ git clone $rpm_test_app_cache rpm_test_app
63
+ cd rpm_test_app || true # rvm overrides cd and it's f-ing up the build by exiting 2
64
+
65
+ git checkout -t origin/$BRANCH || git checkout $BRANCH
66
+
67
+
68
+ # Re-write database.yml to this here doc
69
+ ( cat << "YAML" ) > config/database.yml
70
+ # Shared properties for mysql db
71
+ mysql: &mysql
72
+ adapter: mysql
73
+ socket: <%= (`uname -s` =~ /Linux/ ) ? "" :"/tmp/mysql.sock" %>
74
+ username: root
75
+ host: localhost
76
+ database: <%= [ 'rails_blog', ENV['BRANCH'], ENV['RUBY'] ].compact.join('_') %>
77
+
78
+ # Shared properties for postgres. This won't work with our schema but
79
+ # Does work with agent tests
80
+ sqlite3: &sqlite3
81
+ <% if defined?(JRuby) %>
82
+ adapter: jdbcsqlite3
83
+ <% else %>
84
+ adapter: sqlite3
85
+ <% end %>
86
+ database: db/all.sqlite3
87
+ pool: 5
88
+ timeout: 5000
89
+ host: localhost
90
+
91
+ # SQLite version 3.x
92
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
93
+ development:
94
+ <<: *sqlite3
95
+
96
+ test:
97
+ <<: *mysql
98
+
99
+ production:
100
+ <<: *mysql
101
+ YAML
102
+
103
+
104
+ mkdir -p log
105
+ mkdir -p tmp
106
+ if [ "x$BRANCH" == "xrails20" ]; then
107
+ printf "\e[0;31;49mWarning:\e[0m "
108
+ echo "Testing against the rails20 branch requires your changes to be committed. Uncommitted changes will not be used."
109
+ mkdir -p vendor/plugins
110
+ git clone ../.. vendor/plugins/newrelic_rpm
111
+ else
112
+ perl -p -i'.bak' -e 's#gem .newrelic_rpm.*$#gem "newrelic_rpm", :path => "\.\.\/\.\.\/"#' Gemfile
113
+ fi
114
+
115
+ # save time by reusing the gemset if it exists
116
+
117
+ gemset=ruby_agent_tests_$BRANCH
118
+ rvm gemset use $gemset || ( rvm gemset create $gemset && rvm gemset use $gemset )
119
+
120
+ if [ "x$RUBY" == "x1.8.6" ]; then
121
+ # Bundler 0.1 dropped support for ruby 1.8.6
122
+ gem install bundler -v'~>1.0.0' --no-rdoc --no-ri
123
+ else
124
+ gem install bundler --no-rdoc --no-ri
125
+ fi
126
+
127
+
128
+ export RAILS_ENV=test
129
+ bundle
130
+
131
+ # FIXME: Here we actually trigger the tests. Since the agent deals so heavily
132
+ # in units of time we have many tests that assert that durations are measured
133
+ # correctly. These almost always pass, but as the CI machine has come under
134
+ # heavier load there tend to be discrepencies between the duration measured in
135
+ # the test and the duration the agent measures. This is due to lags in CPU
136
+ # scheduling since many processes are running on the box simultaneously.
137
+ # To reduce the noise from these sporardic failures we rerun the test suite if
138
+ # there are failures to see if they are transient (instead of re-running it by
139
+ # hand). Ultimately we'll move towards a more elegant solution.
140
+ bundle exec rake --trace db:create:all test:newrelic || bundle exec rake --trace test:newrelic || bundle exec rake --trace test:newrelic