newrelic_rpm 2.9.9 → 2.10.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (120) hide show
  1. data/CHANGELOG +117 -49
  2. data/bin/mongrel_rpm +2 -2
  3. data/install.rb +42 -33
  4. data/lib/new_relic/agent.rb +149 -39
  5. data/lib/new_relic/agent/agent.rb +139 -122
  6. data/lib/new_relic/agent/busy_calculator.rb +91 -0
  7. data/lib/new_relic/agent/collection_helper.rb +11 -2
  8. data/lib/new_relic/agent/error_collector.rb +33 -27
  9. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +30 -26
  10. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  11. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +316 -105
  12. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
  13. data/lib/new_relic/agent/instrumentation/memcache.rb +18 -12
  14. data/lib/new_relic/agent/instrumentation/merb/errors.rb +2 -1
  15. data/lib/new_relic/agent/instrumentation/metric_frame.rb +258 -0
  16. data/lib/new_relic/agent/instrumentation/net.rb +7 -11
  17. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
  18. data/lib/new_relic/agent/instrumentation/rack.rb +109 -0
  19. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +6 -5
  20. data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -7
  21. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
  22. data/lib/new_relic/agent/method_tracer.rb +305 -150
  23. data/lib/new_relic/agent/sampler.rb +34 -0
  24. data/lib/new_relic/agent/samplers/cpu_sampler.rb +11 -1
  25. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
  26. data/lib/new_relic/agent/samplers/memory_sampler.rb +22 -10
  27. data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
  28. data/lib/new_relic/agent/shim_agent.rb +10 -0
  29. data/lib/new_relic/agent/stats_engine.rb +16 -278
  30. data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
  31. data/lib/new_relic/agent/stats_engine/samplers.rb +81 -0
  32. data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
  33. data/lib/new_relic/agent/transaction_sampler.rb +73 -67
  34. data/lib/new_relic/agent/worker_loop.rb +69 -68
  35. data/lib/new_relic/commands/deployments.rb +4 -6
  36. data/lib/new_relic/control.rb +121 -60
  37. data/lib/new_relic/control/external.rb +13 -0
  38. data/lib/new_relic/control/merb.rb +2 -0
  39. data/lib/new_relic/control/rails.rb +16 -6
  40. data/lib/new_relic/control/ruby.rb +8 -5
  41. data/lib/new_relic/control/sinatra.rb +18 -0
  42. data/lib/new_relic/delayed_job_injection.rb +25 -0
  43. data/lib/new_relic/histogram.rb +89 -0
  44. data/lib/new_relic/local_environment.rb +64 -30
  45. data/lib/new_relic/metric_data.rb +15 -6
  46. data/lib/new_relic/metric_parser.rb +14 -1
  47. data/lib/new_relic/metric_parser/active_record.rb +14 -0
  48. data/lib/new_relic/metric_parser/controller.rb +5 -2
  49. data/lib/new_relic/metric_parser/external.rb +50 -0
  50. data/lib/new_relic/metric_parser/other_transaction.rb +15 -0
  51. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  52. data/lib/new_relic/metric_spec.rb +39 -20
  53. data/lib/new_relic/metrics.rb +9 -7
  54. data/lib/new_relic/noticed_error.rb +6 -8
  55. data/lib/new_relic/rack/metric_app.rb +5 -4
  56. data/lib/new_relic/rack/{newrelic.ru → mongrel_rpm.ru} +4 -4
  57. data/lib/new_relic/rack/newrelic.yml +1 -0
  58. data/lib/new_relic/{rack.rb → rack_app.rb} +0 -0
  59. data/lib/new_relic/recipes.rb +1 -1
  60. data/lib/new_relic/stats.rb +40 -26
  61. data/lib/new_relic/transaction_analysis.rb +5 -2
  62. data/lib/new_relic/transaction_sample.rb +134 -55
  63. data/lib/new_relic/version.rb +27 -20
  64. data/lib/new_relic_api.rb +67 -47
  65. data/lib/newrelic_rpm.rb +5 -5
  66. data/lib/tasks/tests.rake +2 -0
  67. data/newrelic.yml +69 -29
  68. data/test/active_record_fixtures.rb +2 -2
  69. data/test/config/newrelic.yml +4 -7
  70. data/test/config/test_control.rb +1 -2
  71. data/test/new_relic/agent/active_record_instrumentation_test.rb +115 -31
  72. data/test/new_relic/agent/agent_controller_test.rb +274 -0
  73. data/test/new_relic/agent/agent_test_controller.rb +42 -6
  74. data/test/new_relic/agent/busy_calculator_test.rb +79 -0
  75. data/test/new_relic/agent/collection_helper_test.rb +10 -3
  76. data/test/new_relic/agent/error_collector_test.rb +35 -17
  77. data/test/new_relic/agent/method_tracer_test.rb +60 -20
  78. data/test/new_relic/agent/metric_data_test.rb +2 -2
  79. data/test/new_relic/agent/metric_frame_test.rb +51 -0
  80. data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
  81. data/test/new_relic/agent/{agent_test.rb → rpm_agent_test.rb} +26 -5
  82. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  83. data/test/new_relic/{samplers_test.rb → agent/stats_engine/samplers_test.rb} +23 -22
  84. data/test/new_relic/agent/{stats_engine_test.rb → stats_engine/stats_engine_test.rb} +19 -101
  85. data/test/new_relic/agent/task_instrumentation_test.rb +176 -0
  86. data/test/new_relic/agent/transaction_sample_builder_test.rb +2 -2
  87. data/test/new_relic/agent/transaction_sample_test.rb +53 -38
  88. data/test/new_relic/agent/transaction_sampler_test.rb +101 -33
  89. data/test/new_relic/agent/worker_loop_test.rb +16 -14
  90. data/test/new_relic/control_test.rb +26 -13
  91. data/test/new_relic/metric_parser_test.rb +31 -1
  92. data/test/new_relic/metric_spec_test.rb +2 -2
  93. data/test/new_relic/stats_test.rb +0 -8
  94. data/test/new_relic/version_number_test.rb +31 -1
  95. data/test/test_helper.rb +37 -1
  96. data/ui/controllers/newrelic_controller.rb +19 -11
  97. data/ui/helpers/google_pie_chart.rb +5 -11
  98. data/ui/helpers/newrelic_helper.rb +40 -35
  99. data/ui/views/layouts/newrelic_default.rhtml +7 -7
  100. data/ui/views/newrelic/_sample.rhtml +5 -1
  101. data/ui/views/newrelic/images/new-relic-rpm-desktop.gif +0 -0
  102. data/ui/views/newrelic/images/textmate.png +0 -0
  103. data/ui/views/newrelic/index.rhtml +13 -1
  104. data/ui/views/newrelic/show_sample.rhtml +5 -2
  105. data/ui/views/newrelic/stylesheets/style.css +54 -3
  106. metadata +65 -145
  107. data/Manifest +0 -143
  108. data/Rakefile +0 -22
  109. data/init.rb +0 -38
  110. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +0 -127
  111. data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +0 -14
  112. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +0 -13
  113. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +0 -38
  114. data/lib/new_relic/agent/patch_const_missing.rb +0 -125
  115. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +0 -22
  116. data/lib/new_relic/metric_parser/database.rb +0 -23
  117. data/newrelic_rpm.gemspec +0 -35
  118. data/test/new_relic/agent/classloader_patch_test.rb +0 -56
  119. data/test/new_relic/agent/controller_test.rb +0 -107
  120. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +0 -70
