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
@@ -1,114 +0,0 @@
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 'erb'
6
-
7
- module NewRelic
8
- module Agent
9
- class TransactionInfo
10
-
11
- attr_accessor :token, :capture_deep_tt, :request, :transaction
12
- attr_reader :start_time
13
-
14
- def initialize
15
- @guid = ""
16
- @start_time = Time.now
17
- @ignore_end_user = false
18
- @transaction = Transaction.current
19
- end
20
-
21
- def force_persist_sample?(sample)
22
- token && sample.duration > Agent.config[:apdex_t]
23
- end
24
-
25
- def include_guid?
26
- token && duration > Agent.config[:apdex_t]
27
- end
28
-
29
- def guid
30
- @guid
31
- end
32
-
33
- def guid=(value)
34
- @guid = value
35
- end
36
-
37
- def duration
38
- Time.now - start_time
39
- end
40
-
41
- def ignore_end_user?
42
- @ignore_end_user
43
- end
44
-
45
- def ignore_end_user=(value)
46
- @ignore_end_user = value
47
- end
48
-
49
- def apdex_t
50
- (Agent.config[:web_transactions_apdex] &&
51
- Agent.config[:web_transactions_apdex][@transaction.name]) ||
52
- Agent.config[:apdex_t]
53
- end
54
-
55
- def transaction_trace_threshold
56
- key = :'transaction_tracer.transaction_threshold'
57
- if Agent.config.source(key).class == Configuration::DefaultSource
58
- apdex_t * 4
59
- else
60
- Agent.config[key]
61
- end
62
- end
63
-
64
- def self.get()
65
- Thread.current[:newrelic_transaction_info] ||= TransactionInfo.new
66
- end
67
-
68
- def self.set(instance)
69
- Thread.current[:newrelic_transaction_info] = instance
70
- end
71
-
72
- def self.clear
73
- Thread.current[:newrelic_transaction_info] = nil
74
- end
75
-
76
- # clears any existing transaction info object and initializes a new one.
77
- # This starts the timer for the transaction.
78
- def self.reset(request=nil)
79
- clear
80
- instance = get
81
- instance.token = get_token(request)
82
- instance.request = request
83
- instance.transaction = Transaction.current
84
- end
85
-
86
- def self.get_token(request)
87
- return nil unless request
88
-
89
- agent_flag = request.cookies['NRAGENT']
90
- if agent_flag and agent_flag.instance_of? String
91
- s = agent_flag.split("=")
92
- if s.length == 2
93
- if s[0] == "tk" && s[1]
94
- ERB::Util.h(sanitize_token(s[1]))
95
- end
96
- end
97
- else
98
- nil
99
- end
100
- end
101
-
102
- # Run through a collection of unsafe characters ( in the context of the token )
103
- # and set the token to an empty string if any of them are found in the token so that
104
- # potential XSS attacks via the token are avoided
105
- def self.sanitize_token(token)
106
-
107
- if ( /[<>'"]/ =~ token )
108
- token.replace("")
109
- end
110
- token
111
- end
112
- end
113
- end
114
- end
@@ -1,89 +0,0 @@
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 'optparse'
6
-
7
- # Run the command given by the first argument. Right
8
- # now all we have is deployments. We hope to have other
9
- # kinds of events here later.
10
- $LOAD_PATH << "#{File.dirname(__FILE__)}/.."
11
- module NewRelic
12
- class Command
13
- attr_accessor :leftover
14
- # Capture a failure to execute the command.
15
- class CommandFailure < StandardError
16
- attr_reader :options
17
- def initialize message, opt_parser=nil
18
- super message
19
- @options = opt_parser
20
- end
21
- end
22
-
23
- def info(message)
24
- STDOUT.puts message
25
- end
26
-
27
- def err(message)
28
- STDERR.puts message
29
- end
30
-
31
- def initialize(command_line_args)
32
- if Hash === command_line_args
33
- # command line args is an options hash
34
- command_line_args.each do | key, value |
35
- instance_variable_set "@#{key}", value.to_s if value
36
- end
37
- else
38
- # parse command line args. Throw an exception on a bad arg.
39
- @options = options do | opts |
40
- opts.on("-h", "Show this help") { raise CommandFailure, opts.to_s }
41
- end
42
- @leftover = @options.parse(command_line_args)
43
- end
44
- rescue OptionParser::ParseError => e
45
- raise CommandFailure.new(e.message, @options)
46
- end
47
-
48
- @commands = []
49
- def self.inherited(subclass)
50
- @commands << subclass
51
- end
52
-
53
- cmds = File.expand_path(File.join(File.dirname(__FILE__), 'commands', '*.rb'))
54
- Dir[cmds].each{|command| require command }
55
-
56
- def self.run
57
-
58
- @command_names = @commands.map{ |c| c.command }
59
-
60
- extra = []
61
- options = ARGV.options do |opts|
62
- script_name = File.basename($0)
63
- if script_name =~ /newrelic_cmd$/
64
- $stdout.puts "warning: the 'newrelic_cmd' script has been renamed 'newrelic'"
65
- script_name = 'newrelic'
66
- end
67
- opts.banner = "Usage: #{script_name} [ #{ @command_names.join(" | ")} ] [options]"
68
- opts.separator "use '#{script_name} <command> -h' to see detailed command options"
69
- opts
70
- end
71
- extra = options.order!
72
- command = extra.shift
73
- # just make it a little easier on them
74
- command = 'deployments' if command =~ /deploy/
75
- if command.nil?
76
- STDERR.puts options
77
- elsif !@command_names.include?(command)
78
- STDERR.puts "Unrecognized command: #{command}"
79
- STDERR.puts options
80
- else
81
- command_class = @commands.find{ |c| c.command == command}
82
- command_class.new(extra).run
83
- end
84
- rescue OptionParser::InvalidOption => e
85
- raise NewRelic::Command::CommandFailure, e.message
86
- end
87
- end
88
-
89
- end
@@ -1,348 +0,0 @@
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
- if defined?(::Rails)
6
-
7
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
8
- require 'action_controller/test_case'
9
-
10
- class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
11
- require 'action_controller/base'
12
- require 'new_relic/agent/agent_test_controller'
13
-
14
- self.controller_class = NewRelic::Agent::AgentTestController
15
-
16
- attr_accessor :agent, :engine
17
-
18
- def suite_initialization
19
- # Suggested by cee-dub for merb tests. I'm actually amazed if our tests work with merb.
20
- if defined?(Merb::Router)
21
- Merb::Router.prepare do |r|
22
- match('/:controller(/:action)(.:format)').register
23
- end
24
- elsif NewRelic::Control.instance.rails_version < NewRelic::VersionNumber.new("3.0")
25
- ActionController::Routing::Routes.draw do |map|
26
- map.connect '/:controller/:action.:format'
27
- map.connect '/:controller/:action'
28
- end
29
- else
30
- Rails.application.routes.draw do
31
- get '/:controller/:action.:format'
32
- get '/:controller/:action'
33
- end
34
- end
35
-
36
- if defined?(Rails) && Rails.respond_to?(:application) &&
37
- Rails.application.respond_to?(:routes)
38
- @routes = Rails.application.routes
39
- end
40
-
41
- Thread.current[:newrelic_ignore_controller] = nil
42
- NewRelic::Agent.manual_start
43
- @agent = NewRelic::Agent.instance
44
- agent.transaction_sampler.harvest
45
- NewRelic::Agent::AgentTestController.class_eval do
46
- newrelic_ignore :only => [:action_to_ignore, :entry_action, :base_action]
47
- newrelic_ignore_apdex :only => :action_to_ignore_apdex
48
- end
49
- @engine = @agent.stats_engine
50
-
51
- # ActiveSupport testing keeps blowing away my subscribers on
52
- # teardown for some reason. Have to keep putting it back.
53
- NewRelic::Agent.instance.events.subscribe(:before_call) do |env|
54
- NewRelic::Agent::TransactionInfo.reset(::Rack::Request.new(env))
55
- end
56
- end
57
-
58
- # Normally you can do this with #setup but for some reason in rails 2.0.2
59
- # setup is not called.
60
- if NewRelic::Control.instance.rails_version <= '2.1.0'
61
- def initialize name
62
- super name
63
- suite_initialization
64
- end
65
- else
66
- alias_method :setup, :suite_initialization
67
- end
68
-
69
- def teardown
70
- Thread.current[:newrelic_ignore_controller] = nil
71
- NewRelic::Agent.shutdown
72
- NewRelic::Agent::AgentTestController.clear_headers
73
- super
74
- end
75
-
76
- def test_mongrel_queue
77
- NewRelic::Agent::AgentTestController.clear_headers
78
- engine.clear_stats
79
- NewRelic::Control.instance.local_env.stubs(:mongrel) \
80
- .returns(stub('mongrel',
81
- :workers => stub('workers',
82
- :list => stub('list',
83
- :length => '10'))))
84
- get :index
85
- assert_equal 1, stats('HttpDispatcher').call_count
86
- assert_equal 1, engine.get_stats_no_scope('Mongrel/Queue Length').call_count
87
- assert_equal 9, engine.get_stats_no_scope('Mongrel/Queue Length').total_call_time
88
- assert_equal 0, engine.get_stats_no_scope('WebFrontend/Mongrel/Average Queue Time').call_count
89
- end if ::Rails::VERSION::MAJOR.to_i <= 3
90
-
91
- def test_new_queue_integration
92
- now = freeze_time
93
-
94
- NewRelic::Agent::AgentTestController.clear_headers
95
- engine.clear_stats
96
- start = ((now - 1).to_f * 1_000_000).to_i
97
- NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_QUEUE_START'=> "t=#{start}"
98
- get :index
99
-
100
- assert_metrics_recorded('WebFrontend/QueueTime' => { :total_call_time => 1 })
101
- end
102
-
103
- def test_new_frontend_work_integration
104
- now = freeze_time
105
-
106
- engine.clear_stats
107
- times = [now - 3, now - 2, now - 1]
108
- times.map! {|t| (t.to_f * 1_000_000).to_i }
109
- NewRelic::Agent::AgentTestController.set_some_headers(
110
- 'HTTP_X_REQUEST_START' => "t=#{times[0]}",
111
- 'HTTP_X_QUEUE_START' => "t=#{times[1]}",
112
- 'HTTP_X_MIDDLEWARE_START' => "t=#{times[2]}"
113
- )
114
- get :index
115
-
116
- assert_metrics_recorded('WebFrontend/QueueTime' => { :total_call_time => 3 })
117
- end
118
-
119
- def test_render_inline
120
- engine.clear_stats
121
- get :action_inline
122
- assert_equal 'foofah', @response.body
123
- compare_metrics(%w[Controller/new_relic/agent/agent_test/action_inline],
124
- engine.metrics.grep(/^Controller/))
125
- end
126
-
127
- def test_metric__ignore
128
- engine.clear_stats
129
- compare_metrics [], engine.metrics
130
- get :action_to_ignore
131
- compare_metrics [], engine.metrics
132
- end
133
-
134
- # Rails 4 does all error tracking in Rack, not testable here
135
- # see the rails Multiverse suit for Rails 4 error tests
136
- if ::Rails::VERSION::MAJOR.to_i <= 3
137
- def test_controller_rescued_error
138
- engine.clear_stats
139
- assert_raise RuntimeError do
140
- get :action_with_error
141
- end
142
- metrics = ['Apdex',
143
- 'Apdex/new_relic/agent/agent_test/action_with_error',
144
- 'HttpDispatcher',
145
- 'Controller/new_relic/agent/agent_test/action_with_error',
146
- 'Errors/all',
147
- 'Errors/Controller/new_relic/agent/agent_test/action_with_error']
148
-
149
- compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
150
- assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_error").call_count
151
- assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
152
- apdex = engine.get_stats_no_scope("Apdex")
153
-
154
- assert_equal 1, apdex.apdex_f, 'failing'
155
- assert_equal 0, apdex.apdex_t, 'tol'
156
- assert_equal 0, apdex.apdex_s, 'satisfied'
157
- end
158
-
159
- def test_controller_error
160
- engine.clear_stats
161
- assert_raise RuntimeError do
162
- get :action_with_error
163
- end
164
- metrics = ['Apdex',
165
- 'Apdex/new_relic/agent/agent_test/action_with_error',
166
- 'HttpDispatcher',
167
- 'Controller/new_relic/agent/agent_test/action_with_error',
168
- 'Errors/all',
169
- 'Errors/Controller/new_relic/agent/agent_test/action_with_error']
170
-
171
- compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
172
- assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_error").call_count
173
- assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
174
- apdex = engine.get_stats_no_scope("Apdex")
175
-
176
- assert_equal 1, apdex.apdex_f, 'failing'
177
- assert_equal 0, apdex.apdex_t, 'tol'
178
- assert_equal 0, apdex.apdex_s, 'satisfied'
179
- end
180
-
181
- def test_filter_error
182
- engine.clear_stats
183
- assert_raise RuntimeError do
184
- get :action_with_before_filter_error
185
- end
186
- metrics = ['Apdex',
187
- 'Apdex/new_relic/agent/agent_test/action_with_before_filter_error',
188
- 'HttpDispatcher',
189
- 'Controller/new_relic/agent/agent_test/action_with_before_filter_error',
190
- 'Errors/all',
191
- 'Errors/Controller/new_relic/agent/agent_test/action_with_before_filter_error']
192
-
193
- compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0 || m.index('GC')==0}
194
- assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_before_filter_error").call_count
195
- assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
196
- apdex = engine.get_stats_no_scope("Apdex")
197
-
198
- assert_equal 1, apdex.apdex_f, 'failing'
199
- assert_equal 0, apdex.apdex_t, 'tol'
200
- assert_equal 0, apdex.apdex_s, 'satisfied'
201
- end
202
- end
203
-
204
- def test_metric__ignore_base
205
- engine.clear_stats
206
- get :base_action
207
- compare_metrics [], engine.metrics
208
- end
209
-
210
- def test_metric__no_ignore
211
- path = 'new_relic/agent/agent_test/index'
212
- index_stats = stats("Controller/#{path}")
213
- index_apdex_stats = engine.get_stats_no_scope("Apdex/#{path}")
214
- assert_difference 'index_stats.call_count' do
215
- assert_difference 'index_apdex_stats.call_count' do
216
- get :index
217
- end
218
- end
219
- assert_nil Thread.current[:newrelic_ignore_controller]
220
- end
221
-
222
- def test_metric__ignore_apdex
223
- engine = @agent.stats_engine
224
- path = 'new_relic/agent/agent_test/action_to_ignore_apdex'
225
- cpu_stats = stats("ControllerCPU/#{path}")
226
- index_stats = stats("Controller/#{path}")
227
- index_apdex_stats = engine.get_stats_no_scope("Apdex/#{path}")
228
- assert_difference 'index_stats.call_count' do
229
- assert_no_difference 'index_apdex_stats.call_count' do
230
- get :action_to_ignore_apdex
231
- end
232
- end
233
- assert_nil Thread.current[:newrelic_ignore_controller]
234
- end
235
-
236
- def test_records_metric_dispite_ignore_state_when_forced
237
- engine = @agent.stats_engine
238
- get :entry_action
239
- assert_nil Thread.current[:newrelic_ignore_controller]
240
- # explicitly ignored
241
- assert_nil engine.lookup_stats('Controller/agent_test/entry_action')
242
- assert_nil engine.lookup_stats('Controller/agent_test_controller/entry_action')
243
- assert_nil engine.lookup_stats('Controller/AgentTestController/entry_action')
244
- # implicitly ignored because parent action ignored
245
- assert_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController/internal_action')
246
- assert_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController_controller/internal_action')
247
- # forced to be recorded, overrides parent ignore state
248
- assert_not_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController/internal_traced_action')
249
- end
250
-
251
- def test_action_instrumentation
252
- get :index, :foo => 'bar'
253
- assert_match /bar/, @response.body
254
- end
255
-
256
- def test_request_params
257
- s = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
258
- agent.transaction_sampler.reset!
259
- get :index, 'number' => "001-555-1212"
260
- agent.transaction_sampler.harvest(nil)
261
- end
262
- assert_equal 1, s.size
263
- assert_equal('001-555-1212',
264
- s.first.params[:request_params]['number'])
265
- end
266
-
267
- def test_busy_calculation_correctly_calculates_based_acccumlator
268
- # woah it's 1970
269
- now = Time.at 0
270
-
271
- # We'll record two seconds of transactions
272
- later = Time.at(now + 2)
273
- NewRelic::Agent::BusyCalculator.stubs(:time_now).
274
- returns(now).then.returns(later)
275
-
276
- # reset harvest time to epoch (based on stub)
277
- NewRelic::Agent::BusyCalculator.reset
278
-
279
- # We record 1 second of busy time in our two seconds of wall clock
280
- NewRelic::Agent::BusyCalculator.instance_variable_set(:@accumulator, 1.0)
281
-
282
-
283
- NewRelic::Agent::BusyCalculator.harvest_busy
284
-
285
- # smooth out floating point math
286
- stat_int = (stats('Instance/Busy').total_call_time * 10).to_i
287
-
288
- # Despite your expectations, #total_call_time is a percentage here.
289
- assert_equal(stat_int, 5,
290
- "#{stats('Instance/Busy').total_call_time} != 0.5")
291
- end
292
-
293
- def test_busy_calculation_generates_a_positive_value
294
- engine.clear_stats
295
- get :index, 'social_security_number' => "001-555-1212", 'wait' => '0.05'
296
- NewRelic::Agent::BusyCalculator.harvest_busy
297
-
298
- assert_equal 1, stats('Instance/Busy').call_count
299
- assert_equal 1, stats('HttpDispatcher').call_count
300
-
301
- # Timing is too non-deterministic, so we just assert a positive, non-zero
302
- # value here. See
303
- # #test_busy_calculation_correctly_calculates_based_acccumlator for
304
- # assertions that the formula is correct.
305
- assert(stats('Instance/Busy').total_call_time > 0,
306
- "#{stats('Instance/Busy').total_call_time} !> 0")
307
- assert_equal 0, stats('WebFrontend/Mongrel/Average Queue Time').call_count
308
- end
309
- def test_queue_headers_no_header
310
- engine.clear_stats
311
- queue_length_stat = stats('Mongrel/Queue Length')
312
- queue_time_stat = stats('WebFrontend/QueueTime')
313
-
314
- # no request start header
315
- get 'index'
316
- assert_equal 0, queue_length_stat.call_count
317
- end
318
-
319
- def test_queue_headers_apache
320
- # make this test deterministic
321
- Time.stubs(:now => Time.at(1360973845))
322
-
323
- NewRelic::Agent::AgentTestController.clear_headers
324
- engine.clear_stats
325
- queue_length_stat = stats('Mongrel/Queue Length')
326
- queue_time_stat = stats('WebFrontend/QueueTime')
327
-
328
- # apache version of header
329
- request_start = ((Time.now.to_f - 0.5) * 1e6).to_i.to_s
330
- NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_QUEUE_START' => "t=#{request_start}"})
331
- get :index
332
- assert_equal(0, queue_length_stat.call_count, 'We should not be seeing a queue length yet')
333
- assert_equal(1, queue_time_stat.call_count, 'We should have seen the queue header once')
334
- assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
335
- assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
336
-
337
- end
338
-
339
- private
340
- def stats(name)
341
- engine.get_stats_no_scope(name)
342
- end
343
-
344
- end
345
-
346
- else
347
- puts "Skipping tests in #{__FILE__} because Rails is unavailable"
348
- end