newrelic_rpm 3.6.5.130 → 3.6.6.147

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +27 -3
  3. data/Gemfile +1 -14
  4. data/Rakefile +15 -5
  5. data/config.dot +1 -1
  6. data/lib/new_relic/agent/agent.rb +15 -0
  7. data/lib/new_relic/agent/agent_logger.rb +19 -14
  8. data/lib/new_relic/agent/configuration/defaults.rb +4 -3
  9. data/lib/new_relic/agent/configuration/environment_source.rb +6 -4
  10. data/lib/new_relic/agent/configuration/manager.rb +7 -2
  11. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -2
  12. data/lib/new_relic/agent/cross_app_monitor.rb +5 -4
  13. data/lib/new_relic/agent/cross_app_tracing.rb +0 -1
  14. data/lib/new_relic/agent/error_collector.rb +30 -1
  15. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +67 -0
  16. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +59 -0
  17. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +12 -0
  18. data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -3
  19. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +3 -3
  20. data/lib/new_relic/agent/instrumentation/authlogic.rb +3 -3
  21. data/lib/new_relic/agent/instrumentation/curb.rb +179 -0
  22. data/lib/new_relic/agent/instrumentation/data_mapper.rb +3 -3
  23. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +35 -26
  24. data/lib/new_relic/agent/instrumentation/httpclient.rb +46 -0
  25. data/lib/new_relic/agent/instrumentation/merb/controller.rb +3 -3
  26. data/lib/new_relic/agent/instrumentation/puma.rb +23 -0
  27. data/lib/new_relic/agent/instrumentation/rack.rb +40 -0
  28. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +4 -4
  29. data/lib/new_relic/agent/instrumentation/rails/errors.rb +0 -1
  30. data/lib/new_relic/agent/instrumentation/sequel.rb +0 -1
  31. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  32. data/lib/new_relic/agent/internal_agent_error.rb +18 -0
  33. data/lib/new_relic/agent/new_relic_service.rb +2 -8
  34. data/lib/new_relic/agent/request_sampler.rb +4 -6
  35. data/lib/new_relic/agent/samplers/cpu_sampler.rb +0 -1
  36. data/lib/new_relic/agent/stats.rb +9 -0
  37. data/lib/new_relic/agent/stats_engine/stats_hash.rb +44 -6
  38. data/lib/new_relic/agent/system_info.rb +1 -1
  39. data/lib/new_relic/agent/thread_profiler.rb +6 -6
  40. data/lib/new_relic/agent/transaction.rb +1 -1
  41. data/lib/new_relic/agent/transaction_info.rb +0 -1
  42. data/lib/new_relic/agent/transaction_sample_builder.rb +6 -5
  43. data/lib/new_relic/agent/transaction_sampler.rb +1 -1
  44. data/lib/new_relic/commands/deployments.rb +6 -0
  45. data/lib/new_relic/commands/install.rb +2 -2
  46. data/lib/new_relic/control/frameworks/rails.rb +1 -2
  47. data/lib/new_relic/control/instrumentation.rb +2 -2
  48. data/lib/new_relic/control/server_methods.rb +1 -2
  49. data/lib/new_relic/delayed_job_injection.rb +0 -40
  50. data/lib/new_relic/helper.rb +0 -1
  51. data/lib/new_relic/latest_changes.rb +1 -1
  52. data/lib/new_relic/local_environment.rb +9 -4
  53. data/lib/new_relic/metric_spec.rb +19 -3
  54. data/lib/new_relic/noticed_error.rb +2 -1
  55. data/lib/new_relic/rack/agent_hooks.rb +0 -1
  56. data/lib/new_relic/rack/developer_mode.rb +1 -1
  57. data/lib/new_relic/rack/error_collector.rb +42 -21
  58. data/lib/new_relic/recipes.rb +0 -1
  59. data/lib/new_relic/transaction_analysis.rb +0 -1
  60. data/lib/new_relic/transaction_sample/segment.rb +4 -4
  61. data/lib/new_relic/version.rb +1 -1
  62. data/lib/sequel/extensions/newrelic_instrumentation.rb +6 -7
  63. data/lib/sequel/plugins/newrelic_instrumentation.rb +0 -1
  64. data/lib/tasks/install.rake +2 -2
  65. data/newrelic_rpm.gemspec +11 -1
  66. data/test/active_record_fixtures.rb +2 -2
  67. data/test/agent_helper.rb +46 -3
  68. data/test/config/newrelic.yml +2 -2
  69. data/test/multiverse/.gitignore +2 -0
  70. data/test/multiverse/lib/multiverse/envfile.rb +6 -9
  71. data/test/multiverse/lib/multiverse/environment.rb +0 -1
  72. data/test/multiverse/lib/multiverse/output_collector.rb +43 -11
  73. data/test/multiverse/lib/multiverse/runner.rb +37 -5
  74. data/test/multiverse/lib/multiverse/suite.rb +149 -67
  75. data/test/multiverse/script/run_one +4 -2
  76. data/test/multiverse/script/runner +1 -5
  77. data/test/multiverse/suites/active_record/Envfile +3 -2
  78. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +13 -12
  79. data/test/multiverse/suites/active_record/config/newrelic.yml +0 -3
  80. data/test/multiverse/suites/agent_only/audit_log_test.rb +30 -34
  81. data/test/multiverse/suites/agent_only/before_suite.rb +7 -0
  82. data/test/multiverse/suites/agent_only/config/newrelic.yml +1 -7
  83. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +12 -20
  84. data/test/multiverse/suites/agent_only/http_response_code_test.rb +16 -34
  85. data/test/multiverse/suites/agent_only/key_transactions_test.rb +18 -28
  86. data/test/multiverse/suites/agent_only/logging_test.rb +25 -49
  87. data/test/multiverse/suites/agent_only/marshaling_test.rb +30 -38
  88. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +12 -6
  89. data/test/multiverse/suites/agent_only/rename_rule_test.rb +30 -38
  90. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +16 -18
  91. data/test/multiverse/suites/agent_only/service_timeout_test.rb +6 -7
  92. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +26 -32
  93. data/test/multiverse/suites/agent_only/ssl_test.rb +10 -14
  94. data/test/multiverse/suites/agent_only/start_up_test.rb +1 -1
  95. data/test/multiverse/suites/agent_only/testing_app.rb +2 -0
  96. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +23 -24
  97. data/test/multiverse/suites/config_file_loading/Envfile +6 -2
  98. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +8 -4
  99. data/test/multiverse/suites/curb/Envfile +19 -0
  100. data/test/multiverse/suites/curb/config/newrelic.yml +19 -0
  101. data/test/multiverse/suites/curb/curb_test.rb +195 -0
  102. data/test/multiverse/suites/datamapper/Envfile +2 -0
  103. data/test/multiverse/suites/datamapper/config/newrelic.yml +0 -2
  104. data/test/multiverse/suites/datamapper/datamapper_test.rb +6 -10
  105. data/test/multiverse/suites/deferred_instrumentation/Envfile +19 -0
  106. data/test/multiverse/suites/deferred_instrumentation/config/newrelic.yml +22 -0
  107. data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +103 -0
  108. data/test/multiverse/suites/excon/config/newrelic.yml +0 -2
  109. data/test/multiverse/suites/excon/excon_test.rb +3 -3
  110. data/test/multiverse/suites/httpclient/Envfile +15 -0
  111. data/test/multiverse/suites/httpclient/config/newrelic.yml +19 -0
  112. data/test/multiverse/suites/httpclient/httpclient_test.rb +70 -0
  113. data/test/multiverse/suites/net_http/config/newrelic.yml +0 -2
  114. data/test/multiverse/suites/net_http/net_http_test.rb +9 -4
  115. data/test/multiverse/suites/padrino/Envfile +2 -0
  116. data/test/multiverse/suites/padrino/config/newrelic.yml +0 -3
  117. data/test/multiverse/suites/padrino/padrino_test.rb +5 -4
  118. data/test/multiverse/suites/rails/Envfile +3 -0
  119. data/test/multiverse/suites/rails/app.rb +1 -0
  120. data/test/multiverse/suites/rails/bad_instrumentation_test.rb +31 -0
  121. data/test/multiverse/suites/rails/config/newrelic.yml +2 -3
  122. data/test/multiverse/suites/rails/error_tracing_test.rb +32 -41
  123. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +6 -16
  124. data/test/multiverse/suites/rails/queue_time_test.rb +4 -20
  125. data/test/multiverse/suites/rails/request_statistics_test.rb +7 -32
  126. data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -10
  127. data/test/multiverse/suites/resque/config/newrelic.yml +1 -3
  128. data/test/multiverse/suites/resque/instrumentation_test.rb +10 -7
  129. data/test/multiverse/suites/sequel/Envfile +8 -0
  130. data/test/multiverse/suites/sequel/config/newrelic.yml +0 -3
  131. data/test/multiverse/suites/sequel/sequel_test.rb +1 -2
  132. data/test/multiverse/suites/sidekiq/Envfile +0 -12
  133. data/test/multiverse/suites/sidekiq/config/newrelic.yml +1 -3
  134. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +44 -100
  135. data/test/multiverse/suites/sinatra/config/newrelic.yml +0 -3
  136. data/test/multiverse/suites/sinatra/ignoring_test.rb +8 -5
  137. data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +8 -1
  138. data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +9 -12
  139. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +9 -8
  140. data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +1 -1
  141. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +6 -5
  142. data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +10 -13
  143. data/test/multiverse/suites/typhoeus/config/newrelic.yml +0 -2
  144. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +7 -4
  145. data/test/multiverse/test/suite_examples/one/a/a_test.rb +0 -1
  146. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +0 -1
  147. data/test/multiverse/test/suite_examples/one/b/b_test.rb +0 -1
  148. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +0 -1
  149. data/test/new_relic/agent/agent/connect_test.rb +1 -1
  150. data/test/new_relic/agent/agent/start_test.rb +0 -1
  151. data/test/new_relic/agent/agent/start_worker_thread_test.rb +0 -1
  152. data/test/new_relic/agent/agent_logger_test.rb +37 -3
  153. data/test/new_relic/agent/agent_test.rb +23 -1
  154. data/test/new_relic/agent/browser_monitoring_test.rb +0 -1
  155. data/test/new_relic/agent/busy_calculator_test.rb +2 -2
  156. data/test/new_relic/agent/configuration/environment_source_test.rb +22 -0
  157. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -1
  158. data/test/new_relic/agent/error_collector_test.rb +95 -13
  159. data/test/new_relic/agent/event_listener_test.rb +0 -1
  160. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +23 -0
  161. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +4 -2
  162. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +0 -1
  163. data/test/new_relic/agent/instrumentation/queue_time_test.rb +16 -11
  164. data/test/new_relic/agent/instrumentation/rack_test.rb +0 -1
  165. data/test/new_relic/agent/memcache_instrumentation_test.rb +7 -7
  166. data/test/{multiverse/suites/agent_only/test_trace_method_with_punctuation.rb → new_relic/agent/method_interrobang_test.rb} +3 -5
  167. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -2
  168. data/test/{multiverse/suites/agent_only → new_relic/agent}/method_visibility_test.rb +17 -29
  169. data/test/new_relic/agent/new_relic_service_test.rb +1 -1
  170. data/test/new_relic/agent/pipe_service_test.rb +1 -1
  171. data/test/new_relic/agent/request_sampler_test.rb +10 -10
  172. data/test/new_relic/agent/rpm_agent_test.rb +1 -2
  173. data/test/new_relic/agent/stats_hash_test.rb +83 -5
  174. data/test/new_relic/agent/stats_test.rb +0 -1
  175. data/test/new_relic/agent/thread_profiler_test.rb +7 -7
  176. data/test/new_relic/agent/threaded_test.rb +1 -2
  177. data/test/new_relic/agent/transaction/pop_test.rb +0 -1
  178. data/test/{multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb → new_relic/agent/transaction_interrobang_test.rb} +2 -4
  179. data/test/new_relic/agent/transaction_sample_builder_test.rb +13 -0
  180. data/test/new_relic/agent/transaction_test.rb +7 -5
  181. data/test/new_relic/agent/worker_loop_test.rb +0 -1
  182. data/test/new_relic/agent_test.rb +0 -27
  183. data/test/new_relic/collection_helper_test.rb +17 -17
  184. data/test/new_relic/control/class_methods_test.rb +1 -1
  185. data/test/new_relic/control_test.rb +6 -6
  186. data/test/new_relic/dependency_detection_test.rb +28 -0
  187. data/test/new_relic/evil_server.rb +0 -1
  188. data/test/new_relic/fake_collector.rb +20 -2
  189. data/test/new_relic/fake_server.rb +0 -12
  190. data/test/new_relic/http_client_test_cases.rb +20 -24
  191. data/test/new_relic/metric_spec_test.rb +18 -0
  192. data/test/new_relic/multiverse_helpers.rb +164 -0
  193. data/test/new_relic/rack/agent_hooks_test.rb +0 -1
  194. data/test/new_relic/rack/all_test.rb +0 -1
  195. data/test/new_relic/rack/deferred_instrumentation_test.rb +35 -0
  196. data/test/new_relic/rack/developer_mode_helper_test.rb +8 -9
  197. data/test/new_relic/rack/developer_mode_test.rb +0 -2
  198. data/test/new_relic/rack/error_collector_test.rb +52 -8
  199. data/test/new_relic/transaction_sample/composite_segment_test.rb +0 -1
  200. data/test/new_relic/transaction_sample/fake_segment_test.rb +0 -1
  201. data/test/new_relic/transaction_sample/segment_test.rb +0 -1
  202. data/test/new_relic/transaction_sample/summary_segment_test.rb +0 -1
  203. data/test/performance/README.md +162 -0
  204. data/test/performance/lib/performance.rb +28 -0
  205. data/test/performance/lib/performance/console_reporter.rb +51 -0
  206. data/test/performance/lib/performance/hako_client.rb +31 -0
  207. data/test/performance/lib/performance/hako_reporter.rb +26 -0
  208. data/test/performance/lib/performance/instrumentation/cpu_usage.rb +26 -0
  209. data/test/performance/lib/performance/instrumentation/gc_stats.rb +53 -0
  210. data/test/performance/lib/performance/instrumentation/perf_tools.rb +30 -0
  211. data/test/performance/lib/performance/instrumentor.rb +110 -0
  212. data/test/performance/lib/performance/json_reporter.rb +15 -0
  213. data/test/performance/lib/performance/result.rb +80 -0
  214. data/test/performance/lib/performance/runner.rb +207 -0
  215. data/test/performance/lib/performance/test_case.rb +65 -0
  216. data/test/performance/lib/performance/timer.rb +38 -0
  217. data/test/performance/script/mega-runner +37 -0
  218. data/test/performance/script/runner +81 -0
  219. data/test/performance/suites/startup.rb +12 -0
  220. data/test/performance/suites/transaction_tracing.rb +66 -0
  221. data/test/script/ci_agent-tests_runner.sh +4 -4
  222. data/test/script/ci_multiverse_runner.sh +3 -3
  223. data/test/test_helper.rb +0 -11
  224. data/ui/helpers/developer_mode_helper.rb +1 -1
  225. data/ui/views/layouts/newrelic_default.rhtml +1 -1
  226. data/ui/views/newrelic/_segment.rhtml +2 -2
  227. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -1
  228. data/ui/views/newrelic/_show_sample_detail.rhtml +1 -1
  229. data/ui/views/newrelic/_show_sample_sql.rhtml +4 -4
  230. data/ui/views/newrelic/_stack_trace.rhtml +2 -2
  231. data/ui/views/newrelic/file/javascript/transaction_sample.js +3 -3
  232. data/ui/views/newrelic/file/stylesheets/style.css +13 -13
  233. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +18 -4
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +0 -1
  235. metadata +186 -17
  236. metadata.gz.sig +0 -0
  237. data/test/multiverse/suites/active_record/encoding_test.rb +0 -30
  238. data/test/multiverse/suites/agent_only/no_dns_resolv.rb +0 -21
  239. data/test/multiverse/suites/sidekiq/app.rb +0 -25
  240. data/test/new_relic/delayed_job_injection_test.rb +0 -25
