newrelic_rpm 3.6.6.147 → 3.6.7.152

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +0 -1
  3. data/CHANGELOG +55 -17
  4. data/Guardfile +7 -0
  5. data/Rakefile +6 -0
  6. data/bin/mongrel_rpm +33 -0
  7. data/bin/newrelic +13 -0
  8. data/bin/newrelic_cmd +5 -0
  9. data/bin/nrdebug +273 -0
  10. data/install.rb +3 -3
  11. data/lib/new_relic/agent.rb +4 -6
  12. data/lib/new_relic/agent/agent.rb +76 -72
  13. data/lib/new_relic/agent/autostart.rb +18 -5
  14. data/lib/new_relic/agent/browser_monitoring.rb +41 -35
  15. data/lib/new_relic/agent/browser_token.rb +38 -0
  16. data/lib/new_relic/agent/busy_calculator.rb +7 -5
  17. data/lib/new_relic/agent/commands/agent_command.rb +19 -0
  18. data/lib/new_relic/agent/commands/agent_command_router.rb +88 -0
  19. data/lib/new_relic/agent/commands/thread_profiler.rb +80 -0
  20. data/lib/new_relic/agent/configuration/default_source.rb +700 -0
  21. data/lib/new_relic/agent/configuration/environment_source.rb +83 -30
  22. data/lib/new_relic/agent/configuration/manager.rb +8 -8
  23. data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
  24. data/lib/new_relic/agent/cross_app_monitor.rb +10 -21
  25. data/lib/new_relic/agent/cross_app_tracing.rb +3 -3
  26. data/lib/new_relic/agent/error_collector.rb +7 -10
  27. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
  28. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +5 -1
  29. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +5 -1
  30. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
  31. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -12
  33. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -0
  34. data/lib/new_relic/agent/instrumentation/{rails4/active_record.rb → active_record_4.rb} +1 -1
  35. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -11
  36. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -6
  37. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +12 -6
  38. data/lib/new_relic/agent/instrumentation/curb.rb +11 -2
  39. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -3
  40. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +11 -2
  41. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +13 -4
  42. data/lib/new_relic/agent/instrumentation/puma.rb +2 -1
  43. data/lib/new_relic/agent/instrumentation/rack.rb +15 -17
  44. data/lib/new_relic/agent/method_tracer.rb +181 -191
  45. data/lib/new_relic/agent/new_relic_service.rb +16 -14
  46. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  47. data/lib/new_relic/agent/request_sampler.rb +32 -165
  48. data/lib/new_relic/agent/sampled_buffer.rb +79 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -8
  50. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  51. data/lib/new_relic/agent/stats_engine.rb +1 -1
  52. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  53. data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -3
  54. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -22
  55. data/lib/new_relic/agent/threading/agent_thread.rb +41 -0
  56. data/lib/new_relic/agent/threading/backtrace_node.rb +71 -0
  57. data/lib/new_relic/agent/threading/thread_profile.rb +172 -0
  58. data/lib/new_relic/agent/transaction.rb +16 -4
  59. data/lib/new_relic/agent/transaction_sample_builder.rb +13 -3
  60. data/lib/new_relic/agent/transaction_sampler.rb +5 -8
  61. data/lib/new_relic/agent/transaction_state.rb +166 -0
  62. data/lib/new_relic/agent/transaction_timings.rb +53 -0
  63. data/lib/new_relic/cli/command.rb +91 -0
  64. data/lib/new_relic/{commands → cli}/deployments.rb +13 -9
  65. data/lib/new_relic/{commands → cli}/install.rb +2 -2
  66. data/lib/new_relic/control/frameworks/rails.rb +1 -8
  67. data/lib/new_relic/control/instance_methods.rb +1 -2
  68. data/lib/new_relic/helper.rb +9 -0
  69. data/lib/new_relic/local_environment.rb +16 -63
  70. data/lib/new_relic/rack/browser_monitoring.rb +8 -5
  71. data/lib/new_relic/recipes.rb +44 -31
  72. data/lib/new_relic/transaction_sample.rb +6 -2
  73. data/lib/new_relic/version.rb +1 -1
  74. data/lib/tasks/install.rake +21 -1
  75. data/newrelic_rpm.gemspec +5 -1
  76. data/test/agent_helper.rb +4 -9
  77. data/test/environments/.gitignore +16 -0
  78. data/test/environments/lib/environments/runner.rb +104 -0
  79. data/test/environments/norails/Gemfile +11 -0
  80. data/test/environments/norails/Rakefile +9 -0
  81. data/test/environments/rails21/Gemfile +24 -0
  82. data/test/environments/rails21/Rakefile +12 -0
  83. data/test/environments/rails21/app/controllers/application.rb +20 -0
  84. data/test/environments/rails21/config/boot.rb +113 -0
  85. data/test/environments/rails21/config/database.yml +31 -0
  86. data/test/environments/rails21/config/environment.rb +28 -0
  87. data/test/environments/rails21/config/environments/development.rb +16 -0
  88. data/test/environments/rails21/config/environments/production.rb +8 -0
  89. data/test/environments/rails21/config/environments/test.rb +10 -0
  90. data/test/environments/rails21/config/routes.rb +5 -0
  91. data/test/environments/rails21/db/schema.rb +5 -0
  92. data/test/environments/rails22/Gemfile +29 -0
  93. data/test/environments/rails22/Rakefile +12 -0
  94. data/test/environments/rails22/app/controllers/application.rb +20 -0
  95. data/test/environments/rails22/config/boot.rb +113 -0
  96. data/test/environments/rails22/config/database.yml +31 -0
  97. data/test/environments/rails22/config/environment.rb +27 -0
  98. data/test/environments/rails22/config/environments/development.rb +16 -0
  99. data/test/environments/rails22/config/environments/production.rb +8 -0
  100. data/test/environments/rails22/config/environments/test.rb +10 -0
  101. data/test/environments/rails22/config/routes.rb +5 -0
  102. data/test/environments/rails22/db/schema.rb +5 -0
  103. data/test/environments/rails23/Gemfile +22 -0
  104. data/test/environments/rails23/Rakefile +12 -0
  105. data/test/environments/rails23/app/controllers/application.rb +20 -0
  106. data/test/environments/rails23/config/boot.rb +127 -0
  107. data/test/environments/rails23/config/database.yml +31 -0
  108. data/test/environments/rails23/config/environment.rb +25 -0
  109. data/test/environments/rails23/config/environments/development.rb +16 -0
  110. data/test/environments/rails23/config/environments/production.rb +8 -0
  111. data/test/environments/rails23/config/environments/test.rb +10 -0
  112. data/test/environments/rails23/config/preinitializer.rb +25 -0
  113. data/test/environments/rails23/config/routes.rb +5 -0
  114. data/test/environments/rails23/db/schema.rb +5 -0
  115. data/test/environments/rails30/Gemfile +19 -0
  116. data/test/environments/rails30/Rakefile +9 -0
  117. data/test/environments/rails30/config/application.rb +17 -0
  118. data/test/environments/rails30/config/boot.rb +10 -0
  119. data/test/environments/rails30/config/database.yml +31 -0
  120. data/test/environments/rails30/config/environment.rb +6 -0
  121. data/test/environments/rails30/config/initializers/new_rails_defaults.rb +11 -0
  122. data/test/environments/rails30/db/schema.rb +5 -0
  123. data/test/environments/rails31/Gemfile +19 -0
  124. data/test/environments/rails31/Rakefile +9 -0
  125. data/test/environments/rails31/config/application.rb +18 -0
  126. data/test/environments/rails31/config/boot.rb +10 -0
  127. data/test/environments/rails31/config/database.yml +31 -0
  128. data/test/environments/rails31/config/environment.rb +6 -0
  129. data/test/environments/rails31/config/initializers/new_rails_defaults.rb +21 -0
  130. data/test/environments/rails31/db/schema.rb +5 -0
  131. data/test/environments/rails32/Gemfile +25 -0
  132. data/test/environments/rails32/Rakefile +9 -0
  133. data/test/environments/rails32/config/application.rb +19 -0
  134. data/test/environments/rails32/config/boot.rb +10 -0
  135. data/test/environments/rails32/config/database.yml +31 -0
  136. data/test/environments/rails32/config/environment.rb +6 -0
  137. data/test/environments/rails32/db/schema.rb +5 -0
  138. data/test/environments/rails40/Gemfile +25 -0
  139. data/test/environments/rails40/Rakefile +9 -0
  140. data/test/environments/rails40/config/application.rb +18 -0
  141. data/test/environments/rails40/config/boot.rb +10 -0
  142. data/test/environments/rails40/config/database.yml +31 -0
  143. data/test/environments/rails40/config/environment.rb +6 -0
  144. data/test/environments/rails40/db/schema.rb +5 -0
  145. data/test/multiverse/lib/multiverse/suite.rb +24 -12
  146. data/test/multiverse/suites/agent_only/logging_test.rb +18 -1
  147. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +1 -8
  148. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +10 -7
  149. data/test/multiverse/suites/curb/curb_test.rb +17 -3
  150. data/test/multiverse/suites/excon/Envfile +1 -1
  151. data/test/multiverse/suites/excon/excon_test.rb +18 -2
  152. data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
  153. data/test/multiverse/suites/net_http/net_http_test.rb +2 -2
  154. data/test/multiverse/suites/rails/error_tracing_test.rb +35 -8
  155. data/test/multiverse/suites/rails/ignore_test.rb +48 -0
  156. data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +44 -0
  157. data/test/multiverse/suites/sequel/sequel_test.rb +11 -0
  158. data/test/multiverse/suites/sinatra/ignoring_test.rb +2 -2
  159. data/test/multiverse/suites/typhoeus/Envfile +9 -2
  160. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -2
  161. data/test/new_relic/agent/agent/start_test.rb +3 -22
  162. data/test/new_relic/agent/agent_test.rb +6 -5
  163. data/test/new_relic/agent/autostart_test.rb +39 -1
  164. data/test/new_relic/agent/browser_monitoring_test.rb +43 -88
  165. data/test/new_relic/agent/browser_token_test.rb +52 -0
  166. data/test/new_relic/agent/busy_calculator_test.rb +1 -1
  167. data/test/new_relic/agent/commands/agent_command_router_test.rb +98 -0
  168. data/test/new_relic/agent/commands/agent_command_test.rb +37 -0
  169. data/test/new_relic/agent/commands/thread_profiler_test.rb +177 -0
  170. data/test/new_relic/agent/configuration/default_source_test.rb +81 -0
  171. data/test/new_relic/agent/configuration/environment_source_test.rb +81 -7
  172. data/test/new_relic/agent/configuration/manager_test.rb +16 -1
  173. data/test/new_relic/agent/cross_app_monitor_test.rb +3 -5
  174. data/test/new_relic/agent/error_collector_test.rb +14 -0
  175. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
  176. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +2 -3
  177. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +29 -31
  178. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +22 -0
  179. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +2 -2
  180. data/test/new_relic/agent/method_tracer_test.rb +2 -2
  181. data/test/new_relic/agent/new_relic_service_test.rb +5 -49
  182. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -0
  183. data/test/new_relic/agent/request_sampler_test.rb +32 -95
  184. data/test/new_relic/agent/rpm_agent_test.rb +7 -5
  185. data/test/new_relic/agent/sampled_buffer_test.rb +178 -0
  186. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +0 -1
  187. data/test/new_relic/agent/stats_engine_test.rb +10 -17
  188. data/test/new_relic/agent/threading/agent_thread_test.rb +107 -0
  189. data/test/new_relic/agent/threading/backtrace_node_test.rb +96 -0
  190. data/test/new_relic/agent/{threaded_test.rb → threading/fake_thread.rb} +0 -25
  191. data/test/new_relic/agent/threading/thread_profile_test.rb +308 -0
  192. data/test/new_relic/agent/threading/threaded_test_case.rb +33 -0
  193. data/test/new_relic/agent/transaction/pop_test.rb +0 -16
  194. data/test/new_relic/agent/transaction_sample_builder_test.rb +23 -4
  195. data/test/new_relic/agent/transaction_sampler_test.rb +14 -15
  196. data/test/new_relic/agent/transaction_state_test.rb +75 -0
  197. data/test/new_relic/agent/transaction_test.rb +15 -0
  198. data/test/new_relic/agent/transaction_timings_test.rb +81 -0
  199. data/test/new_relic/agent_test.rb +12 -14
  200. data/test/new_relic/{command → cli}/deployments_test.rb +41 -13
  201. data/test/new_relic/control/frameworks/rails_test.rb +1 -2
  202. data/test/new_relic/control_test.rb +1 -2
  203. data/test/new_relic/dependency_detection_test.rb +14 -0
  204. data/test/new_relic/fake_collector.rb +1 -0
  205. data/test/new_relic/helper_test.rb +7 -2
  206. data/test/new_relic/http_client_test_cases.rb +33 -1
  207. data/test/new_relic/local_environment_test.rb +0 -23
  208. data/test/new_relic/metric_data_test.rb +4 -0
  209. data/test/new_relic/rack/browser_monitoring_test.rb +31 -30
  210. data/test/performance/lib/performance/result.rb +15 -4
  211. data/test/performance/lib/performance/timer.rb +7 -1
  212. data/test/performance/script/baselines +102 -0
  213. data/test/performance/suites/rum_autoinsertion.rb +57 -0
  214. data/test/rum/basic.result.html +10 -0
  215. data/test/rum/basic.source.html +10 -0
  216. data/test/rum/comments1.result.html +24 -0
  217. data/test/rum/comments1.source.html +24 -0
  218. data/test/rum/comments2.result.html +24 -0
  219. data/test/rum/comments2.source.html +24 -0
  220. data/test/rum/gt_in_quotes1.result.html +27 -0
  221. data/test/rum/gt_in_quotes1.source.html +27 -0
  222. data/test/rum/gt_in_quotes2.result.html +24 -0
  223. data/test/rum/gt_in_quotes2.source.html +24 -0
  224. data/test/rum/gt_in_quotes_mismatch.result.html +24 -0
  225. data/test/rum/gt_in_quotes_mismatch.source.html +24 -0
  226. data/test/rum/gt_in_single_quotes1.result.html +25 -0
  227. data/test/rum/gt_in_single_quotes1.source.html +25 -0
  228. data/test/rum/gt_in_single_quotes_mismatch.result.html +25 -0
  229. data/test/rum/gt_in_single_quotes_mismatch.source.html +25 -0
  230. data/test/rum/incomplete_non_meta_tags.result.html +10 -0
  231. data/test/rum/incomplete_non_meta_tags.source.html +10 -0
  232. data/test/rum/no_body.result.html +21 -0
  233. data/test/rum/no_body.source.html +21 -0
  234. data/test/rum/no_header.result.html +7 -0
  235. data/test/rum/no_header.source.html +7 -0
  236. data/test/rum/no_start_header.result.html +9 -0
  237. data/test/rum/no_start_header.source.html +9 -0
  238. data/test/rum/script1.result.html +19 -0
  239. data/test/rum/script1.source.html +19 -0
  240. data/test/rum/script2.result.html +17 -0
  241. data/test/rum/script2.source.html +17 -0
  242. data/test/rum/x_ua_meta_tag.result.html +10 -0
  243. data/test/rum/x_ua_meta_tag.source.html +10 -0
  244. data/test/rum/x_ua_meta_tag_multiline.result.html +11 -0
  245. data/test/rum/x_ua_meta_tag_multiline.source.html +11 -0
  246. data/test/rum/x_ua_meta_tag_with_others.result.html +11 -0
  247. data/test/rum/x_ua_meta_tag_with_others.source.html +11 -0
  248. data/test/rum/x_ua_meta_tag_with_spaces.result.html +10 -0
  249. data/test/rum/x_ua_meta_tag_with_spaces.source.html +10 -0
  250. data/test/script/ci.sh +1 -12
  251. data/test/test_helper.rb +1 -0
  252. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +11 -0
  253. metadata +225 -32
  254. metadata.gz.sig +0 -0
  255. data/lib/new_relic/agent/configuration/defaults.rb +0 -157
  256. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +0 -56
  257. data/lib/new_relic/agent/thread.rb +0 -37
  258. data/lib/new_relic/agent/thread_profiler.rb +0 -323
  259. data/lib/new_relic/agent/transaction_info.rb +0 -114
  260. data/lib/new_relic/command.rb +0 -89
  261. data/test/new_relic/agent/agent_test_controller_test.rb +0 -348
  262. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +0 -70
  263. data/test/new_relic/agent/thread_profiler_test.rb +0 -586
  264. data/test/new_relic/agent/thread_test.rb +0 -93
  265. data/test/new_relic/agent/transaction_info_test.rb +0 -99