@@ -1,8 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
- ##require 'new_relic/agent/error_collector'
3
2
  require 'test/unit'
4
3
 
5
-
6
4
  class FakeRequest
7
5
  attr_reader :path
8
6
 
@@ -18,11 +16,30 @@ end
18
16
  class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
19
17
 
20
18
  def setup
21
- @error_collector = NewRelic::Agent::ErrorCollector.new(nil)
19
+ @error_collector = NewRelic::Agent::ErrorCollector.new
20
+ NewRelic::Agent.instance.stubs(:should_send_errors).returns(true)
21
+ end
22
+ def teardown
23
+
24
+ end
25
+ def test_empty
26
+ @error_collector.harvest_errors([])
27
+ @error_collector.notice_error(nil, :metric=> 'path', :request_params => {:x => 'y'})
28
+ errors = @error_collector.harvest_errors([])
29
+
30
+ assert_equal errors.length, 1
31
+
32
+ err = errors.first
33
+ assert_equal '<no message>', err.message
34
+ assert_equal 'y', err.params[:request_params][:x]
35
+ assert_equal '', err.params[:request_uri]
36
+ assert_equal '', err.params[:request_referer]
37
+ assert_equal 'path', err.path
38
+ assert_equal '<no exception>', err.exception_class
39
+
22
40
  end