@@ -14,14 +14,17 @@ omit_mocha!
14
14
  gemfile <<-RB
15
15
  gem 'rails', '~>3.2.0'
16
16
  gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
17
+ gem 'minitest_tu_shim', :require => false
17
18
  RB
18
19
 
19
20
  gemfile <<-RB
20
21
  gem 'rails', '~>3.1.0'
21
22
  gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
23
+ gem 'minitest_tu_shim', :require => false
22
24
  RB
23
25
 
24
26
  gemfile <<-RB
25
27
  gem 'rails', '~>3.0.0'
26
28
  gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
29
+ gem 'minitest_tu_shim', :require => false
27
30
  RB
@@ -31,6 +31,7 @@ if !defined?(MyApp)
31
31
  config.active_support.deprecation = :log
32
32
  config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
33
33
  config.eager_load = false
34
+ config.filter_parameters += [:secret]
34
35
  initializer "install_error_middleware" do
35
36
  config.middleware.use ErrorMiddleware
36
37
  end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require './app'
6
+ require 'rails/test_help'
7
+ require 'multiverse_helpers'
8
+
9
+ class BadInstrumentationController < ApplicationController
10
+ include Rails.application.routes.url_helpers
11
+
12
+ # This action is intended to simulate a chunk of instrumentation that pushes
13
+ # a TT scope, but then never pops it. Such a situation will break
14
+ # instrumentation of that request, but should not actually cause the request
15
+ # to fail.
16
+ # https://newrelic.atlassian.net/browse/RUBY-1158
17
+ def failwhale
18
+ NewRelic::Agent.instance.stats_engine.push_scope('failwhale', Time.now)
19
+ render :text => 'everything went great'
20
+ end
21
+ end
22
+
23
+ class BadInstrumentationTest < ActionDispatch::IntegrationTest
24
+ include MultiverseHelpers
25
+ setup_and_teardown_agent
26
+
27
+ def test_unbalanced_tt_stack_should_not_cause_request_to_fail
28
+ rsp = get '/bad_instrumentation/failwhale'
29
+ assert_equal(200, rsp.to_i)
30
+ end
31
+ end
@@ -1,10 +1,9 @@
1
1
  common: &default_settings
