newrelic_rpm 3.1.0 → 3.1.1.beta1

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 (94) hide show
  1. data/CHANGELOG +3 -0
  2. data/lib/new_relic/agent.rb +29 -12
  3. data/lib/new_relic/agent/agent.rb +355 -78
  4. data/lib/new_relic/agent/beacon_configuration.rb +49 -7
  5. data/lib/new_relic/agent/browser_monitoring.rb +20 -1
  6. data/lib/new_relic/agent/busy_calculator.rb +11 -3
  7. data/lib/new_relic/agent/chained_call.rb +2 -2
  8. data/lib/new_relic/agent/error_collector.rb +229 -183
  9. data/lib/new_relic/agent/instrumentation.rb +2 -2
  10. data/lib/new_relic/agent/instrumentation/active_merchant.rb +5 -1
  11. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +5 -1
  12. data/lib/new_relic/agent/instrumentation/authlogic.rb +4 -0
  13. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +16 -5
  14. data/lib/new_relic/agent/instrumentation/data_mapper.rb +5 -1
  15. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +5 -1
  16. data/lib/new_relic/agent/instrumentation/memcache.rb +5 -1
  17. data/lib/new_relic/agent/instrumentation/merb/controller.rb +5 -1
  18. data/lib/new_relic/agent/instrumentation/merb/errors.rb +5 -1
  19. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +0 -5
  20. data/lib/new_relic/agent/instrumentation/net.rb +5 -1
  21. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -3
  22. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +5 -1
  23. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +5 -1
  24. data/lib/new_relic/agent/instrumentation/rails/errors.rb +4 -0
  25. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +4 -0
  26. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +13 -6
  27. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +4 -0
  28. data/lib/new_relic/agent/instrumentation/sinatra.rb +4 -0
  29. data/lib/new_relic/agent/instrumentation/sunspot.rb +4 -0
  30. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -1
  31. data/lib/new_relic/agent/method_tracer.rb +205 -99
  32. data/lib/new_relic/agent/shim_agent.rb +0 -1
  33. data/lib/new_relic/agent/stats_engine.rb +1 -0
  34. data/lib/new_relic/agent/stats_engine/metric_stats.rb +23 -7
  35. data/lib/new_relic/agent/stats_engine/samplers.rb +8 -2
  36. data/lib/new_relic/agent/stats_engine/transactions.rb +26 -12
  37. data/lib/new_relic/agent/transaction_sampler.rb +3 -1
  38. data/lib/new_relic/agent/worker_loop.rb +13 -5
  39. data/lib/new_relic/collection_helper.rb +6 -3
  40. data/lib/new_relic/control.rb +1 -3
  41. data/lib/new_relic/control/class_methods.rb +8 -3
  42. data/lib/new_relic/control/configuration.rb +24 -5
  43. data/lib/new_relic/control/frameworks.rb +10 -0
  44. data/lib/new_relic/control/frameworks/external.rb +4 -4
  45. data/lib/new_relic/control/frameworks/merb.rb +1 -0
  46. data/lib/new_relic/control/frameworks/rails.rb +5 -5
  47. data/lib/new_relic/control/frameworks/rails3.rb +5 -3
  48. data/lib/new_relic/control/frameworks/ruby.rb +5 -5
  49. data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
  50. data/lib/new_relic/control/instance_methods.rb +23 -7
  51. data/lib/new_relic/control/instrumentation.rb +22 -3
  52. data/lib/new_relic/control/logging_methods.rb +25 -7
  53. data/lib/new_relic/control/server_methods.rb +16 -6
  54. data/lib/new_relic/data_serialization.rb +83 -14
  55. data/lib/new_relic/delayed_job_injection.rb +7 -1
  56. data/lib/new_relic/local_environment.rb +55 -25
  57. data/lib/new_relic/metric_data.rb +7 -2
  58. data/lib/new_relic/metric_spec.rb +5 -3
  59. data/lib/new_relic/stats.rb +16 -7
  60. data/lib/new_relic/transaction_analysis.rb +2 -1
  61. data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
  62. data/lib/new_relic/transaction_sample.rb +33 -7
  63. data/lib/new_relic/transaction_sample/segment.rb +21 -3
  64. data/lib/new_relic/version.rb +2 -2
  65. data/newrelic_rpm.gemspec +7 -11
  66. data/test/config/newrelic.yml +1 -1
  67. data/test/new_relic/agent/agent/start_worker_thread_test.rb +1 -4
  68. data/test/new_relic/agent/agent_test.rb +16 -0
  69. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  70. data/test/new_relic/agent/agent_test_controller_test.rb +14 -19
  71. data/test/new_relic/agent/beacon_configuration_test.rb +2 -2
  72. data/test/new_relic/agent/browser_monitoring_test.rb +7 -3
  73. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +13 -4
  74. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +0 -10
  75. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  76. data/test/new_relic/agent_test.rb +168 -0
  77. data/test/new_relic/collection_helper_test.rb +21 -3
  78. data/test/new_relic/control/configuration_test.rb +25 -0
  79. data/test/new_relic/data_serialization_test.rb +58 -3
  80. data/test/new_relic/delayed_job_injection_test.rb +17 -0
  81. data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
  82. data/test/new_relic/transaction_analysis_test.rb +3 -3
  83. data/test/new_relic/transaction_sample/segment_test.rb +11 -0
  84. data/test/test_helper.rb +1 -1
  85. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
  86. metadata +13 -13
  87. data/lib/new_relic/histogram.rb +0 -91
  88. data/lib/new_relic/rack/metric_app.rb +0 -65
  89. data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
  90. data/lib/new_relic/rack/newrelic.yml +0 -27
  91. data/lib/new_relic/rack_app.rb +0 -6
  92. data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
  93. data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
  94. data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