@@ -11,6 +11,7 @@ module NewRelic::Agent::Configuration
11
11
  def setup
12
12
  @original_env = {}
13
13
  @original_env.replace(ENV)
14
+ @environment_source = EnvironmentSource.new
14
15
  end
15
16
 
16
17
  def teardown
@@ -24,7 +25,10 @@ module NewRelic::Agent::Configuration
24
25
  assert_applied_string 'NEW_RELIC_APP_NAME', 'app_name'
25
26
  assert_applied_string 'NEWRELIC_APP_NAME', 'app_name'
26
27
  assert_applied_string 'NEW_RELIC_HOST', 'host'
27
- assert_applied_string 'NEW_RELIC_PORT', 'port'
28
+ end
29
+
30
+ def test_environment_fixnums_are_applied
31
+ assert_applied_fixnum 'NEW_RELIC_PORT', 'port'
28
32
  end
29
33
 
30
34
  def test_environment_symbols_are_applied
@@ -37,21 +41,21 @@ module NewRelic::Agent::Configuration
37
41
  %w| NEWRELIC_ENABLE NEWRELIC_ENABLED NEW_RELIC_ENABLE NEW_RELIC_ENABLED |.each do |var|
38
42
  define_method("test_environment_booleans_truths_are_applied_to_#{var}") do
