newrelic_rpm 3.5.7.59 → 3.5.8.64.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data.tar.gz.sig +3 -2
  2. data/CHANGELOG +34 -3
  3. data/LICENSE +23 -0
  4. data/lib/new_relic/agent.rb +50 -3
  5. data/lib/new_relic/agent/agent.rb +40 -60
  6. data/lib/new_relic/agent/configuration/defaults.rb +9 -3
  7. data/lib/new_relic/agent/configuration/server_source.rb +4 -0
  8. data/lib/new_relic/agent/cross_app_monitor.rb +230 -0
  9. data/lib/new_relic/agent/cross_app_tracing.rb +274 -0
  10. data/lib/new_relic/agent/database.rb +28 -10
  11. data/lib/new_relic/agent/error_collector.rb +5 -0
  12. data/lib/new_relic/agent/event_listener.rb +4 -0
  13. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +53 -34
  14. data/lib/new_relic/agent/instrumentation/metric_frame.rb +16 -3
  15. data/lib/new_relic/agent/instrumentation/net.rb +13 -11
  16. data/lib/new_relic/agent/instrumentation/resque.rb +10 -10
  17. data/lib/new_relic/agent/instrumentation/sinatra.rb +19 -9
  18. data/lib/new_relic/agent/new_relic_service.rb +63 -9
  19. data/lib/new_relic/agent/pipe_service.rb +8 -12
  20. data/lib/new_relic/agent/rules_engine.rb +72 -0
  21. data/lib/new_relic/agent/shim_agent.rb +0 -1
  22. data/lib/new_relic/agent/sql_sampler.rb +3 -2
  23. data/lib/new_relic/agent/stats.rb +149 -0
  24. data/lib/new_relic/agent/stats_engine.rb +9 -0
  25. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -24
  26. data/lib/new_relic/agent/stats_engine/metric_stats.rb +84 -185
  27. data/lib/new_relic/agent/stats_engine/stats_hash.rb +58 -0
  28. data/lib/new_relic/agent/stats_engine/transactions.rb +10 -2
  29. data/lib/new_relic/agent/transaction_info.rb +31 -6
  30. data/lib/new_relic/agent/transaction_sample_builder.rb +19 -8
  31. data/lib/new_relic/agent/transaction_sampler.rb +17 -10
  32. data/lib/new_relic/helper.rb +32 -0
  33. data/lib/new_relic/local_environment.rb +24 -32
  34. data/lib/new_relic/okjson.rb +599 -0
  35. data/lib/new_relic/transaction_sample.rb +2 -1
  36. data/lib/new_relic/transaction_sample/segment.rb +2 -1
  37. data/lib/new_relic/version.rb +1 -1
  38. data/newrelic.yml +27 -41
  39. data/test/multiverse/suites/agent_only/audit_log_test.rb +2 -4
  40. data/test/multiverse/suites/agent_only/config/newrelic.yml +1 -2
  41. data/test/multiverse/suites/agent_only/{cross_process_test.rb → cross_application_tracing_test.rb} +3 -3
  42. data/test/multiverse/suites/agent_only/key_transactions_test.rb +66 -0
  43. data/test/multiverse/suites/agent_only/marshaling_test.rb +9 -22
  44. data/test/multiverse/suites/agent_only/rename_rule_test.rb +57 -0
  45. data/test/multiverse/suites/agent_only/start_up_test.rb +1 -1
  46. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +17 -6
  47. data/test/multiverse/suites/rails/error_tracing_test.rb +20 -8
  48. data/test/multiverse/suites/resque/instrumentation_test.rb +2 -2
  49. data/test/multiverse/suites/sinatra/Envfile +2 -0
  50. data/test/multiverse/suites/sinatra/config/newrelic.yml +1 -0
  51. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +5 -5
  52. data/test/multiverse/suites/sinatra/sinatra_test.rb +75 -4
  53. data/test/new_relic/agent/agent/connect_test.rb +45 -1
  54. data/test/new_relic/agent/agent/start_worker_thread_test.rb +0 -3
  55. data/test/new_relic/agent/agent_test.rb +20 -40
  56. data/test/new_relic/agent/agent_test_controller_test.rb +24 -19
  57. data/test/new_relic/agent/busy_calculator_test.rb +1 -1
  58. data/test/new_relic/agent/configuration/server_source_test.rb +8 -3
  59. data/test/new_relic/agent/cross_app_monitor_test.rb +237 -0
  60. data/test/new_relic/agent/database_test.rb +60 -16
  61. data/test/new_relic/agent/error_collector_test.rb +28 -4
  62. data/test/new_relic/agent/event_listener_test.rb +23 -2
  63. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +53 -0
  64. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +95 -0
  65. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +414 -59
  66. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -5
  67. data/test/new_relic/agent/method_tracer_test.rb +4 -2
  68. data/test/new_relic/agent/new_relic_service_test.rb +108 -6
  69. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
  70. data/test/new_relic/agent/pipe_service_test.rb +9 -9
  71. data/test/new_relic/agent/rpm_agent_test.rb +0 -11
  72. data/test/new_relic/agent/rules_engine_test.rb +82 -0
  73. data/test/new_relic/agent/shim_agent_test.rb +0 -4
  74. data/test/new_relic/agent/sql_sampler_test.rb +7 -0
  75. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +85 -0
  76. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +110 -23
  77. data/test/new_relic/agent/stats_engine_test.rb +1 -46
  78. data/test/new_relic/agent/stats_hash_test.rb +93 -0
  79. data/test/new_relic/agent/stats_test.rb +197 -0
  80. data/test/new_relic/agent/transaction_info_test.rb +63 -11
  81. data/test/new_relic/agent/transaction_sample_builder_test.rb +10 -3
  82. data/test/new_relic/agent/transaction_sampler_test.rb +92 -80
  83. data/test/new_relic/agent_test.rb +35 -5
  84. data/test/new_relic/control_test.rb +1 -1
  85. data/test/new_relic/fake_collector.rb +87 -9
  86. data/test/new_relic/helper_test.rb +24 -0
  87. data/test/new_relic/metric_data_test.rb +11 -11
  88. data/test/new_relic/metric_spec_test.rb +1 -1
  89. data/test/script/ci.sh +1 -1
  90. data/test/test_contexts.rb +0 -1
  91. data/test/test_helper.rb +21 -3
  92. metadata +32 -16
  93. metadata.gz.sig +0 -0
  94. data/lib/new_relic/agent/cross_process_monitoring.rb +0 -187
  95. data/lib/new_relic/stats.rb +0 -337
  96. data/test/new_relic/agent/cross_process_monitoring_test.rb +0 -190
  97. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +0 -133
  98. data/test/new_relic/fakes_sending_data.rb +0 -30
  99. data/test/new_relic/stats_test.rb +0 -421