23
-
24
41
  def test_simple
25
- @error_collector.notice_error(Exception.new("message"), FakeRequest.new('/myurl/'), 'path', {:x => 'y'})
42
+ @error_collector.notice_error(Exception.new("message"), :uri => '/myurl/', :metric => 'path', :referer => 'test_referer', :request_params => {:x => 'y'})
26
43
 
27
44
  old_errors = []
28
45
  errors = @error_collector.harvest_errors(old_errors)
@@ -46,7 +63,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
46
63
  def test_long_message
47
64
  #yes, times 500. it's a 5000 byte string. Assuming strings are
48
65
  #still 1 byte / char.
49
- @error_collector.notice_error(Exception.new("1234567890" * 500), FakeRequest.new('/myurl/'), 'path', {:x => 'y'})
66
+ @error_collector.notice_error(Exception.new("1234567890" * 500), :uri => '/myurl/', :metric => 'path', :request_params => {:x => 'y'})
50
67
 
51
68
  old_errors = []
52
69
  errors = @error_collector.harvest_errors(old_errors)
@@ -54,17 +71,18 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
54
71
  assert_equal errors.length, 1
55
72
 
56
73
  err = errors.first
57
- assert_equal ('1234567890' * 500)[0..4096], err.message
74
+ assert_equal 4096, err.message.length
75
+ assert_equal ('1234567890' * 500)[0..4095], err.message
58
76
  end
59
77
 
60
78
  def test_collect_failover
61
- @error_collector.notice_error(Exception.new("message"), nil, 'first', {:x => 'y'})
79
+ @error_collector.notice_error(Exception.new("message"), :metric => 'first', :request_params => {:x => 'y'})
62
80
 
63
81
  errors = @error_collector.harvest_errors([])
64
82
 
65
- @error_collector.notice_error(Exception.new("message"), nil, 'second', {:x => 'y'})
66
- @error_collector.notice_error(Exception.new("message"), nil, 'path', {:x => 'y'})
67
- @error_collector.notice_error(Exception.new("message"), nil, 'path', {:x => 'y'})
83
+ @error_collector.notice_error(Exception.new("message"), :metric => 'second', :request_params => {:x => 'y'})
84
+ @error_collector.notice_error(Exception.new("message"), :metric => 'path', :request_params => {:x => 'y'})
85
+ @error_collector.notice_error(Exception.new("message"), :metric => 'path', :request_params => {:x => 'y'})
68
86
 
69
87
  errors = @error_collector.harvest_errors(errors)
70
88
 
@@ -72,8 +90,8 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
72
90
  assert_equal 'first', errors.first.path
73
91
 
74
92
  # add two more
75
- @error_collector.notice_error(Exception.new("message"), nil, 'path', {:x => 'y'})
76
- @error_collector.notice_error(Exception.new("message"), nil, 'last', {:x => 'y'})
93
+ @error_collector.notice_error(Exception.new("message"), :metric => 'path', :request_params => {:x => 'y'})
94
+ @error_collector.notice_error(Exception.new("message"), :metric => 'last', :request_params => {:x => 'y'})
77
95
 