@@ -15,11 +15,13 @@ module NewRelic
15
15
  @metric_name = metric_name || '<unknown>'
16
16
  @segment_id = segment_id || object_id
17
17
  end
18
-
18
+
19
+ # sets the final timestamp on a segment to indicate the exit
20
+ # point of the segment
19
21
  def end_trace(timestamp)
20
22
  @exit_timestamp = timestamp
21
23
  end
22
-
24
+
23
25
  def add_called_segment(s)
24
26
  @called_segments ||= []
25
27
  @called_segments << s
@@ -100,7 +102,8 @@ module NewRelic
100
102
  called_segments.each { | seg | count += seg.count_segments }
101
103
  count
102
104
  end
103
- # Walk through the tree and truncate the segments
105
+ # Walk through the tree and truncate the segments in a
106
+ # depth-first manner
104
107
  def truncate(max)
105
108
  return 1 unless @called_segments
106
109
  total, self.called_segments = truncate_each_child(max - 1)
@@ -148,6 +151,21 @@ module NewRelic
148
151
  end
149
152
  end
150
153
 
154
+ # call the provided block for this segment and each
155
+ # of the called segments while keeping track of nested segments
156
+ def each_segment_with_nest_tracking(&block)
157
+ summary = block.call self
158
+ summary.current_nest_count += 1 if summary
159
+
160
+ if @called_segments
161
+ @called_segments.each do |segment|
162
+ segment.each_segment_with_nest_tracking(&block)
163
+ end
164
+ end
165
+
166
+ summary.current_nest_count -= 1 if summary
167
+ end
168
+
151
169
  def find_segment(id)
152
170
  return self if @segment_id == id
153
171
  called_segments.each do |segment|
@@ -3,8 +3,8 @@ module NewRelic
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 3
5
5
  MINOR = 1
6
- TINY = 0
7
- BUILD = nil #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
6
+ TINY = 1
7
+ BUILD = 'beta1' #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
10
10
 