@@ -9,46 +9,98 @@ class NewRelic::Agent::TransactionInfoTest < Test::Unit::TestCase
9
9
  @request_with_double_quotes = OpenStruct.new(:cookies => {'NRAGENT' => 'tk="""deadbeef"""'})
10
10
  @request_with_single_quotes = OpenStruct.new(:cookies => {'NRAGENT' => "tk='''deadbeef'''"})
11
11
  @request_with_multi_lt = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=<<<deadbeef'})
12
- @request_with_multi_gt = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=>>>deadbeef'})
12
+ @request_with_multi_gt = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=>>>deadbeef'})
13
13
  @request_with_bare_token = OpenStruct.new(:cookies => {'NRAGENT' => 0xdeadbeef})
14
14
  @request_with_nil_token = OpenStruct.new(:cookies => {'NRAGENT' => nil})
15
15
  end
16
-
16
+
17
17
  def test_get_token_safe_token_returned_untouched
18
18
  assert_equal("12345678", NewRelic::Agent::TransactionInfo.get_token(@request))
19
19
  end
20
20
 
21
21
  def test_get_token_with_embedded_tags_sanitized
22
- assert_equal("",NewRelic::Agent::TransactionInfo.get_token(@request_with_embedded_tag))
22
+ assert_equal("",NewRelic::Agent::TransactionInfo.get_token(@request_with_embedded_tag))
23
23
  end
24
24
 
25
25
  def test_get_token_with_embedded_utf8_js_sanitized
26
- assert_equal("1234&amp;#34&amp;#93&amp;#41&amp;#595678",
27
- NewRelic::Agent::TransactionInfo.get_token(@request_with_embedded_utf8_encoded_js))
26
+ assert_equal("1234&amp;#34&amp;#93&amp;#41&amp;#595678",
27
+ NewRelic::Agent::TransactionInfo.get_token(@request_with_embedded_utf8_encoded_js))
28
28
  end
29
29
 