2
2
  license_key: 'bd0e1d52adade840f7ca727d29a86249e89a6f1c'
3
3
  host: 127.0.0.1
4
- port: <%= 30_000 + ($$ % 10_000) %>
4
+ port: <%= $collector && $collector.port %>
5
5
  app_name: Rails 3 view test ap
6
6
  enabled: true
7
- log_level: debug
8
7
  ssl: false
9
8
  apdex_t: 1.0
10
9
  capture_params: true
@@ -15,7 +14,7 @@ common: &default_settings
15
14
  stack_trace_threshold: 0.500
16
15
  error_collector:
17
16
  enabled: true
18
- capture_source: true
17
+ capture_source: true
19
18
  ignore_errors: IgnoredError
20
19
 
21
20
  development:
@@ -5,6 +5,7 @@
5
5
  # https://newrelic.atlassian.net/browse/RUBY-747
6
6
  require 'rails/test_help'
7
7
  require 'fake_collector'
8
+ require 'multiverse_helpers'
8
9
 
9
10
  class ErrorController < ApplicationController
10
11
  include Rails.application.routes.url_helpers
@@ -14,6 +15,10 @@ class ErrorController < ApplicationController
14
15
  raise 'this is an uncaught controller error'
15
16
  end
16
17
 
18
+ def exception_error
19
+ raise Exception.new('wobble')
20
+ end
21
+
17
22
  def view_error