39
43
  ENV[var] = 'true'
40
- assert EnvironmentSource.new[:agent_enabled]
44
+ assert EnvironmentSource.new[:enabled]
41
45
  ENV[var] = 'on'
42
- assert EnvironmentSource.new[:agent_enabled]
46
+ assert EnvironmentSource.new[:enabled]
43
47
  ENV[var] = 'yes'
44
- assert EnvironmentSource.new[:agent_enabled]
48
+ assert EnvironmentSource.new[:enabled]
45
49
  ENV.delete(var)
46
50
  end
47
51
 
48
52
  define_method("test_environment_booleans_falsehoods_are_applied_to_#{var}") do
49
53
  ENV[var] = 'false'
50
- assert !EnvironmentSource.new[:agent_enabled]
54
+ assert !EnvironmentSource.new[:enabled]
51
55
  ENV[var] = 'off'
52
- assert !EnvironmentSource.new[:agent_enabled]
56
+ assert !EnvironmentSource.new[:enabled]
53
57
  ENV[var] = 'no'
54
- assert !EnvironmentSource.new[:agent_enabled]
58
+ assert !EnvironmentSource.new[:enabled]
55
59
  ENV.delete(var)
56
60
  end
57
61
  end
@@ -92,6 +96,63 @@ module NewRelic::Agent::Configuration
92
96
  assert_equal 'STDOUT', source[:log_file_path]