30
30
  def test_get_token_replaces_double_quoted_token_with_empty_string
31
- assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_double_quotes))
31
+ assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_double_quotes))
32
32
  end
33
33
 
34
34
  def test_get_token_replaces_single_quoted_toket_with_empty_string
35
- assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_single_quotes))
35
+ assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_single_quotes))
36
36
  end
37
37
 
38
38
  def test_get_token_replaces_token_started_with_multiple_Lt_with_empty_string
39
- assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_multi_lt))
39
+ assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_multi_lt))
40
40
  end
41
41
 
42
42
  def test_get_token_replaces_token_started_with_multiple_gt_with_empty_string
43
- assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_multi_gt))
43
+ assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_multi_gt))
44
44
  end
45
45
 
46
46
  def test_get_token_bare_value_replaced_with_nil
47
- assert_equal(nil,NewRelic::Agent::TransactionInfo.get_token(@request_with_bare_token))
47
+ assert_equal(nil,NewRelic::Agent::TransactionInfo.get_token(@request_with_bare_token))
48
48
  end
49
49
 
50
50
  def test_get_token_nil_token_returns_nil_token
51
- assert_equal(nil,NewRelic::Agent::TransactionInfo.get_token(@request_with_ni_token))
51
+ assert_equal(nil,NewRelic::Agent::TransactionInfo.get_token(@request_with_ni_token))
52
+ end
53
+
54
+ def test_has_correct_apdex_t_for_tansaction
55
+ txn_info = NewRelic::Agent::TransactionInfo.get
56
+ config = { :web_transactions_apdex => {'Controller/foo/bar' => 1.5},
57
+ :apdex_t => 2.0 }
58
+
59
+ with_config(config, :do_not_cast => true) do
60
+ txn_info.transaction_name = 'Controller/foo/bar'
61
+ assert_equal 1.5, txn_info.apdex_t
62
+ txn_info.transaction_name = 'Controller/some/other/txn'
63
+ assert_equal 2.0, txn_info.apdex_t
64
+ end
52
65
  end
53
66
 
67
+ def test_has_correct_transaction_trace_threshold_when_default
68
+ txn_info = NewRelic::Agent::TransactionInfo.get
69
+ config = { :web_transactions_apdex => {'Controller/foo/bar' => 1.5},
70
+ :apdex_t => 2.0 }
71
+
72
+ with_config(config, :do_not_cast => true) do
73
+ txn_info.transaction_name = 'Controller/foo/bar'
74
+ assert_equal 6.0, txn_info.transaction_trace_threshold
75
+ txn_info.transaction_name = 'Controller/some/other/txn'
76
+ assert_equal 8.0, txn_info.transaction_trace_threshold
77
+ end
78
+ end
79
+
80
+ def test_has_correct_transaction_trace_threshold_when_specified
81
+ txn_info = NewRelic::Agent::TransactionInfo.get
82
+ config = {
83
+ :web_transactions_apdex => {'Controller/foo/bar' => 1.5},
84
+ :apdex_t => 2.0,
85
+ :'transaction_tracer.transaction_threshold' => 4.0
86
+ }
87
+
88
+ with_config(config, :do_not_cast => true) do
89
+ txn_info.transaction_name = 'Controller/foo/bar'
90
+ assert_equal 4.0, txn_info.transaction_trace_threshold
91
+ txn_info.transaction_name = 'Controller/some/other/txn'
92
+ assert_equal 4.0, txn_info.transaction_trace_threshold
93
+ end
94
+ end
95
+
96
+ def test_transaction_name
97
+ NewRelic::Agent::TransactionInfo.reset
98
+ txn = NewRelic::Agent::TransactionInfo.get
99
+ assert_equal(NewRelic::Agent::TransactionInfo::DEFAULT_TRANSACTION_NAME,
100
+ txn.transaction_name)
101
+ assert_equal(false, txn.transaction_name_set?)
102
+ txn.transaction_name = "foobar"
103
+ assert_equal("foobar", txn.transaction_name)
104
+ assert_equal(true, txn.transaction_name_set?)
105
+ end
54
106
  end
@@ -102,7 +102,7 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
102
102
 
103
103
  should_be_a_copy = sample.omit_segments_with('OMIT NOTHING')
104
104
  validate_segment should_be_a_copy.root_segment, false
105
-
105
+
106
106
  assert_equal sample.params, should_be_a_copy.params
