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
@@ -76,6 +76,24 @@ class NewRelic::MetricSpecTest < Test::Unit::TestCase
76
76
  assert_equal("b" * 255, spec.scope, "should have shortened the scope")
77
77
  end
78
78
 
79
+ def test_invalid_name_setting_nil
80
+ NewRelic::Agent.instance.error_collector.errors.clear
81
+
82
+ spec = NewRelic::MetricSpec.new
83
+ spec.scope = nil
84
+
85
+ assert_has_error(NewRelic::MetricSpec::InvalidScopeSettingError)
86
+ end
87
+
88
+ def test_invalid_name_setting_false
89
+ NewRelic::Agent.instance.error_collector.errors.clear
90
+
91
+ spec = NewRelic::MetricSpec.new
92
+ spec.scope = false
93
+
94
+ assert_has_error(NewRelic::MetricSpec::InvalidScopeSettingError)
95
+ end
96
+
79
97
  private
80
98
 
81
99
  def compare_spec(spec, import)
@@ -0,0 +1,164 @@
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
+ module MultiverseHelpers
6
+
7
+ #
8
+ # Agent startup/shutdown
9
+ #
10
+ # These are considered to be the standard steps for each test to take.
11
+ # If your tests do something different, it's important that they clean up
12
+ # after themselves!
13
+
14
+ def self.included(base)
15
+ base.extend(self)
16
+ end
17
+
18
+ def agent
19
+ NewRelic::Agent.instance
20
+ end
21
+
22
+ def setup_and_teardown_agent(opts = {}, &block)
23
+ define_method(:setup) do
24
+ before_setup if respond_to?(:before_setup)
25
+ setup_agent(opts, &block)
26
+ after_setup if respond_to?(:after_setup)
27
+ end
28
+
29
+ define_method(:teardown) do
30
+ before_teardown if respond_to?(:before_teardown)
31
+ teardown_agent
32
+ after_teardown if respond_to?(:after_teardown)
33
+ end
34
+ end
35
+
36
+ def setup_agent(opts = {}, &block)
37
+ setup_collector
38
+ make_sure_agent_reconnects(opts)
39
+
40
+ # Give caller a shot to setup before we start
41
+ # Don't just yield, as that won't necessary have the intended receiver
42
+ # (the test case instance itself)
43
+ self.instance_exec($collector, &block) if block_given? && self.respond_to?(:instance_exec)
44
+
45
+ NewRelic::Agent.manual_start(opts)
46
+ end
47
+
48
+ def teardown_agent
49
+ reset_collector
50
+
51
+ # Put the configs back where they belong....
52
+ NewRelic::Agent.config.reset_to_defaults
53
+
54
+ # Renaming rules don't get cleared on connect--only appended to
55
+ NewRelic::Agent.instance.transaction_rules.rules.clear
56
+ NewRelic::Agent.instance.metric_rules.rules.clear
57
+
58
+ # Clear out lingering stats we didn't transmit
59
+ NewRelic::Agent.instance.reset_stats
60
+
61
+ # Clear out lingering errors in the collector
62
+ NewRelic::Agent.instance.error_collector.harvest_errors(nil)
63
+ NewRelic::Agent.instance.error_collector.instance_variable_set(:@ignore_filter, nil)
64
+
65
+ # Clear out the request sampler!
66
+ NewRelic::Agent.instance.instance_variable_get(:@request_sampler).reset
67
+
68
+ # Clean up any thread-local variables starting with 'newrelic'
69
+ Thread.current.keys.select { |k| k.to_s =~ /^newrelic/i }.each do |key|
70
+ Thread.current[key] = nil
71
+ end
72
+
73
+ NewRelic::Agent.shutdown
74
+ end
75
+
76
+ def run_agent(options={}, &block)
77
+ setup_agent(options)
78
+ yield if block_given?
79
+ teardown_agent
80
+ end
81
+
82
+ def make_sure_agent_reconnects(opts)
83
+ # Clean-up if others don't (or we're first test after auto-loading of agent)
84
+ if NewRelic::Agent.instance.started?
85
+ NewRelic::Agent.shutdown
86
+ NewRelic::Agent.logger.warn("TESTING: Agent wasn't shut down before test")
87
+ end
88
+
89
+ # This will force a reconnect when we start again
90
+ NewRelic::Agent.instance.instance_variable_set(:@connect_state, :pending)
91
+
92
+ # Almost always want a test to force a new connect when setting up
93
+ default_options(opts,
94
+ :sync_startup => true,
95
+ :force_reconnect => true)
96
+ end
97
+
98
+ def default_options(options, defaults={})
99
+ defaults.each do |(k, v)|
100
+ options.merge!({k => v}) unless options.key?(k)
101
+ end
102
+ end
103
+
104
+ #
105
+ # Collector interactions
106
+ #
107
+ # These are here to ease interactions with the fake collector, and allow
108
+ # classes that don't need them to avoid it by an environment variable.
109
+ # This helps so the runner process can decide before spawning the child
110
+ # whether we want the collector running or not.
111
+
112
+ def setup_collector
113
+ return if omit_collector?
114
+
115
+ require 'fake_collector'
116
+ $collector ||= NewRelic::FakeCollector.new
117
+ $collector.reset
118
+ $collector.run
119
+
120
+ if (NewRelic::Agent.instance &&
121
+ NewRelic::Agent.instance.service &&
122
+ NewRelic::Agent.instance.service.collector)
123
+ NewRelic::Agent.instance.service.collector.port = $collector.port
124
+ end
125
+ end
126
+
127
+ def reset_collector
128
+ return if omit_collector?
129
+ $collector.reset
130
+ end
131
+
132
+ def omit_collector?
133
+ ENV["NEWRELIC_OMIT_FAKE_COLLECTOR"] == "true"
134
+ end
135
+
136
+ extend self
137
+ end
138
+
139
+ if RUBY_VERSION < "1.8.7"
140
+ # No instance_exec in 1.8.6... sigh
141
+ #
142
+ # Cribbed from https://www.ruby-forum.com/topic/72172#101957, most straight
143
+ # forward implementation I could find without using ActiveSupport
144
+ class Object
145
+ unless defined? instance_exec # 1.9
146
+ def instance_exec(*arguments, &block)
147
+ block.bind(self)[*arguments]
148
+ end
149
+ end
150
+ end
151
+
152
+ class Proc
153
+ def bind(object)
154
+ block, time = self, Time.now
155
+ (class << object; self end).class_eval do
156
+ method_name = "__bind_#{time.to_i}_#{time.usec}"
157
+ define_method(method_name, &block)
158
+ method = instance_method(method_name)
159
+ remove_method(method_name)
160
+ method
161
+ end.bind(object)
162
+ end
163
+ end
164
+ end
@@ -38,4 +38,3 @@ class AgentHooksTest < Test::Unit::TestCase
38
38
  end