93
97
  end
94
98
 
99
+ def test_set_values_from_new_relic_environment_variables
100
+ keys = %w(NEW_RELIC_LICENSE_KEY NEWRELIC_CONFIG_PATH)
101
+ keys.each { |key| ENV[key] = 'skywizards' }
102
+
103
+ expected_source = EnvironmentSource.new
104
+
105
+ [:license_key, :config_path].each do |key|
106
+ assert_equal 'skywizards', expected_source[key]
107
+ end
108
+ end
109
+
110
+ def test_set_value_from_environment_variable
111
+ ENV['NEW_RELIC_LICENSE_KEY'] = 'super rad'
112
+ @environment_source.set_value_from_environment_variable('NEW_RELIC_LICENSE_KEY')
113
+ assert_equal @environment_source[:license_key], 'super rad'
114
+ end
115
+
116
+ def test_set_key_by_type_uses_the_default_type
117
+ ENV['NEW_RELIC_TEST'] = 'true'
118
+ @environment_source.set_key_by_type(:enabled, 'NEW_RELIC_TEST')
119
+ assert_equal true, @environment_source[:enabled]
120
+ end
121
+
122
+ def test_set_key_with_new_relic_prefix
123
+ assert_applied_string('NEW_RELIC_LICENSE_KEY', :license_key)
124
+ end
125
+
126
+ def test_set_key_with_newrelic_prefix
127
+ assert_applied_string('NEWRELIC_LICENSE_KEY', :license_key)
128
+ end
129
+
130
+ def test_does_not_set_key_without_new_relic_related_prefix
131
+ ENV['CONFIG_PATH'] = 'boom'
132
+ assert_not_equal 'boom', EnvironmentSource.new[:config_path]
133
+ end
134
+
135
+ def test_convert_environment_key_to_config_key
136
+ result = @environment_source.convert_environment_key_to_config_key('NEW_RELIC_IS_RAD')
137
+ assert_equal :is_rad, result
138
+ end
139
+
140
+ def test_convert_environment_key_to_config_key_respects_aliases
141
+ assert_applied_boolean('NEWRELIC_ENABLE', :enabled)
142
+ end
143
+
144
+ def test_convert_environment_key_to_config_key_allows_underscores_as_dots
145
+ assert_applied_string('NEW_RELIC_AUDIT_LOG_PATH', :'audit_log.path')
146
+ end
147
+
148
+ def test_collect_new_relic_environment_variable_keys
149
+ keys = %w(NEW_RELIC_IS_RAD NEWRELIC_IS_MAGIC)
150
+ keys.each { |key| ENV[key] = 'true' }
151
+
152
+ result = @environment_source.collect_new_relic_environment_variable_keys
153
+ assert_equal keys, result
154
+ end
155
+
95
156
  def assert_applied_string(env_var, config_var)