107
107
  assert_equal(sample.root_segment.to_debug_str(0),
108
108
  should_be_a_copy.root_segment.to_debug_str(0))
@@ -169,7 +169,7 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
169
169
  @builder.finish_trace(Time.now.to_f)
170
170
  validate_builder
171
171
  end
172
-
172
+
173
173
  def test_trace_should_not_record_more_than_segment_limit
174
174
  with_config(:'transaction_tracer.limit_segments' => 3) do
175
175
  8.times {|i| build_segment i.to_s }
@@ -177,6 +177,13 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
177
177
  end
178
178
  end
179
179
 
180
+ def test_finish_trace_records_threshold
181
+ NewRelic::Agent::TransactionInfo.get.stubs(:transaction_trace_threshold) \
182
+ .returns(2.0)
183
+ @builder.finish_trace
184
+ assert_equal 2.0, @builder.sample.threshold
185
+ end
186
+
180
187
  # regression
181
188
  def test_trace_should_log_segment_reached_once
182
189
  with_config(:'transaction_tracer.limit_segments' => 3) do
@@ -184,7 +191,7 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
184
191
  8.times {|i| build_segment i.to_s }
185
192
  end
186
193
  end
187
-
194
+
188
195
  def validate_builder(check_names = true)
189
196
  validate_segment @builder.sample.root_segment, check_names
190
197
  end
@@ -227,10 +227,9 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
227
227
  end
228
228
 
229
229
  def test_store_slowest_sample_new_is_slowest
230
- old_sample = mock('old_sample')
231
- new_sample = mock('new_sample')
230
+ old_sample = stub('old_sample', :duration => 3.0, :threshold => 1.0)
231
+ new_sample = stub('new_sample', :duration => 4.0, :threshold => 1.0)
232
232
  @sampler.instance_eval { @slowest_sample = old_sample }
233
- @sampler.expects(:slowest_sample?).with(old_sample, new_sample).returns(true)
234
233
 
235
234
  @sampler.store_slowest_sample(new_sample)
236
235
 
@@ -248,6 +247,15 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
248
247
  assert_equal(old_sample, @sampler.instance_variable_get('@slowest_sample'))
249
248
  end
250
249
 
250
+ def test_store_slowest_sample_does_not_store_if_faster_than_threshold
251
+ old_sample = stub('old_sample', :duration => 1.0, :threshold => 0.5)
252
+ new_sample = stub('new_sample', :duration => 2.0, :threshold => 4.0)
253
+ @sampler.instance_eval { @slowest_sample = old_sample }
254
+ @sampler.store_slowest_sample(new_sample)
255
+
256
+ assert_equal(old_sample, @sampler.instance_variable_get('@slowest_sample'))
257
+ end
258
+
251
259
  def test_slowest_sample_no_sample
252
260
  old_sample = nil
253
261
  new_sample = mock('new_sample')
@@ -269,7 +277,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
269
277
  new_sample.expects(:duration).returns(1.0)
270
278
  assert_equal(true, @sampler.slowest_sample?(old_sample, new_sample))
271
279
  end
272
-
280
+
273
281
  def test_truncate_samples_no_samples
274
282
  @sampler.instance_eval { @max_samples = 10 }
275
283
  @sampler.instance_eval { @samples = [] }
@@ -358,7 +366,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
358
366
  @sampler.send(:notice_extra_data, nil, nil, nil)
359
367
  end
360
368
 
361
- def test_notice_extra_data_no_segment
369
+ def test_notice_extra_data_no_builder
362
370
  builder = mock('builder')
363
371
  @sampler.expects(:builder).returns(builder).twice
364
372
  builder.expects(:current_segment).returns(nil)
@@ -373,7 +381,8 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
373
381
  builder.expects(:current_segment).returns(segment)
374
382
  segment.expects(:[]).with(key).returns(nil)
375
383
  @sampler.expects(:append_new_message).with(nil, 'a message').returns('a message')
376
- @sampler.expects(:truncate_message).with('a message').returns('truncated_message')
384
+ NewRelic::Agent::TransactionSampler.expects(:truncate_message) \
385
+ .with('a message').returns('truncated_message')
377
386
  segment.expects(:[]=).with(key, 'truncated_message')
378
387
  @sampler.expects(:append_backtrace).with(segment, 1.0)
379
388
  @sampler.send(:notice_extra_data, 'a message', 1.0, key)