18
23
  render :inline => "<% raise 'this is an uncaught view error' %>"
19
24
  end
@@ -50,39 +55,20 @@ class ServerIgnoredError < StandardError; end
50
55
  class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
51
56
  extend Multiverse::Color
52
57
 
53
- def setup
54
- $collector ||= NewRelic::FakeCollector.new
55
- $collector.reset
56
- setup_collector
57
- $collector.run
58
-
59
- NewRelic::Agent.reset_config
60
- NewRelic::Agent.instance_variable_set(:@agent, nil)
61
- NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
62
- NewRelic::Agent.manual_start
63
- NewRelic::Agent::TransactionInfo.reset
58
+ include MultiverseHelpers
64
59
 
65
- reset_error_collector
60
+ setup_and_teardown_agent do |collector|
61
+ setup_collector_mocks
62
+ @error_collector = agent.error_collector
66
63
  end
67
64
 
68
65
  # Let base class override this without moving where we start the agent
69
- def setup_collector
66
+ def setup_collector_mocks
70
67
  $collector.mock['connect'] = [200, {'return_value' => {"agent_run_id" => 666 }}]
71
68
  end
72
69
 
73
- def teardown
74
- NewRelic::Agent::Agent.instance.shutdown if NewRelic::Agent::Agent.instance
75
- NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
76
- end
77
-
78
- def reset_error_collector
79
- @error_collector = NewRelic::Agent::Agent.instance.error_collector
80
-
81
- # sanity checks
82
- assert(@error_collector.enabled?,
83
- 'error collector should be enabled')
84
- assert(!NewRelic::Agent.instance.error_collector.ignore_error_filter,
85
- 'no ignore error filter should be set')
70
+ def last_error
71
+ @error_collector.errors.last
86
72
  end