96
157
  ENV[env_var] = 'test value'
97
158
  assert_equal 'test value', EnvironmentSource.new[config_var.to_sym]
@@ -103,5 +164,18 @@ module NewRelic::Agent::Configuration
103
164
  assert_equal :'test value', EnvironmentSource.new[config_var.to_sym]
104
165
  ENV.delete(env_var)
105
166
  end
167
+
168
+ def assert_applied_fixnum(env_var, config_var)
169
+ ENV[env_var] = '3000'
170
+ assert_equal 3000, EnvironmentSource.new[config_var.to_sym]
171
+ ENV.delete(env_var)
172
+ end
173
+
174
+ def assert_applied_boolean(env_var, config_var)
175
+ ENV[env_var] = 'true'
176
+ assert_equal true, EnvironmentSource.new[config_var.to_sym]
177
+ ENV.delete(env_var)
178
+ end
179
+
106
180
  end
107
181
  end
@@ -72,6 +72,21 @@ module NewRelic::Agent::Configuration
72
72
  @manager.remove_config(source)
73
73
  end
74
74
 
75
+ def test_manager_resolves_nested_procs_from_default_source
76
+ source = {
77
+ :foo => Proc.new { self[:bar] },
78
+ :bar => Proc.new { self[:baz] },
79
+ :baz => Proc.new { 'Russian Nesting Dolls!' }
80
+ }
81
+ @manager.apply_config(source)
82
+
83
+ source.keys.each do |key|
84
+ assert_equal 'Russian Nesting Dolls!', @manager[key]
85
+ end
86
+
87
+ @manager.remove_config(source)
88
+ end
89
+
75
90
  def test_should_not_apply_removed_sources
76
91
  test_source = TestSource.new
77
92
  @manager.apply_config(test_source)
@@ -138,7 +153,7 @@ module NewRelic::Agent::Configuration
138
153
  end
139
154
 
140
155
  def test_config_masks_thread_profiler
141
- supported = NewRelic::Agent::ThreadProfiler.is_supported?
156
+ supported = NewRelic::Agent::Commands::ThreadProfiler.is_supported?
142
157
  reported_config = @manager.to_collector_hash
143
158
 
144
159
  if supported
@@ -41,9 +41,7 @@ module NewRelic::Agent
41
41
 
42
42
  NewRelic::Agent.config.apply_config( @config )
43
43
  @monitor.register_event_listeners