@@ -381,12 +390,12 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
381
390
 
382
391
  def test_truncate_message_short_message
383
392
  message = 'a message'
384
- assert_equal(message, @sampler.truncate_message(message))
393
+ assert_equal(message, NewRelic::Agent::TransactionSampler.truncate_message(message))
385
394
  end
386
395
 
387
396
  def test_truncate_message_long_message
388
397
  message = 'a' * 16384
389
- truncated_message = @sampler.truncate_message(message)
398
+ truncated_message = NewRelic::Agent::TransactionSampler.truncate_message(message)
390
399
  assert_equal(16384, truncated_message.length)
391
400
  assert_equal('a' * 16381 + '...', truncated_message)
392
401
  end
@@ -558,17 +567,6 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
558
567
  end
559
568
  end
560
569
 
561
- def test_add_samples_to_under_threshold
562
- result = []
563
- sample = mock('sample')
564
- sample.expects(:duration).returns(1.0).at_least_once
565
- @sampler.instance_eval { @slowest_sample = sample }
566
- @sampler.expects(:add_random_sample_to).with([])
567
- with_config(:'transaction_tracer.transaction_threshold' => 2.0) do
568
- assert_equal([], @sampler.add_samples_to(result))
569
- end
570
- end
571
-
572
570
  def test_add_samples_to_two_sample_enter_one_sample_leave
573
571
  slower_sample = mock('slower')
574
572
  slower_sample.expects(:duration).returns(10.0).at_least_once
@@ -667,23 +665,23 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
667
665
  end
668
666
 
669
667
  def test_sample_tree
670
- assert_equal 0, @sampler.scope_depth
668
+ with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
669
+ assert_equal 0, @sampler.scope_depth
671
670
 
672
- @sampler.notice_first_scope_push Time.now.to_f
673
- @sampler.notice_transaction "/path", nil, {}
674
- @sampler.notice_push_scope "a"
671
+ @sampler.notice_first_scope_push Time.now.to_f
672
+ @sampler.notice_transaction "/path", nil, {}
673
+ @sampler.notice_push_scope "a"
675
674
 
676
- @sampler.notice_push_scope "b"
677
- @sampler.notice_pop_scope "b"
675
+ @sampler.notice_push_scope "b"
676
+ @sampler.notice_pop_scope "b"
678
677
 
679
- @sampler.notice_push_scope "c"
680
- @sampler.notice_push_scope "d"
681
- @sampler.notice_pop_scope "d"
682
- @sampler.notice_pop_scope "c"
678
+ @sampler.notice_push_scope "c"
679
+ @sampler.notice_push_scope "d"
680
+ @sampler.notice_pop_scope "d"
681
+ @sampler.notice_pop_scope "c"
683
682
 
684
- @sampler.notice_pop_scope "a"
685
- @sampler.notice_scope_empty
686
- with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
683
+ @sampler.notice_pop_scope "a"
684
+ @sampler.notice_scope_empty
687
685
  sample = @sampler.harvest([]).first
688
686
  assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
689
687
  end
@@ -696,22 +694,22 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
696
694
  MockGCStats.mock_values = [0,0,0,1,0,0,1,0,0,0,0,0,0,0,0]
697
695
  assert_equal 0, @sampler.scope_depth
698
696
 
699
- @sampler.notice_first_scope_push Time.now.to_f
700
- @sampler.notice_transaction "/path", nil, {}
701
- @sampler.notice_push_scope "a"
697
+ with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
698
+ @sampler.notice_first_scope_push Time.now.to_f
699
+ @sampler.notice_transaction "/path", nil, {}
700
+ @sampler.notice_push_scope "a"
702
701
 
703
- @sampler.notice_push_scope "b"
704
- @sampler.notice_pop_scope "b"
702
+ @sampler.notice_push_scope "b"
703
+ @sampler.notice_pop_scope "b"
705
704
 
706
- @sampler.notice_push_scope "c"
707
- @sampler.notice_push_scope "d"
708
- @sampler.notice_pop_scope "d"
709
- @sampler.notice_pop_scope "c"
705
+ @sampler.notice_push_scope "c"
706
+ @sampler.notice_push_scope "d"
707
+ @sampler.notice_pop_scope "d"
708
+ @sampler.notice_pop_scope "c"
710
709
 
711
- @sampler.notice_pop_scope "a"
712
- @sampler.notice_scope_empty
710
+ @sampler.notice_pop_scope "a"
711
+ @sampler.notice_scope_empty
713
712
 