data/newrelic_rpm.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{newrelic_rpm}
8
- s.version = "3.1.0"
8
+ s.version = "3.1.1.beta1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Bill Kayser", "Justin George"]
12
- s.date = %q{2011-06-15}
11
+ s.authors = ["Bill Kayser", "Jon Guymon", "Justin George", "Darin Swanson"]
12
+ s.date = %q{2011-07-06}
13
13
  s.description = %q{New Relic is a performance management system, developed by New Relic,
14
14
  Inc (http://www.newrelic.com). New Relic provides you with deep
15
15
  information about the performance of your web application as it runs
@@ -92,6 +92,7 @@ http://github.com/newrelic/rpm/
92
92
  "lib/new_relic/control.rb",
93
93
  "lib/new_relic/control/class_methods.rb",
94
94
  "lib/new_relic/control/configuration.rb",
95
+ "lib/new_relic/control/frameworks.rb",
95
96
  "lib/new_relic/control/frameworks/external.rb",
96
97
  "lib/new_relic/control/frameworks/merb.rb",
97
98
  "lib/new_relic/control/frameworks/rails.rb",
@@ -105,7 +106,6 @@ http://github.com/newrelic/rpm/
105
106
  "lib/new_relic/control/server_methods.rb",
106
107
  "lib/new_relic/data_serialization.rb",
107
108
  "lib/new_relic/delayed_job_injection.rb",
108
- "lib/new_relic/histogram.rb",
109
109
  "lib/new_relic/local_environment.rb",
110
110
  "lib/new_relic/merbtasks.rb",
111
111
  "lib/new_relic/metric_data.rb",
@@ -114,10 +114,6 @@ http://github.com/newrelic/rpm/
114
114
  "lib/new_relic/noticed_error.rb",
115
115
  "lib/new_relic/rack/browser_monitoring.rb",
116
116
  "lib/new_relic/rack/developer_mode.rb",
117
- "lib/new_relic/rack/metric_app.rb",
118
- "lib/new_relic/rack/mongrel_rpm.ru",
119
- "lib/new_relic/rack/newrelic.yml",
120
- "lib/new_relic/rack_app.rb",
121
117
  "lib/new_relic/recipes.rb",
122
118
  "lib/new_relic/stats.rb",
123
119
  "lib/new_relic/timer_lib.rb",
@@ -176,12 +172,15 @@ http://github.com/newrelic/rpm/
176
172
  "test/new_relic/agent/transaction_sample_builder_test.rb",
177
173
  "test/new_relic/agent/transaction_sampler_test.rb",
178
174
  "test/new_relic/agent/worker_loop_test.rb",
175
+ "test/new_relic/agent_test.rb",
179
176
  "test/new_relic/collection_helper_test.rb",
180
177
  "test/new_relic/command/deployments_test.rb",
181
178
  "test/new_relic/control/class_methods_test.rb",
179
+ "test/new_relic/control/configuration_test.rb",
182
180
  "test/new_relic/control/logging_methods_test.rb",
183
181
  "test/new_relic/control_test.rb",
184
182
  "test/new_relic/data_serialization_test.rb",
183
+ "test/new_relic/delayed_job_injection_test.rb",
185
184
  "test/new_relic/local_environment_test.rb",
186
185
  "test/new_relic/metric_data_test.rb",
187
186
  "test/new_relic/metric_spec_test.rb",
@@ -232,11 +231,8 @@ http://github.com/newrelic/rpm/
232
231
  "ui/views/newrelic/show_source.rhtml",
233
232
  "ui/views/newrelic/threads.rhtml",
234
233
  "vendor/gems/dependency_detection-0.0.1.build/LICENSE",
235
- "vendor/gems/dependency_detection-0.0.1.build/README",
236
234
  "vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb",
237
235
  "vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb",
238
- "vendor/gems/metric_parser-0.1.0.pre1/LICENSE",
239
- "vendor/gems/metric_parser-0.1.0.pre1/README",
240
236
  "vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb",
241
237
  "vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb",
242
238
  "vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb",
@@ -24,7 +24,7 @@ test:
24
24
  - a
25
25
  - b
26
26
  - c
27
- log_file_path: <%= RAILS_ROOT %>/log
27
+ log_file_path: <%= ::Rails::VERSION::MAJOR == 3 ? Rails.root : RAILS_ROOT %>/log
28
28
 
29
29
  # Some fixtures for newrelic.yml parsing tests
30
30
  erb_value: <%= 'hey'*3 %>
@@ -63,10 +63,7 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
63
63
  wl = mock('worker loop')
64
64
  NewRelic::Agent::WorkerLoop.expects(:new).returns(wl)
65
65
  wl.expects(:run).with(30).yields
66
- self.expects(:harvest_and_send_timeslice_data)
67
- self.expects(:harvest_and_send_slowest_sample)
68
- self.expects(:harvest_and_send_errors)
69
- NewRelic::Agent.expects(:load_data)
66
+ self.expects(:save_or_transmit_data)
70
67
  create_and_run_worker_loop
71
68
  end
72
69
 
@@ -8,6 +8,22 @@ module NewRelic
8
8
  @agent = NewRelic::Agent::Agent.new
9
9
  end
10
10
 
11
+ def test_save_or_transmit_data_should_save
12
+ NewRelic::Agent.expects(:save_data).once
13
+ @agent.expects(:harvest_and_send_timeslice_data).never
14
+ NewRelic::DataSerialization.expects(:should_send_data?).returns(false)
15
+ @agent.instance_eval { save_or_transmit_data }
16
+ end
17
+
18
+ def test_save_or_transmit_data_should_transmit
19
+ NewRelic::Agent.expects(:load_data)
20
+ @agent.expects(:harvest_and_send_timeslice_data)
21
+ @agent.expects(:harvest_and_send_slowest_sample)
22
+ @agent.expects(:harvest_and_send_errors)
23
+ NewRelic::DataSerialization.expects(:should_send_data?).returns(true)
24
+ @agent.instance_eval { save_or_transmit_data }
25
+ end
26
+
11
27
  def test_serialize
12
28
  assert_equal([{}, [], []], @agent.send(:serialize), "should return nil when shut down")
13
29
  end
@@ -7,7 +7,7 @@ class NewRelic::Agent::SuperclassController < ActionController::Base
7
7
  end
8
8
  # This is a controller class used in testing controller instrumentation
9
9
  class NewRelic::Agent::AgentTestController < NewRelic::Agent::SuperclassController
10
- filter_parameter_logging :social_security_number
10
+ # filter_parameter_logging :social_security_number
11
11
 
12
12
  @@headers_to_add = nil
13
13
 
@@ -14,16 +14,21 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
14
14
  super name
15
15
 
16
16
  # Suggested by cee-dub for merb tests. I'm actually amazed if our tests work with merb.
17
- if defined?(Merb::Router)
18
- Merb::Router.prepare do |r|
19
- match('/:controller(/:action)(.:format)').register
20
- end
21
- else
22
- ActionController::Routing::Routes.draw do | map |
23
- map.connect '/:controller/:action.:format'
24
- map.connect '/:controller/:action'
17
+ if defined?(Merb::Router)
18
+ Merb::Router.prepare do |r|
19
+ match('/:controller(/:action)(.:format)').register
25
20
  end
26
- end
21
+ elsif NewRelic::Control.instance.rails_version < NewRelic::VersionNumber.new("3.0")
22
+ ActionController::Routing::Routes.draw do |map|
23
+ map.connect '/:controller/:action.:format'
24
+ map.connect '/:controller/:action'
25
+ end
26
+ else
27
+ Rails.application.routes.draw do
28
+ match '/:controller/:action.:format'
29
+ match '/:controller/:action'
30
+ end
31
+ end
27
32
 
28
33
  if defined?(Rails) && Rails.respond_to?(:application) && Rails.application.respond_to?(:routes)
29
34
  @routes = Rails.application.routes
@@ -281,16 +286,6 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
281
286
  assert_equal 0, stats('WebFrontend/Mongrel/Average Queue Time').call_count
282
287
  end
283
288
 
284
- def test_histogram
285
- engine.clear_stats
286
- get :index, 'social_security_number' => "001-555-1212"
287
- stats_engine = NewRelic::Agent.instance.stats_engine
288
- bucket = NewRelic::Agent.instance.stats_engine.metrics.find { | m | m =~ /^Response Times/ }
289
- assert_not_nil bucket, "Bucket contents: #{bucket.inspect}, #{stats_engine.metrics.inspect}"
290
- bucket_stats = stats(bucket)
291
- assert_equal 1, bucket_stats.call_count, "expected the bucket to have a call, but instead got: #{bucket_stats.inspect}"
292
- end
293
-
294
289
  def test_queue_headers_no_header
295
290
  engine.clear_stats
296
291
  queue_length_stat = stats('Mongrel/Queue Length')
@@ -87,13 +87,13 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
87
87
  def test_build_load_file_js_load_episodes_file_missing
88
88
  connect_data = {}
89
89
  bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
90
- assert_equal(184, bc.build_load_file_js(connect_data).size, "should output the javascript when there is no configuration")
90
+ assert_equal(304, bc.build_load_file_js(connect_data).size, "should output the javascript when there is no configuration")
91
91
  end
92
92
 
93
93
  def test_build_load_file_js_load_episodes_file_present
94
94
  connect_data = {'rum.load_episodes_file' => true}
95
95
  bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
96
- assert_equal(184, bc.build_load_file_js(connect_data).size, "should output the javascript when rum.load_episodes_file is true")
96
+ assert_equal(304, bc.build_load_file_js(connect_data).size, "should output the javascript when rum.load_episodes_file is true")
97
97
  end
98
98
 
99
99
  def test_build_load_file_js_load_episodes_file_with_episodes_url
@@ -68,7 +68,9 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
68
68
  Thread.current[:newrelic_start_time] = Time.now
69
69
 
70
70
  footer = browser_timing_footer
71
- snippet = "<script type=\"text/javascript\">(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"this_is_my_file\";e.type=\"text/javascript\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push([\"nrf2\","
71
+ snippet = '<script type="text/javascript">if (!NREUMQ.f) NREUMQ.f=function() {
72
+ NREUMQ.push(["load",new Date().getTime()]);
73
+ var e=document.createElement("script");'
72
74
  assert footer.include?(snippet), "Expected footer to include snippet: #{snippet}, but instead was #{footer}"
73
75
  end
74
76
 
@@ -101,7 +103,9 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
101
103
  config.expects(:license_bytes).returns(license_bytes)
102
104
  NewRelic::Agent.instance.expects(:beacon_configuration).returns(config).at_least_once
103
105
  footer = browser_timing_footer
104
- beginning_snippet = "(function(){var d=document;var e=d.createElement(\"script\");e.async=true;e.src=\"this_is_my_file\";e.type=\"text/javascript\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push([\"nrf2\","
106
+ beginning_snippet = '<script type="text/javascript">if (!NREUMQ.f) NREUMQ.f=function() {
107
+ NREUMQ.push(["load",new Date().getTime()]);
108
+ var e=document.createElement("script");'
105
109
  ending_snippet = "])</script>"
106
110
  assert(footer.include?(beginning_snippet), "expected footer to include beginning snippet: #{beginning_snippet}, but was #{footer}")
107
111
  assert(footer.include?(ending_snippet), "expected footer to include ending snippet: #{ending_snippet}, but was #{footer}")
@@ -234,7 +238,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
234
238
  self.expects(:obfuscate).with('most recent transaction').returns('most recent transaction')
235
239
 
236
240
  value = footer_js_string(beacon, license_key, application_id)
237
- assert_equal('<script type="text/javascript">(function(){var d=document;var e=d.createElement("script");e.async=true;e.src="this_is_my_file";e.type="text/javascript";var s=d.getElementsByTagName("script")[0];s.parentNode.insertBefore(e,s);})();NREUMQ.push(["nrf2","","",1,"most recent transaction",0,0,new Date().getTime()])</script>', value, "should return the javascript given some default values")
241
+ assert_equal("<script type=\"text/javascript\">if (!NREUMQ.f) NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nvar e=document.createElement(\"script\");\ne.type=\"text/javascript\";e.async=true;e.src=\"this_is_my_file\";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nif(window.onload!==NREUMQ.f){NREUMQ.a=window.onload;window.onload=NREUMQ.f;};\nNREUMQ.push([\"nrf2\",\"\",\"\",1,\"most recent transaction\",0,0,new Date().getTime()])</script>", value, "should return the javascript given some default values")
238
242
  end
239
243
 
240
244
  def test_html_safe_if_needed_unsafed
@@ -45,7 +45,8 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
45
45
  check_metric_count(find_metric, 2)
46
46
  end
47
47
 
48
- return if NewRelic::Control.instance.rails_version < "2.3.4"
48
+ return if NewRelic::Control.instance.rails_version < "2.3.4" ||
49
+ NewRelic::Control.instance.rails_version >= "3.1"
49
50
 
50
51
  assert_calls_metrics(find_metric) do
51
52
  ActiveRecordFixtures::Order.exists?(["name=?", 'jeff'])
@@ -450,7 +451,11 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
450
451
  # These are only valid for rails 2.1 and later
451
452
  if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("2.1.0")
452
453
  ActiveRecordFixtures::Order.class_eval do
453
- named_scope :jeffs, :conditions => { :name => 'Jeff' }
454
+ if NewRelic::Control.instance.rails_version < NewRelic::VersionNumber.new("3.1")
455
+ named_scope :jeffs, :conditions => { :name => 'Jeff' }
456
+ else
457
+ scope :jeffs, :conditions => { :name => 'Jeff' }
458
+ end
454
459
  end
455
460
  def test_named_scope
456
461
  ActiveRecordFixtures::Order.create :name => 'Jeff'
@@ -508,15 +513,19 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
508
513
  (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i == 3)
509
514
  end
510
515
 
516
+ def rails_env
517
+ rails3? ? ::Rails.env : RAILS_ENV
518
+ end
519
+
511
520
  def isPostgres?
512
- ActiveRecordFixtures::Order.configurations[RAILS_ENV]['adapter'] =~ /postgres/i
521
+ ActiveRecordFixtures::Order.configurations[rails_env]['adapter'] =~ /postgres/i
513
522
  end
514
523
  def isMysql?
515
524
  ActiveRecordFixtures::Order.connection.class.name =~ /mysql/i
516
525
  end
517
526
 
518
527
  def isSqlite?
519
- ActiveRecord::Base.configurations[RAILS_ENV]['adapter'] =~ /sqlite/i
528
+ ActiveRecord::Base.configurations[rails_env]['adapter'] =~ /sqlite/i
520
529
  end
521
530
 
522
531
  end
@@ -37,14 +37,6 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
37
37
  log_underflow
38
38
  end
39
39
 
40
- def test_process_histogram_for_transaction
41
- fakehistogram = mock('histogram')
42
- agent.expects(:histogram).returns(fakehistogram)
43
- self.expects(:start).returns(2)
44
- fakehistogram.expects(:process).with(1.0)
45
- process_histogram_for_transaction(3)
46
- end
47
-
48
40
  def test_notice_scope_empty
49
41
  transaction_sampler.expects(:notice_scope_empty)
50
42
  notice_scope_empty
@@ -115,14 +107,12 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
115
107
 
116
108
  def test_notify_transaction_sampler_true
117
109
  self.expects(:record_transaction_cpu)
118
- self.expects(:process_histogram_for_transaction)
119
110
  self.expects(:notice_scope_empty)
120
111
  notify_transaction_sampler(true)
121
112
  end
122
113
 
123
114
  def test_notify_transaction_sampler_false
124
115
  self.expects(:record_transaction_cpu)
125
- self.expects(:process_histogram_for_transaction).never
126
116
  self.expects(:notice_scope_empty)
127
117
  notify_transaction_sampler(false)
128
118
  end
@@ -206,7 +206,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
206
206
  assert_raises(RuntimeError) do
207
207
  trace_execution_scoped(['metric', 'array'], passed_in_opts) do
208
208
  ran = true
209
- raise 'wtfmate'
209
+ raise 'raising a test error'
210
210
  end
211
211
  end
212
212
 
@@ -0,0 +1,168 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+ module NewRelic
3
+ class MainAgentTest < Test::Unit::TestCase
4
+
5
+ # mostly this module just passes through to the active agent
6
+ # through the agent method or the control instance through
7
+ # NewRelic::Control.instance . But it's nice to make sure.
8
+
9
+ def teardown
10
+ super
11
+ Thread.current[:newrelic_untraced] = nil
12
+ end
13
+
14
+ def test_shutdown
15
+ mock_agent = mocked_agent
16
+ mock_agent.expects(:shutdown).with({})
17
+ NewRelic::Agent.shutdown
18
+ end
19
+
20
+ def test_after_fork
21
+ mock_agent = mocked_agent
22
+ mock_agent.expects(:after_fork).with({})
23
+ NewRelic::Agent.after_fork
24
+ end
25
+
26
+ def test_reset_stats
27
+ mock_agent = mocked_agent
28
+ mock_agent.expects(:reset_stats)
29
+ NewRelic::Agent.reset_stats
30
+ end
31
+
32
+ def test_manual_start_default
33
+ mock_control = mocked_control
34
+ mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => true})
35
+ NewRelic::Agent.manual_start
36
+ end
37
+
38
+ def test_manual_start_with_opts
39
+ mock_control = mocked_control
40
+ mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => false})
41
+ NewRelic::Agent.manual_start(:sync_startup => false)
42
+ end
43
+
44
+ def test_logger
45
+ control = mocked_control
46
+ control.expects(:log)
47
+ NewRelic::Agent.logger
48
+ end
49
+
50
+ def test_browser_timing_header
51
+ agent = mocked_agent
52
+ agent.expects(:browser_timing_header)
53
+ NewRelic::Agent.browser_timing_header
54
+ end
55
+
56
+ def test_browser_timing_footer
57
+ agent = mocked_agent
58
+ agent.expects(:browser_timing_footer)
59
+ NewRelic::Agent.browser_timing_footer
60
+ end
61
+
62
+ def test_get_stats
63
+ agent = mocked_agent
64
+ mock_stats_engine = mock('stats_engine')
65
+ agent.expects(:stats_engine).returns(mock_stats_engine)
66
+ mock_stats_engine.expects(:get_stats).with('Custom/test/metric', false)
67
+ NewRelic::Agent.get_stats('Custom/test/metric')
68
+ end
69
+
70
+ # note that this is the same as get_stats above, they're just aliases
71
+ def test_get_stats_no_scope
72
+ agent = mocked_agent
73
+ mock_stats_engine = mock('stats_engine')
74
+ agent.expects(:stats_engine).returns(mock_stats_engine)
75
+ mock_stats_engine.expects(:get_stats).with('Custom/test/metric', false)
76
+ NewRelic::Agent.get_stats_no_scope('Custom/test/metric')
77
+ end
78
+
79
+ def test_agent_not_started
80
+ old_agent = NewRelic::Agent.agent
81
+ NewRelic::Agent.instance_eval { @agent = nil }
82
+ assert_raise(RuntimeError) do
83
+ NewRelic::Agent.agent
84
+ end
85
+ NewRelic::Agent.instance_eval { @agent = old_agent }
86
+ end
87
+
88
+ def test_agent_when_started
89
+ old_agent = NewRelic::Agent.agent
90
+ NewRelic::Agent.instance_eval { @agent = 'not nil' }
91
+ assert_equal('not nil', NewRelic::Agent.agent, "should return the value from @agent")
92
+ NewRelic::Agent.instance_eval { @agent = old_agent }
93
+ end
94
+
95
+ def test_abort_transaction_bang
96
+ NewRelic::Agent::Instrumentation::MetricFrame.expects(:abort_transaction!)
97
+ NewRelic::Agent.abort_transaction!
98
+ end
99
+
100
+ def test_is_transaction_traced_true
101
+ Thread.current[:record_tt] = true
102
+ assert_equal(true, NewRelic::Agent.is_transaction_traced?, 'should be true since the thread local is set')
103
+ end
104
+
105
+ def test_is_transaction_traced_blank
106
+ Thread.current[:record_tt] = nil
107
+ assert_equal(true, NewRelic::Agent.is_transaction_traced?, 'should be true since the thread local is not set')
108
+ end
109
+
110
+ def test_is_transaction_traced_false
111
+ Thread.current[:record_tt] = false
112
+ assert_equal(false, NewRelic::Agent.is_transaction_traced?, 'should be false since the thread local is false')
113
+ end
114
+
115
+ def test_is_sql_recorded_true
116
+ Thread.current[:record_sql] = true
117
+ assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is set')
118
+ end
119
+
120
+ def test_is_sql_recorded_blank
121
+ Thread.current[:record_sql] = nil
122
+ assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is not set')
123
+ end
124
+
125
+ def test_is_sql_recorded_false
126
+ Thread.current[:record_sql] = false
127
+ assert_equal(false, NewRelic::Agent.is_sql_recorded?, 'should be false since the thread local is false')
128
+ end
129
+
130
+ def test_is_execution_traced_true
131
+ Thread.current[:newrelic_untraced] = [true, true]
132
+ assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is set')
133
+ end
134
+
135
+ def test_is_execution_traced_blank
136
+ Thread.current[:newrelic_untraced] = nil
137
+ assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is not set')
138
+ end
139
+
140
+ def test_is_execution_traced_empty
141
+ Thread.current[:newrelic_untraced] = []
142
+ assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is an empty array')
143
+ end
144
+
145
+ def test_is_execution_traced_false
146
+ Thread.current[:newrelic_untraced] = [true, false]
147
+ assert_equal(false, NewRelic::Agent.is_execution_traced?, 'should be false since the thread local stack has the last element false')
148
+ end
149
+
150
+ def test_instance
151
+ assert_equal(NewRelic::Agent.agent, NewRelic::Agent.instance, "should return the same agent for both identical methods")
152
+ end
153
+
154
+ private
155
+
156
+ def mocked_agent
157
+ agent = mock('agent')
158
+ NewRelic::Agent.stubs(:agent).returns(agent)
159
+ agent
160
+ end
161
+
162
+ def mocked_control
163
+ control = mock('control')
164
+ NewRelic::Control.stubs(:instance).returns(control)
165
+ control
166
+ end
167
+ end
168
+ end