44
- NewRelic::Agent::TransactionInfo.get.guid = TRANSACTION_GUID
45
-
46
- # NewRelic::Agent.logger = NewRelic::Agent::AgentLogger.new( {:log_level => 'debug'}, '', Logger.new($stderr) )
44
+ NewRelic::Agent::TransactionState.get.request_guid = TRANSACTION_GUID
47
45
  end
48
46
 
49
47
  def teardown
@@ -66,7 +64,7 @@ module NewRelic::Agent
66
64
  end
67
65
 
68
66
  def test_encodes_transaction_name
69
- NewRelic::Agent::BrowserMonitoring.stubs(:timings).returns(stub(
67
+ NewRelic::Agent::TransactionState.any_instance.stubs(:timings).returns(stub(
70
68
  :transaction_name => "\"'goo",
71
69
  :queue_time_in_seconds => QUEUE_TIME,
72
70
  :app_time_in_seconds => APP_TIME))
@@ -228,7 +226,7 @@ module NewRelic::Agent
228
226
  end
229
227
 
230
228
  def with_default_timings
231
- NewRelic::Agent::BrowserMonitoring.stubs(:timings).returns(stub(
229
+ NewRelic::Agent::TransactionState.any_instance.stubs(:timings).returns(stub(
232
230
  :transaction_name => TRANSACTION_NAME,
233
231
  :queue_time_in_seconds => QUEUE_TIME,
234
232
  :app_time_in_seconds => APP_TIME))
@@ -301,6 +301,20 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
301
301
  assert err.message.include?("Ruby agent internal error")
302
302
  end
303
303
 
304
+ def test_blamed_metric_from_options
305
+ assert_equal "Errors/boo", @error_collector.blamed_metric_name(:metric => "boo")
306
+ end
307
+
308
+ def test_blamed_metric_from_transaction
309
+ NewRelic::Agent::TransactionState.get.transaction = stub(:name => "Controller/foo/bar")
310
+ assert_equal "Errors/Controller/foo/bar", @error_collector.blamed_metric_name({})
311
+ end
312
+
313
+ def test_blamed_metric_with_no_transaction
314
+ NewRelic::Agent::TransactionState.get.transaction = nil
315
+ assert_nil @error_collector.blamed_metric_name({})
316
+ end
317
+
304
318
  private
305
319
 
306
320
  def expects_error_count_increase(increase)
@@ -132,7 +132,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Test::U
132
132
  @subscriber.start('process_action.action_controller', :id, @entry_payload)
133
133
  @subscriber.finish('process_action.action_controller', :id, @exit_payload)
134
134
 
135
- assert NewRelic::Agent::TransactionInfo.get.ignore_end_user?
135
+ assert NewRelic::Agent::TransactionState.get.request_ignore_enduser
136
136
  end
137
137
 
138
138
  def test_record_busy_time
@@ -23,6 +23,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
23
23
  def setup
24
24
  super
25
25
  NewRelic::Agent.manual_start
26
+ ActiveRecord::Base.establish_connection unless ActiveRecord::Base.connection.active?
26
27
  ActiveRecordFixtures.setup
27
28
  NewRelic::Agent.instance.transaction_sampler.reset!
28
29
  NewRelic::Agent.instance.stats_engine.clear_stats
@@ -33,8 +34,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
33
34
 
34
35
  def teardown
35
36
  super
36
- NewRelic::Agent::TransactionInfo.reset
37
- Thread::current[:newrelic_scope_name] = nil
37
+ NewRelic::Agent::TransactionState.reset
38
38
  NewRelic::Agent.shutdown
39
39
  end
40
40
 
@@ -299,7 +299,6 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
299
299
 
300
300
  def test_direct_sql
301
301
  assert_nil NewRelic::Agent::Transaction.current
302
- assert_nil NewRelic::Agent.instance.stats_engine.scope_name
303
302
  assert_equal 0, NewRelic::Agent.instance.stats_engine.metrics.size, NewRelic::Agent.instance.stats_engine.metrics.inspect
304
303
 
305
304
  expected_metrics = %W[
@@ -31,24 +31,20 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
31
31
  end
32
32
 
33
33
  def test_records_metrics_for_simple_find
34
- t1 = Time.now
35
- t0 = t1 - 2
36
- @subscriber.call('sql.active_record', t0, t1, :id, @params)
34
+ freeze_time
37
35
 
38
- metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
36
+ simulate_query(2)
39
37
 
40
- metric = @stats_engine.lookup_stats(metric_name)
41
- assert_equal(1, metric.call_count)
42
- assert_equal(2.0, metric.total_call_time)
38
+ metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
39
+ assert_metrics_recorded(
40
+ metric_name => { :call_count => 1, :total_call_time => 2.0 }
41
+ )
43
42
  end
44
43
 
45
44
  def test_records_scoped_metrics
46
- t1 = Time.now
47
- t0 = t1 - 2
45
+ freeze_time
48
46
 
49
- in_transaction('test_txn') do
50
- @subscriber.call('sql.active_record', t0, t1, :id, @params)
51
- end
47
+ in_transaction('test_txn') { simulate_query(2) }
52
48
 
53
49
  metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
54
50
  assert_metrics_recorded(
@@ -57,24 +53,18 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
57
53
  end
58
54
 
59
55
  def test_records_nothing_if_tracing_disabled
60
- t1 = Time.now
61
- t0 = t1 - 2
56
+ freeze_time
62
57
 
63
- NewRelic::Agent.disable_all_tracing do
64
- @subscriber.call('sql.active_record', t0, t1, :id, @params)
65
- end
58
+ NewRelic::Agent.disable_all_tracing { simulate_query(2) }
66
59
 
67
60
  metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
68
61
  assert_metrics_not_recorded([metric_name])
69
62
  end
70
63
 
71
64
  def test_records_rollup_metrics
72
- t1 = Time.now
73
- t0 = t1 - 2
65
+ freeze_time
74
66
 
75
- in_web_transaction do
76
- @subscriber.call('sql.active_record', t0, t1, :id, @params)
77
- end
67
+ in_web_transaction { simulate_query(2) }
78
68
 
79
69
  assert_metrics_recorded(
80
70
  'ActiveRecord/find' => { :call_count => 1, :total_call_time => 2 },
@@ -83,10 +73,9 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
83
73
  end
84
74
 
85
75
  def test_records_remote_service_metric
86
- t1 = Time.now
87
- t0 = t1 - 2
76
+ freeze_time
88
77
 
89
- @subscriber.call('sql.active_record', t0, t1, :id, @params)
78
+ simulate_query(2)
90
79
 
91
80
  assert_metrics_recorded(
92
81
  'RemoteService/sql/mysql/server' => { :call_count => 1, :total_call_time => 2.0 }
@@ -94,8 +83,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
94
83
  end
95
84
 
96
85
  def test_creates_txn_segment
97
- t1 = Time.now
98
- t0 = t1 - 2
86
+ freeze_time
99
87
 
100
88
  NewRelic::Agent.manual_start
101
89
  @stats_engine.start_transaction
@@ -103,7 +91,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
103
91
  sampler.notice_first_scope_push(Time.now.to_f)
104
92
  sampler.notice_transaction('/path', {})
105
93
  sampler.notice_push_scope('Controller/sandwiches/index')
106
- @subscriber.call('sql.active_record', t0, t1, :id, @params)
94
+ simulate_query(2)
107
95
  sampler.notice_pop_scope('Controller/sandwiches/index')
108
96
  sampler.notice_scope_empty(stub('txn', :name => '/path', :custom_parameters => {}))
109
97
 
@@ -121,15 +109,25 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
121
109
  NewRelic::Agent.manual_start
122
110
  sampler = NewRelic::Agent.instance.sql_sampler
123
111
  sampler.notice_first_scope_push nil
124
- t1 = Time.now
125
- t0 = t1 - 2
112
+ freeze_time
126
113
 
127
- @subscriber.call('sql.active_record', t0, t1, :id, @params)
114
+ simulate_query(2)
128
115
 
129
116
  assert_equal 'SELECT * FROM sandwiches', sampler.transaction_data.sql_data[0].sql
130
117
  ensure
131
118
  NewRelic::Agent.shutdown
132
119
  end
120
+
121
+ def test_should_not_raise_due_to_an_exception_during_instrumentation_callback
122
+ @subscriber.stubs(:record_metrics).raises(StandardError)
123
+ assert_nothing_raised { simulate_query }
124
+ end
125
+
126
+ def simulate_query(duration=nil)
127
+ @subscriber.start('sql.active_record', :id, @params)
128
+ advance_time(duration) if duration
129
+ @subscriber.finish('sql.active_record', :id, @params)
130
+ end
133
131
  end
134
132
 
135
133
  else
@@ -7,6 +7,18 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Test::Un
7
7
  require 'new_relic/agent/instrumentation/controller_instrumentation'
8
8
  class TestObject
9
9
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
10
+
11
+ def public_transaction(*args); end
12
+
13
+ protected
14
+ def protected_transaction(*args); end
15
+
16
+ private
17
+ def private_transaction(*args); end
18
+
19
+ add_transaction_tracer :public_transaction
20
+ add_transaction_tracer :protected_transaction
21
+ add_transaction_tracer :private_transaction
10
22
  end
11
23
 
12
24
  def setup
@@ -94,4 +106,14 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Test::Un
94
106
  result = @txn_namer.path_name(:name => "perform", :class_name => 'Resque')
95
107
  assert_equal("Resque/perform", result)
96
108
  end
109
+
110
+ def test_add_transaction_tracer_should_not_double_instrument
111
+ TestObject.expects(:alias_method).never
112
+ TestObject.class_eval do
113
+ add_transaction_tracer :public_transaction
114
+ add_transaction_tracer :protected_transaction
115
+ add_transaction_tracer :private_transaction
116
+ end
117
+ obj = TestObject.new
118
+ end
97
119
  end
@@ -3,9 +3,9 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
6
- class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest < Test::Unit::TestCase
6
+ class NewRelic::Agent::MethodTracer::TraceExecutionScopedTest < Test::Unit::TestCase
7
7
  require 'new_relic/agent/method_tracer'
8
- include NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScoped
8
+ include NewRelic::Agent::MethodTracer::TraceExecutionScoped
9
9
 
10
10
  def setup
11
11
  NewRelic::Agent.agent.stats_engine.clear_stats
@@ -62,7 +62,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
62
62
  attr_reader :stats_engine
63
63
 
64
64
  def setup
65
- Thread::current[:newrelic_scope_stack] = nil
65
+ NewRelic::Agent::TransactionState.clear
66
66
 
67
67
  NewRelic::Agent.manual_start
68
68
  @stats_engine = NewRelic::Agent.instance.stats_engine
@@ -94,7 +94,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
94
94
 
95
95
  def test_record_metrics_does_not_raise_outside_transaction
96
96
  assert_nothing_raised do
97
- NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScoped.record_metrics('a', ['b'], 12, 10, :metric => true)
97
+ NewRelic::Agent::MethodTracer::TraceExecutionScoped.record_metrics('a', ['b'], 12, 10, :metric => true)
98
98
  end
99
99
  expected = { :call_count => 1, :total_call_time => 12, :total_exclusive_time => 10 }
100
100
  assert_metrics_recorded('a' => expected, 'b' => expected)
@@ -3,7 +3,7 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
6
- require 'new_relic/agent/thread_profiler'
6
+ require 'new_relic/agent/commands/thread_profiler'
7
7
 
8
8
  # Tests of HTTP Keep Alive implementation that require a different setup and
9
9
  # set of mocks.
@@ -108,42 +108,6 @@ class NewRelicServiceTest < Test::Unit::TestCase
108
108
  assert_equal File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'cert', 'cacert.pem')), @service.cert_file_path
109
109
  end
110
110
 
111
- # This test does not actually use the ruby agent in any way - it's
112
- # testing that the CA file we ship actually validates our server's
113
- # certificate.
114
- def test_cert_file
115
- if internet_connection?
116
- require 'socket'
117
- require 'openssl'
118
-
119
- s = TCPSocket.new 'collector.newrelic.com', 443
120
- ctx = OpenSSL::SSL::SSLContext.new
121
- ctx.ca_file = @service.cert_file_path
122
- ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
123
- s = OpenSSL::SSL::SSLSocket.new s, ctx
124
- s.connect
125
- # should not raise an error
126
- end
127
- end
128
-
129
- # see above, but for staging, as well. This allows us to test new
130
- # certificates in a non-customer-facing place before setting them
131
- # live.
132
- def test_staging_cert_file
133
- if internet_connection?
134
- require 'socket'
135
- require 'openssl'
136
-
137
- s = TCPSocket.new 'staging-collector.newrelic.com', 443
138
- ctx = OpenSSL::SSL::SSLContext.new
139
- ctx.ca_file = @service.cert_file_path
140
- ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
141
- s = OpenSSL::SSL::SSLSocket.new s, ctx
142
- s.connect
143
- # should not raise an error
144
- end
145
- end
146
-
147
111
  def test_initialize_uses_correct_license_key_settings
148
112
  with_config(:license_key => 'abcde') do
149
113
  service = NewRelic::Agent::NewRelicService.new
@@ -269,12 +233,11 @@ class NewRelicServiceTest < Test::Unit::TestCase
269
233
  assert_equal 'some analytic events', response
270
234
  end
271
235
 
272
-
273
- # Thread profiling only available in certain versions
274
- if NewRelic::Agent::ThreadProfiler.is_supported?
236
+ # Although thread profiling is only available in some circumstances, the
237
+ # service communication doesn't care about that at all
275
238
  def test_profile_data
276
239
  @http_handle.respond_to(:profile_data, 'profile' => 123)
277
- response = @service.profile_data(NewRelic::Agent::ThreadProfile.new(0, 0, 0, true))
240
+ response = @service.profile_data([])
278
241
  assert_equal({ "profile" => 123 }, response)
279
242
  end
280
243
 
@@ -296,17 +259,10 @@ if NewRelic::Agent::ThreadProfiler.is_supported?
296
259
 
297
260
  def test_agent_command_results
298
261
  @http_handle.respond_to(:agent_command_results, {})
299
- response = @service.agent_command_results(4200)
262
+ response = @service.agent_command_results({'1' => {}})
300
263
  assert_equal({}, response)
301
264
  end
302
265
 
303
- def test_agent_command_results_with_errors
304
- @http_handle.respond_to(:agent_command_results, [123])
305
- response = @service.agent_command_results(4200, 'Boo!')
306
- assert_equal [123], response
307
- end
308
- end
309
-
310
266
  def test_request_timeout
311
267
  with_config(:timeout => 600) do
312
268
  service = NewRelic::Agent::NewRelicService.new('abcdef', @server)