78
96
  errors = @error_collector.harvest_errors(nil)
79
97
  assert_equal 5, errors.length
@@ -88,7 +106,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
88
106
 
89
107
  silence_stream(::STDERR) do
90
108
  (max_q_length + 5).times do |n|
91
- @error_collector.notice_error(Exception.new("exception #{n}"), nil, "path", {:x => n})
109
+ @error_collector.notice_error(Exception.new("exception #{n}"), :metric => "path", :request_params => {:x => n})
92
110
  end
93
111
  end
94
112
 
@@ -119,7 +137,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
119
137
 
120
138
 
121
139
  types.each do |test|
122
- @error_collector.notice_error(Exception.new("message"), nil, 'path', {:x => test[0]})
140
+ @error_collector.notice_error(Exception.new("message"), :metric => 'path', :request_params => {:x => test[0]})
123
141
 
124
142
  assert_equal test[1], @error_collector.harvest_errors([])[0].params[:request_params][:x]
125
143
  end
@@ -129,7 +147,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
129
147
  def test_exclude
130
148
  @error_collector.ignore(["ActionController::RoutingError"])
131
149
 
132
- @error_collector.notice_error(ActionController::RoutingError.new("message"), nil, 'path', {:x => 'y'})
150
+ @error_collector.notice_error(ActionController::RoutingError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
133
151
 
134
152
  errors = @error_collector.harvest_errors([])
135
153
 
@@ -145,7 +163,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
145
163
  end
146
164
  end
147
165
 
148
- @error_collector.notice_error(ActionController::RoutingError.new("message"), nil, 'path', {:x => 'y'})
166
+ @error_collector.notice_error(ActionController::RoutingError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
149
167
 
150
168
  errors = @error_collector.harvest_errors([])
151
169
 
@@ -22,7 +22,7 @@ class Insider
22
22
  # sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
23
23
  sampler = "<none>"
24
24
  begin
25
- @stats_engine.add_scope_stack_listener sampler
25
+ @stats_engine.transaction_sampler = sampler
26
26
  fail "This should not have worked."
27
27
  rescue; end
28
28
  else
@@ -33,15 +33,6 @@ end
33
33
 
34
34
  module NewRelic
35
35
  module Agent
36
-
37
- # for testing, enable the stats engine to clear itself
38
- class StatsEngine
39
- def reset
40
- scope_stack.clear
41
- @stats_hash.clear
42
- end
43
- end
44
-
45
36
  extend self
46
37
  def module_method_to_be_traced (x, testcase)
47
38
  testcase.assert x == "x"
@@ -54,22 +45,27 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
54
45
  attr_reader :stats_engine
55
46
 
56
47
  def setup
48
+ super
57
49
  NewRelic::Agent.manual_start
58
50
  @stats_engine = NewRelic::Agent.instance.stats_engine
59
- @stats_engine.reset
51
+ @stats_engine.clear_stats
60
52
  @scope_listener = NewRelic::Agent::MockScopeListener.new
61
- @stats_engine.add_scope_stack_listener(@scope_listener)
53
+ @old_sampler = NewRelic::Agent.instance.transaction_sampler
54
+ @stats_engine.transaction_sampler = @scope_listener
62
55
  end
63
-
56
+
64
57
  def teardown
58
+ @stats_engine.transaction_sampler = @old_sampler
59
+ @stats_engine.clear_stats
65
60
  self.class.remove_method_tracer :method_to_be_traced, @metric_name if @metric_name
66
61
  @metric_name = nil
62
+ super
67
63
  end
68
64
 
69
65
  def test_basic
70
66
  metric = "hello"
71
67
  t1 = Time.now
72
- self.class.trace_method_execution_with_scope metric, true, true do
68
+ self.class.trace_execution_scoped metric do
73
69
  sleep 1
74
70
  assert metric == @stats_engine.peek_scope.name
75
71
  end
@@ -108,7 +104,27 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
108
104
  assert stats.call_count == 1
109
105
  end
110
106
 
111
-
107
+ def test_add_method_tracer__default
108
+ self.class.add_method_tracer :simple_method
109
+
110
+ simple_method
111
+
112
+ stats = @stats_engine.get_stats("Custom/#{self.class.name}/simple_method")
113
+ assert stats.call_count == 1
114
+
115
+ end
116
+ def test_add_method_tracer__reentry
117
+ self.class.add_method_tracer :simple_method
118
+ self.class.add_method_tracer :simple_method
119
+ self.class.add_method_tracer :simple_method
120
+
121
+ simple_method
122
+
123
+ stats = @stats_engine.get_stats("Custom/#{self.class.name}/simple_method")
124
+ assert stats.call_count == 1
125
+
126
+ end
127
+
112
128
  def test_method_traced?
113
129
  assert !self.class.method_traced?(:method_to_be_traced, METRIC)
114
130
  self.class.add_method_tracer :method_to_be_traced, METRIC
@@ -220,10 +236,32 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
220
236
  self.class.static_method "x", self, false
221
237
  end
222
238
 
239
+ def test_multiple_metrics__scoped
240
+ metrics = %w[first second third]
241
+ self.class.trace_execution_scoped metrics do
242
+ sleep 0.05
243
+ end
244
+ elapsed = @stats_engine.get_stats('first').average_call_time
245
+ metrics.map{|name| @stats_engine.get_stats name}.each do | m |
246
+ assert_equal 1, m.call_count
247
+ assert_equal elapsed, m.total_call_time
248
+ end
249
+ end
250
+ def test_multiple_metrics__unscoped
251
+ metrics = %w[first second third]
252
+ self.class.trace_execution_unscoped metrics do
253
+ sleep 0.05
254
+ end
255
+ elapsed = @stats_engine.get_stats('first').average_call_time
256
+ metrics.map{|name| @stats_engine.get_stats name}.each do | m |
257
+ assert_equal 1, m.call_count
258
+ assert_equal elapsed, m.total_call_time
259
+ end
260
+ end
223
261
  def test_exception
224
262
  begin
225
- metric = "hey there"
226
- self.class.trace_method_execution_with_scope metric, true, true do
263
+ metric = "hey"
264
+ self.class.trace_execution_scoped metric do
227
265
  assert @stats_engine.peek_scope.name == metric
228
266
  throw Exception.new
229
267
  end
@@ -256,8 +294,8 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
256
294
  method_to_be_traced 1,2,3,false,'X'
257
295
  end
258
296
 
259
- def check_time (t1, t2)
260
- assert((t2-t1).abs < 0.01, "Times not close: #{t1} ~ #{t2}")
297
+ def check_time(t1, t2)
298
+ assert_in_delta t2, t1, 0.02
261
299
  end
262
300
 
263
301
  # =======================================================
@@ -296,5 +334,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
296
334
 
297
335
  def method_c3
298
336
  end
299
-
337
+
338
+ def simple_method
339
+ end
300
340
  end
@@ -47,9 +47,9 @@ class NewRelic::Agent::MetricDataTest < Test::Unit::TestCase
47
47
 
48
48
  def compare_metric_data(metric_data, import)
49
49
  assert_equal 3, import.length
50
- compare_spec(metric_data.metric_spec, import['metric_spec'])
51
- compare_stat(metric_data.stats, import['stats'])
52
50
  assert_equal metric_data.metric_id, import['metric_id']
51
+ compare_spec(metric_data.metric_spec, import['metric_spec']) unless metric_data.metric_id
52
+ compare_stat(metric_data.stats, import['stats'])
53
53
  end
54
54
 
55
55
  end
@@ -0,0 +1,51 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
3
+
4
+ class NewRelic::Agent::MetricFrameTest < Test::Unit::TestCase
5
+
6
+ attr_reader :f
7
+ def setup
8
+ @f = NewRelic::Agent::Instrumentation::MetricFrame.new
9
+ end
10
+
11
+ def test_request_parsing__none
12
+ assert_nil f.uri
13
+ assert_nil f.referer
14
+ end
15
+ def test_request_parsing__path
16
+ request = stub(:path => '/path?hello=bob#none')
17
+ f.request = request
18
+ assert_equal "/path", f.uri
19
+ end
20
+ def test_request_parsing__fullpath
21
+ request = stub(:fullpath => '/path?hello=bob#none')
22
+ f.request = request
23
+ assert_equal "/path", f.uri
24
+ end
25
+ def test_request_parsing__referer
26
+ request = stub(:referer => 'https://www.yahoo.com:8080/path/hello?bob=none&foo=bar')
27
+ f.request = request
28
+ assert_nil f.uri
29
+ assert_equal "https://www.yahoo.com:8080/path/hello", f.referer
30
+ end
31
+
32
+ def test_request_parsing__uri
33
+ request = stub(:uri => 'http://creature.com/path?hello=bob#none', :referer => '/path/hello?bob=none&foo=bar')
34
+ f.request = request
35
+ assert_equal "http://creature.com/path", f.uri
36
+ assert_equal "/path/hello", f.referer
37
+ end
38
+
39
+ def test_request_parsing__hostname_only
40
+ request = stub(:uri => 'http://creature.com')
41
+ f.request = request
42
+ assert_equal "http://creature.com", f.uri
43
+ assert_nil f.referer
44
+ end
45
+ def test_request_parsing__slash
46
+ request = stub(:uri => 'http://creature.com/')
47
+ f.request = request
48
+ assert_equal "http://creature.com/", f.uri
49
+ assert_nil f.referer
50
+ end
51
+ end
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+
3
+ class NewRelic::Agent::NetInstrumentationTest < Test::Unit::TestCase
4
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
5
+ def setup
6
+ NewRelic::Agent.manual_start
7
+ @engine = NewRelic::Agent.instance.stats_engine
8
+ @engine.clear_stats
9
+ end
10
+ def test_get
11
+ url = URI.parse('http://www.google.com/index.html')
12
+ res = Net::HTTP.start(url.host, url.port) {|http|
13
+ http.get('/index.html')
14
+ }
15
+ assert_match /<head>/, res.body
16
+ assert_equal %w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort,
17
+ @engine.metrics.sort
18
+ end
19
+
20
+ def test_background
21
+ perform_action_with_newrelic_trace("task", :category => :task) do
22
+ url = URI.parse('http://www.google.com/index.html')
23
+ res = Net::HTTP.start(url.host, url.port) {|http|
24
+ http.get('/index.html')
25
+ }
26
+ assert_match /<head>/, res.body
27
+ end
28
+ assert_equal @engine.metrics.select{|m| m =~ /^External/}.sort,
29
+ %w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all
30
+ External/www.google.com/Net::HTTP/GET:OtherTransaction/Background/NewRelic::Agent::NetInstrumentationTest/task].sort
31
+ end
32
+
33
+ def test_transactional
34
+ perform_action_with_newrelic_trace("task") do
35
+ url = URI.parse('http://www.google.com/index.html')
36
+ res = Net::HTTP.start(url.host, url.port) {|http|
37
+ http.get('/index.html')
38
+ }
39
+ assert_match /<head>/, res.body
40
+ end
41
+ assert_equal @engine.metrics.select{|m| m =~ /^External/}.sort,
42
+ %w[External/www.google.com/Net::HTTP/GET External/allWeb External/www.google.com/all
43
+ External/www.google.com/Net::HTTP/GET:Controller/NewRelic::Agent::NetInstrumentationTest/task].sort
44
+ end
45
+ def test_get__simple
46
+ Net::HTTP.get URI.parse('http://www.google.com/index.html')
47
+ assert_equal @engine.metrics.sort,
48
+ %w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort
49
+ end
50
+ def test_ignore
51
+ NewRelic::Agent.disable_all_tracing do
52
+ url = URI.parse('http://www.google.com/index.html')
53
+ res = Net::HTTP.start(url.host, url.port) {|http|
54
+ http.post('/index.html','data')
55
+ }
56
+ end
57
+ assert_equal 0, @engine.metrics.size
58
+ end
59
+ def test_head
60
+ url = URI.parse('http://www.google.com/index.html')
61
+ res = Net::HTTP.start(url.host, url.port) {|http|
62
+ http.head('/index.html')
63
+ }
64
+ assert_equal %w[External/www.google.com/Net::HTTP/HEAD External/allOther External/www.google.com/all].sort,
65
+ @engine.metrics.sort
66
+ end
67
+
68
+ def test_post
69
+ url = URI.parse('http://www.google.com/index.html')
70
+ res = Net::HTTP.start(url.host, url.port) {|http|
71
+ http.post('/index.html','data')
72
+ }
73
+ assert_equal %w[External/www.google.com/Net::HTTP/POST External/allOther External/www.google.com/all].sort,
74
+ @engine.metrics.sort
75
+ end
76
+
77
+ end
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
2
2
  ##require 'new_relic/agent/agent'
3
3
  ##require 'new_relic/local_environment'
4
4
 
5
- class AgentTest < ActiveSupport::TestCase
5
+ class RpmAgentTest < ActiveSupport::TestCase
6
6
 
7
7
  attr_reader :agent
8
8
 
@@ -35,10 +35,10 @@ class AgentTest < ActiveSupport::TestCase
35
35
  ignore_called = true
36
36
  nil
37
37
  end
38
+ NewRelic::Agent.notice_error(ActionController::RoutingError.new("message"), :request_params => {:x => "y"})
39
+ assert ignore_called
40
+ NewRelic::Agent.ignore_error_filter
38
41
 
39
- NewRelic::Agent.agent.error_collector.notice_error(ActionController::RoutingError.new("message"), nil, "path", {:x => "y"} )
40
-
41
- assert ignore_called
42
42
  end
43
43
 
44
44
  def test_startup_shutdown
@@ -70,8 +70,29 @@ class AgentTest < ActiveSupport::TestCase
70
70
  assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
71
71
  end
72
72
 
73
+ def test_send_timeslice_data
74
+ @agent.expects(:invoke_remote).returns({NewRelic::MetricSpec.new("/A/b/c") => 1, NewRelic::MetricSpec.new("/A/b/c", "/X") => 2, NewRelic::MetricSpec.new("/A/b/d") => 3 }.to_a)
75
+ @agent.send :harvest_and_send_timeslice_data
76
+ assert_equal 3, @agent.metric_ids.size
77
+ assert_equal 3, @agent.metric_ids[NewRelic::MetricSpec.new("/A/b/d") ], @agent.metric_ids.inspect
78
+ end
79
+ def test_set_record_sql
80
+ @agent.set_record_sql(false)
81
+ assert !Thread::current[:record_sql]
82
+ NewRelic::Agent.disable_sql_recording do
83
+ assert_equal false, Thread::current[:record_sql]
84
+ NewRelic::Agent.disable_sql_recording do
85
+ assert_equal false, Thread::current[:record_sql]
86
+ end
87
+ assert_equal false, Thread::current[:record_sql]
88
+ end
89
+ assert !Thread::current[:record_sql], Thread::current[:record_sql]
90
+ ensure
91
+ @agent.set_record_sql(nil)
92
+ end
93
+
73
94
  def test_version
74
- assert_match /\d\.\d\.\d+/, NewRelic::VERSION::STRING
95
+ assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
75
96
  end
76
97
 
77
98
  def test_invoke_remote__ignore_non_200_results