39
39
 
40
40
  end
41
-
@@ -12,4 +12,3 @@ class NewRelic::Rack::AllTest < Test::Unit::TestCase
12
12
  assert true
13
13
  end
14
14
  end
15
-
@@ -0,0 +1,35 @@
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 File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
+
7
+ class NewRelic::Rack::DeferredInstrumentationTest < Test::Unit::TestCase
8
+ class TestApp
9
+ def call(env)
10
+ [200, {}, ["whatever"]]
11
+ end
12
+ end
13
+
14
+ def test_to_app_does_not_blow_up_when_rack_instrumentation_required_multiple_times
15
+ # We want to use two different paths to require the rack instrumentation here
16
+ # in order to simulate a situation that might arise where a user is
17
+ # explicitly requiring our rack instrumentation file, and then the agent
18
+ # automatically requires it as well, via a different path.
19
+ # On Ruby 1.8.7, this will cause the file to be evaluated multiple times.
20
+ path1 = "new_relic/agent/instrumentation/rack"
21
+ path2 = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'new_relic', 'agent', 'instrumentation', 'rack'))
22
+ assert_not_equal(path2, path1)
23
+
24
+ require path1
25
+ require path2
26
+
27
+ builder = ::Rack::Builder.new do
28
+ run(::NewRelic::Rack::DeferredInstrumentationTest::TestApp.new)
29
+ end
30
+
31
+ assert_nothing_raised do
32
+ builder.to_app
33
+ end
34
+ end
35
+ end
@@ -2,7 +2,6 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- # ENV['SKIP_RAILS'] = 'true'
6
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..', '..',
7
6
  'test_helper'))
8
7
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','ui',
@@ -11,8 +10,8 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','ui',
11
10
  ENV['RACK_ENV'] = 'test'
12
11
  class DeveloperModeTest < Test::Unit::TestCase
13
12
  include NewRelic::DeveloperModeHelper
14
-
15
-
13
+
14
+
16
15
  def test_application_caller