87
73
 
88
74
  def test_error_collector_should_be_enabled
@@ -136,12 +122,24 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
136
122
  assert_error_reported_once('this is an uncaught routing error')
137
123
  end
138
124
 
125
+ def test_should_apply_parameter_filtering
126
+ get '/error/controller_error?secret=shouldnotbecaptured&other=whatever'
127
+ params = last_error.params[:request_params]
128
+ assert_equal('[FILTERED]', params['secret'])
129
+ assert_equal('whatever', params['other'])
130
+ end
131
+
132
+ def test_should_apply_parameter_filtering_for_errors_captured_by_rack_error_collector
133
+ get '/error/exception_error?secret=shouldnotbecaptured&other=whatever'
134
+ params = last_error.params[:request_params]
135
+ assert_equal('[FILTERED]', params['secret'])
136
+ assert_equal('whatever', params['other'])
137
+ end
138
+
139
139
  def test_should_capture_request_uri_and_params
140
140
  get '/bad_route?eat=static'
141
- assert_equal('/bad_route',
142
- @error_collector.errors[0].params[:request_uri])
143
- assert_equal({'eat' => 'static'},
144
- @error_collector.errors[0].params[:request_params])
141
+ assert_equal('/bad_route', last_error.params[:request_uri])
142
+ assert_equal({'eat' => 'static'}, last_error.params[:request_params])
145
143
  end