714
- with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
715
713
  sample = @sampler.harvest([]).first
716
714
  assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
717
715
  end
@@ -730,14 +728,13 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
730
728
  # sample traces, for example. It's unfortunate, but we can't
731
729
  # reliably turn off GC on all versions of ruby under test
732
730
  def test_harvest_slowest
733
- run_sample_trace(0,0.1)
734
- run_sample_trace(0,0.1)
735
- # two second duration
736
- run_sample_trace(0,2)
737
- run_sample_trace(0,0.1)
738
- run_sample_trace(0,0.1)
739
-
740
731
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
732
+ run_sample_trace(0,0.1)
733
+ run_sample_trace(0,0.1)
734
+ # two second duration
735
+ run_sample_trace(0,2)
736
+ run_sample_trace(0,0.1)
737
+ run_sample_trace(0,0.1)
741
738
 
742
739
  slowest = @sampler.harvest(nil)[0]
743
740
  first_duration = slowest.duration
@@ -758,8 +755,8 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
758
755
  end
759
756
 
760
757
  def test_prepare_to_send
761
- run_sample_trace { sleep 0.002 }
762
758
  sample = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
759
+ run_sample_trace { sleep 0.002 }
763
760
  @sampler.harvest(nil)[0]
764
761
  end
765
762
 
@@ -786,43 +783,43 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
786
783
  end
787
784
 
788
785
  def test_sample_with_parallel_paths
789
- assert_equal 0, @sampler.scope_depth
786
+ with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
787
+ assert_equal 0, @sampler.scope_depth
790
788
 
791
- @sampler.notice_first_scope_push Time.now.to_f
792
- @sampler.notice_transaction "/path", nil, {}
793
- @sampler.notice_push_scope "a"
789
+ @sampler.notice_first_scope_push Time.now.to_f
790
+ @sampler.notice_transaction "/path", nil, {}
791
+ @sampler.notice_push_scope "a"
794
792
 
795
- assert_equal 1, @sampler.scope_depth
793
+ assert_equal 1, @sampler.scope_depth
796
794
 
797
- @sampler.notice_pop_scope "a"
798
- @sampler.notice_scope_empty
795
+ @sampler.notice_pop_scope "a"
796
+ @sampler.notice_scope_empty
799
797
 
800
- assert_equal 0, @sampler.scope_depth
798
+ assert_equal 0, @sampler.scope_depth
801
799
 
802
- @sampler.notice_first_scope_push Time.now.to_f
803
- @sampler.notice_transaction "/path", nil, {}
804
- @sampler.notice_push_scope "a"
805
- @sampler.notice_pop_scope "a"
806
- @sampler.notice_scope_empty
800
+ @sampler.notice_first_scope_push Time.now.to_f
801
+ @sampler.notice_transaction "/path", nil, {}
802
+ @sampler.notice_push_scope "a"
803
+ @sampler.notice_pop_scope "a"
804
+ @sampler.notice_scope_empty
807
805
 
808
- assert_equal 0, @sampler.scope_depth
809
- with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
806
+ assert_equal 0, @sampler.scope_depth
810
807
  sample = @sampler.harvest(nil).first
811
808
  assert_equal "ROOT{a}", sample.to_s_compact
812
809
  end
813
810
  end
814
811
 
815
812
  def test_double_scope_stack_empty
816
- @sampler.notice_first_scope_push Time.now.to_f
817
- @sampler.notice_transaction "/path", nil, {}
818
- @sampler.notice_push_scope "a"
819
- @sampler.notice_pop_scope "a"
820
- @sampler.notice_scope_empty
821
- @sampler.notice_scope_empty
822
- @sampler.notice_scope_empty
823
- @sampler.notice_scope_empty
824
-
825
813
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
814
+ @sampler.notice_first_scope_push Time.now.to_f
815
+ @sampler.notice_transaction "/path", nil, {}
816
+ @sampler.notice_push_scope "a"
817
+ @sampler.notice_pop_scope "a"
818
+ @sampler.notice_scope_empty
819
+ @sampler.notice_scope_empty
820
+ @sampler.notice_scope_empty
821
+ @sampler.notice_scope_empty
822
+
826
823
  assert_not_nil @sampler.harvest(nil)[0]
827
824
  end
828
825
  end
@@ -909,11 +906,10 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
909
906
  def test_param_capture