17
16
  assert_equal "/opt/ruby/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'", application_caller(Fixtures::NORMAL_TRACE)
18
17
  assert_equal "c:/Ruby192/lib/ruby/1.9.1/erb.rb:753:in `eval'", application_caller(Fixtures::WINDOWS_TRACE)
@@ -23,16 +22,16 @@ class DeveloperModeTest < Test::Unit::TestCase
23
22
  assert_equal 29, trace.size
24
23
  trace = application_stack_trace(Fixtures::WINDOWS_TRACE)
25
24
  assert_equal 14, trace.size
26
-
25
+
27
26
  end
28
-
27
+
29
28
  def test_url_for_source
30
29
  for line in Fixtures::NORMAL_TRACE + Fixtures::WINDOWS_TRACE do
31
30
  line = url_for_source(line)
32
31
  assert line =~ /^show_source\?file=.*&amp;line=\d+&amp;/, line
33
32
  end
34
33
  end
35
-
34
+
36
35
  private
37
36
  def params; {} end
38
37
  module Fixtures
@@ -105,9 +104,9 @@ rack (1.2.3) lib/rack/content_length.rb:13:in `call'
105
104
  rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
106
105
  c:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
107
106
  c:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
108
- c:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
107
+ c:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
109
108
  EOF
110
-
109
+
111
110
  NORMAL_TRACE = <<-EOF.split("\n")
112
111
  /opt/ruby/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
113
112
  /opt/ruby/lib/ruby/1.8/timeout.rb:101:in `timeout'
@@ -141,5 +140,5 @@ c:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
141
140
  /Users/joe/dev/workspace/config/initializers/delayed_job_with_shards.rb:17:in `perform'
142
141
  /opt/ruby/gems/delayed_job-2.0.6/lib/delayed/backend/base.rb:74:in `invoke_job'
143
142
  EOF
144
- end
143
+ end
145
144
  end
@@ -2,8 +2,6 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- # ENV['SKIP_RAILS'] = 'true'
6
-
7
5
  if defined?(::Rails)
8
6
 