146
144
 
147
145
  def test_should_not_notice_errors_from_ignored_action
@@ -184,16 +182,9 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
184
182
  protected
185
183
 
186
184
  def assert_errors_reported(message, queued_count, total_count=queued_count, txn_name=nil)
187
- error_count = NewRelic::Agent::Agent.instance.stats_engine.lookup_stats("Errors/all")
188
- assert_equal(total_count, error_count.call_count,
189
- 'Incorrect call count on Errors/all')
190
-
191
- if txn_name
192
- error_count = NewRelic::Agent::Agent.instance.stats_engine \
193
- .lookup_stats("Errors/#{txn_name}")
194
- assert_equal(total_count, error_count.call_count,
195
- "Incorrect call count on Errors/#{txn_name}")
196
- end
185
+ expected = { :call_count => total_count }
186
+ assert_metrics_recorded("Errors/all" => expected)
187
+ assert_metrics_recorded("Errors/#{txn_name}" => expected) if txn_name
197
188
 
198
189
  assert_equal(queued_count,
199
190
  @error_collector.errors.select{|error| error.message == message}.size,
@@ -206,7 +197,7 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
206
197
  end
207
198
 
208
199
  class ErrorsWithSSCTest < ErrorsWithoutSSCTest
209
- def setup_collector
200
+ def setup_collector_mocks
210
201
  $collector.mock['connect'] = [200, {'return_value' => {
211
202
  "listen_to_server_config" => true,
212
203
  "agent_run_id" => 1,
@@ -3,6 +3,7 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require './app'
6
+ require 'multiverse_helpers'
6
7
 
7
8
  # GC instrumentation only works with REE or 1.9.x
8
9
  if (defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise/) ||
@@ -23,17 +24,12 @@ end
23
24
 
24
25
  class GCRailsInstrumentationTest < ActionController::TestCase
25
26
  tests GcController
26
- def setup
27
- enable_gc_stats
28
27
 
29
- @controller = GcController.new
30
- NewRelic::Agent.instance.stats_engine.reset_stats
31
- NewRelic::Agent.instance.transaction_sampler.instance_variable_set(:@samples, [])
32
- NewRelic::Agent.manual_start
33
- end
28
+ include MultiverseHelpers
34
29
 
35
- def teardown
36
- NewRelic::Agent.shutdown
30
+ setup_and_teardown_agent do
31
+ enable_gc_stats
32
+ @controller = GcController.new
37
33
  end
38
34
 
39
35
  def test_records_accurate_time_for_gc_activity
@@ -56,13 +52,7 @@ class GCRailsInstrumentationTest < ActionController::TestCase
56
52
 
57
53
  def assert_in_range(duration, gc_time)
58
54
  assert gc_time > 0.0, "GC Time wasn't recorded!"
59
-
60
- # This is a guess for a reasonable threshold here.
61
- # Since these are timing based, we can revise or ditch as evidence ditacts
62
- # One CI failure we saw at least had duration=0.314 and gc_time=0.088
63
- ratio = gc_time / duration
64
- assert(ratio > 0.1 && ratio < 1.0,
65
- "Problem with GC/duration ratio. #{gc_time}/#{duration} = #{ratio} not between 0.1 and 1.0")
55
+ assert gc_time < duration, "GC Time can't be more than elapsed!"
66
56
  end
67
57
 
68
58
  def get_call_time(name, scope=nil)
@@ -6,6 +6,7 @@
6
6
 
7
7
  require 'rails/test_help'
8
8
  require './app'
9
+ require 'multiverse_helpers'
9
10
 
10
11
  class QueueController < ApplicationController
11
12
  include Rails.application.routes.url_helpers
@@ -18,32 +19,15 @@ class QueueController < ApplicationController
18
19
  end
19
20
 
20
21
  class QueueTimeTest < ActionDispatch::IntegrationTest
21
- def setup
22
- NewRelic::Agent.config.apply_config({
23
- :beacon => "beacon",
24
- :browser_key => "key"})
25
22
 
26
- @agent = NewRelic::Agent::Agent.new
27
- NewRelic::Agent::Agent.instance_variable_set(:@instance, @agent)
28
- NewRelic::Agent.manual_start
23
+ include MultiverseHelpers
29
24
 
30
- # ActiveSupport testing keeps blowing away my subscribers on
31
- # teardown for some reason. Have to keep putting it back.
32
- NewRelic::Agent.instance.events.subscribe(:before_call) do |env|
33
- NewRelic::Agent::TransactionInfo.reset(::Rack::Request.new(env))
34
- end
35
-
36
- @agent.finish_setup({})
37
- end
38
-
39
- def teardown
40
- NewRelic::Agent::Agent.instance.shutdown if NewRelic::Agent::Agent.instance
41
- end
25
+ setup_and_teardown_agent(:beacon => "beacon", :browser_key => "key")
42
26
 
43
27
  def test_should_track_queue_time_metric
44
28
  get_queued
45
29
 
46
- stat = @agent.stats_engine.lookup_stats('WebFrontend/QueueTime')
30
+ stat = agent.stats_engine.lookup_stats('WebFrontend/QueueTime')
47
31
  assert_equal 1, stat.call_count
48
32
  assert stat.total_call_time > 0, "Should track some queue time"
49
33
  end
@@ -6,6 +6,7 @@
6
6
 
7
7
  require 'rails/test_help'
8
8
  require './app'
9
+ require 'multiverse_helpers'
9
10
  require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
10
11
 
11
12
  class RequestStatsController < ApplicationController
@@ -21,24 +22,8 @@ class RequestStatsTest < ActionController::TestCase
21
22
  tests RequestStatsController
22
23
  extend Multiverse::Color
23
24
 
24
- def setup
25
- $collector ||= NewRelic::FakeCollector.new
26
- $collector.reset
27
- setup_collector
28
- $collector.run
29
-
30
- NewRelic::Agent.reset_config
31
- NewRelic::Agent.instance_variable_set(:@agent, nil)
32
- NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
33
- NewRelic::Agent.manual_start
34
- NewRelic::Agent::TransactionInfo.reset
35
- end
36
-
37
- def teardown
38
- NewRelic::Agent::Agent.instance.shutdown if NewRelic::Agent::Agent.instance
39
- NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
40
- end
41
-
25
+ include MultiverseHelpers
26
+ setup_and_teardown_agent
42
27
 
43
28
  #
44
29
  # Tests
@@ -46,7 +31,7 @@ class RequestStatsTest < ActionController::TestCase
46
31
 
47
32
  def test_doesnt_send_when_disabled
48
33
  with_config( :'request_sampler.enabled' => false ) do
49
- 200.times { get :stats_action }
34
+ 20.times { get :stats_action }
50
35
 
51
36
  NewRelic::Agent.agent.send(:harvest_and_send_analytic_event_data)
52
37
 
@@ -56,13 +41,13 @@ class RequestStatsTest < ActionController::TestCase
56
41
 
57
42
  def test_request_times_should_be_reported_if_enabled
58
43
  with_config( :'request_sampler.enabled' => true ) do
59
- 200.times { get :stats_action }
44
+ 20.times { get :stats_action }
60
45
 
61
46
  NewRelic::Agent.agent.send(:harvest_and_send_analytic_event_data)
62
47
 
63
48
  post = $collector.calls_for('analytic_event_data').first
64
49
 
65
- assert_not_nil( post )
50
+ refute_nil( post )
66
51
  assert_kind_of Array, post.body
67
52
  assert_kind_of Array, post.body.first
68
53
 
@@ -73,7 +58,7 @@ class RequestStatsTest < ActionController::TestCase
73
58
  assert_encoding 'utf-8', sample['name']
74
59
  assert_equal 'Transaction', sample['type']
75
60
  assert_kind_of Float, sample['duration']
76
- assert_valid_time sample['timestamp']
61
+ assert_kind_of Float, sample['timestamp']
77
62
  end
78
63
  end
79
64
 
@@ -83,10 +68,6 @@ class RequestStatsTest < ActionController::TestCase
83
68
  # Helpers
84
69
  #
85
70
 
86
- def setup_collector
87
- $collector.mock['connect'] = [200, {'return_value' => {"agent_run_id" => 666 }}]
88
- end
89
-
90
71
  def assert_encoding( encname, string )
91
72
  return unless string.respond_to?( :encoding )
92
73
  expected_encoding = Encoding.find( encname ) or raise "no such encoding #{encname.dump}"
@@ -95,10 +76,4 @@ class RequestStatsTest < ActionController::TestCase
95
76
  assert_equal( expected_encoding, string.encoding, msg )
96
77
  end
97
78
 
98
- def assert_valid_time( object )
99
- return if object.is_a?( Time )
100
- assert_kind_of Time, Time.parse(object.to_s) rescue object
101
- end
102
-
103
79
  end
104
-
@@ -3,6 +3,8 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require './app'
6
+ require 'rails/test_help'
7
+ require 'multiverse_helpers'
6
8
 
7
9
  ActionController::Base.view_paths = ['app/views']
8
10
 
@@ -77,9 +79,9 @@ end
77
79
 
78
80
  class ViewControllerTest < ActionController::TestCase
79
81
  tests ViewsController
80
- def setup
81
- super
82
- NewRelic::Agent.manual_start
82
+
83
+ include MultiverseHelpers
84
+ setup_and_teardown_agent do
83
85
  @controller = ViewsController.new
84
86
  # ActiveSupport testing keeps blowing away my subscribers on
85
87
  # teardown for some reason. Have to keep putting it back.
@@ -90,12 +92,6 @@ class ViewControllerTest < ActionController::TestCase
90
92
  .subscribe(/^process_action.action_controller$/)
91
93
  end
92
94
  end
93
-
94
- def teardown
95
- super
96
- request_sampler = NewRelic::Agent.instance.instance_variable_get(:@request_sampler)
97
- request_sampler.reset unless request_sampler.nil?
98
- end
99
95
  end
100
96
 
101
97
  # SANITY TESTS - Make sure nothing raises errors,
@@ -115,7 +111,7 @@ class SanityTest < ViewControllerTest
115
111
  end
116
112
 
117
113
  test "should allow an uncaught exception to propogate" do
118
- assert_raise RuntimeError do
114
+ assert_raises RuntimeError do
119
115
  get :raise_render
120
116
  end
121
117
  end
@@ -10,13 +10,11 @@ development:
10
10
  developer_mode: false
11
11
  app_name: test
12
12
  host: 127.0.0.1
13
+ port: <%= $collector && $collector.port %>
13
14
  api_host: 127.0.0.1
14
- port: <%= (30_000 + ($$ % 10_000)) %>
15
15
  transaction_tracer:
16
16
  record_sql: obfuscated
17
17
  enabled: true
18
18
  stack_trace_threshold: 0.5
19
19
  transaction_threshold: 1.0
20
20
  capture_params: false
21
- log_level: debug
22
- log_file_path: agent.log
@@ -5,12 +5,16 @@
5
5
  # https://newrelic.atlassian.net/browse/RUBY-669
6
6
 
7
7
  require 'resque'
8
- require 'test/unit'
9
8
  require 'logger'
10
9
  require 'newrelic_rpm'
11
10
  require 'fake_collector'
11
+ require 'multiverse_helpers'
12
+
13
+ class ResqueTest < MiniTest::Unit::TestCase
14
+ include MultiverseHelpers
15
+
16
+ setup_and_teardown_agent
12
17
 
13
- class ResqueTest < Test::Unit::TestCase
14
18
  class JobForTesting
15
19
  @queue = :resque_test
16
20
  @count = 0
@@ -31,11 +35,7 @@ class ResqueTest < Test::Unit::TestCase
31
35
 
32
36
  JOB_COUNT = 5
33
37
 
34
- def setup
35
- $collector ||= NewRelic::FakeCollector.new
36
- $collector.reset
37
- $collector.run
38
-
38
+ def run_jobs
39
39
  JobForTesting.reset_counter
40
40
 
41
41
  # From multiverse, we only run the Resque jobs inline to check that we
@@ -51,15 +51,18 @@ class ResqueTest < Test::Unit::TestCase
51
51
  end
52
52
 
53
53
  def test_all_jobs_ran
54
+ run_jobs
54
55
  assert_equal(JOB_COUNT, JobForTesting.count)
55
56
  end
56
57
 
57
58
  def test_agent_posts_correct_metric_data
59
+ run_jobs
58
60
  assert_metric_and_call_count('Instance/Busy', 1)
59
61
  assert_metric_and_call_count('OtherTransaction/ResqueJob/all', JOB_COUNT)
60
62
  end
61
63
 
62
64
  def test_agent_still_running_after_inline_job
65
+ run_jobs
63
66
  assert NewRelic::Agent.instance.started?
64
67
  end
65
68