910
907
  [true, false].each do |capture|
911
908
  with_config(:capture_params => capture) do
912
- @sampler.notice_first_scope_push Time.now.to_f
913
- @sampler.notice_transaction('/path', nil, {:param => 'hi'})
914
- @sampler.notice_scope_empty
915
-
916
909
  tt = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
910
+ @sampler.notice_first_scope_push Time.now.to_f
911
+ @sampler.notice_transaction('/path', nil, {:param => 'hi'})
912
+ @sampler.notice_scope_empty
917
913
  @sampler.harvest(nil)[0]
918
914
  end
919
915
 
@@ -936,6 +932,22 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
936
932
  end
937
933
  end
938
934
 
935
+ def test_renaming_current_segment_midflight
936
+ @sampler.start_builder
937
+ @sampler.notice_push_scope( 'External/www.google.com/all' )
938
+ @sampler.rename_scope_segment( 'External/www.google.com/Net::HTTP/GET' )
939
+ assert_nothing_raised do
940
+ @sampler.notice_pop_scope( 'External/www.google.com/Net::HTTP/GET' )
941
+ end
942
+ end
943
+
944
+ def test_adding_segment_parameters
945
+ @sampler.start_builder
946
+ @sampler.notice_push_scope( 'External/www.google.com/all' )
947
+ @sampler.add_segment_parameters( :transaction_guid => '97612F92E6194080' )
948
+ assert_equal '97612F92E6194080', @sampler.builder.current_segment[:transaction_guid]
949
+ end
950
+
939
951
  private
940
952
 
941
953
  def run_sample_trace(start = Time.now.to_f, stop = nil)
@@ -42,7 +42,7 @@ module NewRelic
42
42
  def test_finish_setup_applied_server_side_config
43
43
  with_config({ :'transction_tracer.enabled' => true,
44
44
  'error_collector.enabled' => true,
45
- :log_level => 'info' }, 2) do
45
+ :log_level => 'info' }, :level => 2) do
46
46
  NewRelic::Agent.instance.finish_setup('log_level' => 'debug',
47
47
  'agent_config' => { 'transaction_tracer.enabled' => false },
48
48
  'collect_errors' => false)
@@ -78,10 +78,6 @@ module NewRelic
78
78
  NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric) \
79
79
  .record_data_point(1.0)
80
80
 
81
- # ensure that cached metric ids don't interfere with metric merging
82
- NewRelic::Agent.agent.instance_variable_set(:@metric_ids,
83
- { NewRelic::MetricSpec.new('Instance/Busy') => 1 })
84
-
85
81
  NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
86
82
  NewRelic::Agent.register_report_channel(:agent_test) # before fork
87
83
  pid = Process.fork do
@@ -237,6 +233,40 @@ module NewRelic
237
233
  NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
238
234
  end
239
235
 
236
+ def test_record_metric
237
+ dummy_engine = NewRelic::Agent.agent.stats_engine
238
+ dummy_engine.expects(:record_metric).with('foo', 12)
239
+ NewRelic::Agent.record_metric('foo', 12)
240
+ end
241
+
242
+ def test_record_metric_accepts_hash
243
+ dummy_engine = NewRelic::Agent.agent.stats_engine
244
+ stats_hash = {
245
+ :count => 12,
246
+ :total => 42,
247
+ :min => 1,
248
+ :max => 5,
249
+ :sum_of_squares => 999
250
+ }
251
+ expected_stats = NewRelic::Agent::Stats.new()
252
+ expected_stats.call_count = 12
253
+ expected_stats.total_call_time = 42
254
+ expected_stats.total_exclusive_time = 42
255
+ expected_stats.min_call_time = 1
256
+ expected_stats.max_call_time = 5
257
+ expected_stats.sum_of_squares = 999
258
+ dummy_engine.expects(:record_metric).with('foo', expected_stats)
259
+ NewRelic::Agent.record_metric('foo', stats_hash)
260
+ end
261
+
262
+ def test_increment_metric
263
+ dummy_engine = NewRelic::Agent.agent.stats_engine
264
+ dummy_stats = mock
265
+ dummy_stats.expects(:increment_count).with(12)
266
+ dummy_engine.expects(:record_metric).with('foo').yields(dummy_stats)
267
+ NewRelic::Agent.increment_metric('foo', 12)
268
+ end
269
+
240
270
  private
241
271
 
242
272
  def mocked_agent