9
7
  require File.expand_path(File.join(File.dirname(__FILE__),'..', '..',
@@ -45,8 +45,7 @@ module NewRelic::Rack
45
45
  get '/'
46
46
  end
47
47
 
48
- assert_equal('unhandled error',
49
- NewRelic::Agent.instance.error_collector.errors[0].message)
48
+ assert_equal('unhandled error', last_error.message)
50
49
  end
51
50
 
52
51
  def test_ignore_filtered_errors
@@ -76,20 +75,65 @@ module NewRelic::Rack
76
75
  end
77
76
 
78
77
  def test_handles_parameter_parsing_exceptions
79
- bad_request = stub(:env => {}, :path => '/', :referer => '')
80
- bad_request.stubs(:params).raises(TypeError, "can't convert nil into Hash")
81
- Rack::Request.stubs(:new).returns(bad_request)
78
+ if defined?(ActionDispatch::Request)
79
+ bad_request = stub.stubs(:filtered_params).raises(TypeError, "can't convert nil into Hash")
80
+ ActionDispatch::Request.stubs(:new).returns(bad_request)
81
+ else
82
+ bad_request = stub(:env => {}, :path => '/', :referer => '')
83
+ bad_request.stubs(:params).raises(TypeError, "whatever, man")
84
+ Rack::Request.stubs(:new).returns(bad_request)
85
+ end
82
86
 
83
87
  assert_raise RuntimeError do
84
88
  get '/'
85
89
  end
86
90
 
87
- assert_equal('unhandled error',
88
- NewRelic::Agent.instance.error_collector.errors[0].message)
91
+ assert_equal('unhandled error', last_error.message)
89
92
  assert_match(/failed to capture request parameters/i,
90
- NewRelic::Agent.instance.error_collector.errors[0].params[:request_params]['error'])
93
+ last_error.params[:request_params]['error'])
94
+ end
95
+
96
+ # Ideally we'd test this for failures to create Rack::Request as well,
97
+ # but unfortunately rack-test, which we're using to drive, creates
98
+ # Rack::Request objects internally, so there's not an easy way to.
99
+ def test_handles_failure_to_create_request_object
100
+ if defined?(ActionDispatch::Request)
101
+ ActionDispatch::Request.stubs(:new).raises('bad news')
102
+
103
+ assert_raise RuntimeError do
104
+ get '/foo/bar?q=12'
105
+ end
106
+
107
+ assert_equal('unhandled error', last_error.message)
108
+ assert_equal('/foo/bar', last_error.params[:request_uri])
109
+ end
110
+ end
111
+
112
+ def test_captures_parameters_with_rails
113
+ assert_raise RuntimeError do
114
+ get '/?foo=bar&baz=qux'
115
+ end
116
+
117
+ expected_params = { 'foo' => 'bar', 'baz' => 'qux' }
118
+ assert_equal('unhandled error', last_error.message)
119
+ assert_equal(expected_params, last_error.params[:request_params])
120
+ end
121
+
122
+ def test_captures_parameters_without_rails
123
+ undefine_constant(:'ActionDispatch::Request') do
124
+ assert_raise RuntimeError do
125
+ get '/?foo=bar&baz=qux'
126
+ end
127
+ end
128
+
129
+ expected_params = { 'foo' => 'bar', 'baz' => 'qux' }
130
+ assert_equal('unhandled error', last_error.message)
131
+ assert_equal(expected_params, last_error.params[:request_params])
91
132
  end
92
133
 
134
+ def last_error
135
+ NewRelic::Agent.instance.error_collector.errors[0]
136
+ end
93
137
  end
94
138
  end
95
139
 
@@ -36,4 +36,3 @@ class NewRelic::TransactionSample::CompositeSegmentTest < Test::Unit::TestCase
36
36
  segment
37
37
  end
38
38
  end
39
-
@@ -18,4 +18,3 @@ class NewRelic::TransactionSample::FakeSegmentTest < Test::Unit::TestCase
18
18
  assert_equal('foo', s.instance_eval { @parent_segment } )
19
19
  end
20
20
  end
21
-
@@ -377,4 +377,3 @@ class NewRelic::TransactionSample::SegmentTest < Test::Unit::TestCase
377
377
  assert_equal(fake_segment, s.parent_segment)
378
378
  end
379
379
  end
380
-
@@ -32,4 +32,3 @@ class NewRelic::TransactionSample::SummarySegmentTest < Test::Unit::TestCase
32
32
  segment
33
33
  end
34
34
  end
35
-
@@ -0,0 +1,162 @@
1
+ # Ruby Agent Performance Tests
2
+
3
+ This is a performance testing framework for the Ruby Agent.
4
+
5
+ ## Motivation
6
+
7
+ There are two main goals driving the development of this framework:
8
+
9
+ 1. Add a way for automated performance tests to be run against the Ruby Agent
10
+ and ingested into a system for tracking these results over time.
11
+ 2. Provide a tool for Ruby Agent engineers to use while working on performance
12
+ improvements.
13
+
14
+ ## Examples
15
+
16
+ ### Invoking via rake task
17
+
18
+ Basic performance test invocations can be done using a rake task provided in the
19
+ newrelic_rpm Rakefile.
20
+
21
+ Run all performance tests, reporting results to the console:
22
+
23
+ ```
24
+ $ rake test:performance
25
+ ```
26
+
27
+ Run one specific suite:
28
+
29
+ ```
30
+ $ rake test:performance[TransactionTracingPerfTests]
31
+ ```
32
+
33
+ Run one specif suite and test (test name matching is via regex):
34
+
35
+ ```
36
+ $ rake test:performance[TransactionTracingPerfTests,test_short_transactions]
37
+ ```
38
+
39
+ ### Invoking via the runner directly
40
+
41
+ More advanced options can be specified by invoking the runner script directly.
42
+ See `test/performance/script/runner -h` for a full list of options.
43
+
44
+ Run all tests, report detailed results in a human-readable form
45
+
46
+ ```
47
+ $ ./test/performance/script/runner
48
+ ```
49
+
50
+ Run a specific test (test name matching is via regex):
51
+
52
+ ```
53
+ $ ./test/performance/script/runner -n short
54
+ ```
55
+
56
+ Run all the tests, brief output (just timings):
57
+
58
+ ```
59
+ $ ./test/performance/script/runner -b
60
+ ```
61
+
62
+ Run all the tests, produce machine readable JSON output (for eventual ingestion into a storage system):
63
+
64
+ ```
65
+ $ ./test/performance/script/runner -j | json_reformat
66
+ ```
67
+
68
+ Run a specific test using the perftools.rb CPU profiler, producing a call-graph style dot file:
69
+
70
+ ```
71
+ $ ./test/performance/script/runner -n short -i PerfToolsProfile
72
+ ```
73
+
74
+ Run with fewer iterations, and do object allocation profiling (again to a call-graph dot file):
75
+
76
+ ```
77
+ $ CPUPROFILE_OBJECTS=1 ./test/performance/script/runner -n short -i PerfToolsProfile -N 1000
78
+ ```
79
+
80
+ ## Pointing at a different copy of the agent
81
+
82
+ If you want to run performance tests against an older copy of the agent that
83
+ doesn't have the performance test framework embedded within it, you can do that
84
+ by specifying the path to the agent you want to test against by passing the `-A`
85
+ flag to the `runner` script, or by setting the `AGENT_PATH` environment variable
86
+ when using the rake task.
87
+
88
+ ## Sending results to Hako
89
+
90
+ This is currently considered experimental, but you can send results
91
+ automatically to Hako by passing `-R HakoReporter` on the command line to the
92
+ `runner`. This will produce JSON-formatted versions of each test result, and
93
+ submit them to Hako. You will need to set the `HAKO_TOKEN` environment variable
94
+ to a valid Hako access token when doing this.
95
+
96
+ ## Writing tests
97
+
98
+ Performance tests are written in the style of `test/unit`: create a `.rb` file
99
+ under `test/performance/suites`, subclass `Performance::TestCase`, and write
100
+ test methods that start with `test_`. You can also write `setup` and `teardown`
101
+ methods that will be run before/after each test.
102
+
103
+ Generally in your test, you'll want to do some operation N times (where N is
104
+ large). You should base your N on the return value of
105
+ `Performance::TestCase#iterations`, which is controlled by the `-N` command-line
106
+ flag to `runner`. You may scale this value linearly as appropriate for your test
107
+ if need be, but the idea is to have a single knob to turn that will change the
108
+ iteration count for all tests.
109
+
110
+ The invocation of each `test_*` method will be timed, so any setup / teardown
111
+ you need for your test that you don't want included in the timing should be
112
+ confined to the `setup` and `teardown` methods.
113
+
114
+ ## Test Isolation
115
+
116
+ Initial testing suggested that certain kinds of tests would have a large impact
117
+ on tests run later on in the same process (e.g. tests that create lots of
118
+ long-lived objects will slow down all future GC runs for as long as those
119
+ objects remain live).
120
+
121
+ In order to address this problem, the test runner will attempt to isolate each
122
+ test to its own process by re-spawning itself for each test invocation. This is
123
+ done using `IO.popen` rather than `Process.fork` in order to maintain
124
+ compatibility with JRuby.
125
+
126
+ Additionally, when operating in this mode, the `newrelic_rpm` gem will not be
127
+ loaded until *after* the fork call. This means that your **test cases must be
128
+ loadable (though not necessarily runnable) without the `newrelic_rpm` gem
129
+ avaiable**.
130
+
131
+ Not all command-line options to the runner work with this test isolation yet.
132
+ You can disable it by passing the `-I/--inline` flag to the runner.
133
+
134
+ ## Adding instrumentation layers
135
+
136
+ The GC stats that are collected with each test run, and the perftools.rb
137
+ profiling are examples of Instrumentors which can be wrapped around each test run.
138
+
139
+ The basic idea is that each instrumentor gets callbacks before and after each
140
+ test, and add information to the test results, or attach artifacts (a fancy name
141
+ for file paths, currently) to the result.
142
+
143
+ Instrumentors inherit from `Performance::Instrumentation::Instrumentor`, and may
144
+ constrain themselves to running only on certain platforms (see `instrumentor.rb`
145
+ for a list) by calling the `platforms` method in their class definitions. They
146
+ may also signal that they should be used by default by calling `on_by_default`.
147
+ They should imlement the `before`, `after` and `results` methods as follows:
148
+
149
+ The `before` method is called before each test is run. The test class and test
150
+ name are passed as arguments.
151
+
152
+ The `after` method is called after each test is run. The test class, and test
153
+ name are passed as arguments. Artifacts may be attached to the result here by
154
+ appending to the `@artifacts` array. You may obtain paths to store artifacts at
155
+ by calling `Performance::Instrumentation::Instrumentor#artifact_path` (see
156
+ perf_tools.rb for an example).
157
+
158
+ The `results` method must return a Hash of key-value pairs to be attached to the
159
+ `Result` object produced by running each test.
160
+
161
+ If your instrumentation layer needs to do one-time setup (requiring a gem, for
162
+ example), implement the `setup` class method to do this setup.