newrelic_rpm 3.7.1.188 → 3.7.2.190.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. data.tar.gz.sig +3 -2
  2. data/CHANGELOG +1 -1
  3. data/Guardfile +3 -3
  4. data/README.md +1 -1
  5. data/Rakefile +0 -2
  6. data/init.rb +2 -5
  7. data/lib/new_relic/agent.rb +3 -0
  8. data/lib/new_relic/agent/agent.rb +2 -0
  9. data/lib/new_relic/agent/configuration/default_source.rb +32 -14
  10. data/lib/new_relic/agent/configuration/environment_source.rb +1 -0
  11. data/lib/new_relic/agent/cross_app_monitor.rb +2 -2
  12. data/lib/new_relic/agent/cross_app_tracing.rb +2 -2
  13. data/lib/new_relic/agent/error_collector.rb +1 -1
  14. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -1
  15. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +10 -8
  16. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +11 -6
  17. data/lib/new_relic/agent/javascript_instrumentor.rb +27 -36
  18. data/lib/new_relic/agent/method_tracer.rb +20 -2
  19. data/lib/new_relic/agent/new_relic_service.rb +35 -27
  20. data/lib/new_relic/agent/request_sampler.rb +20 -13
  21. data/lib/new_relic/agent/sampler_collection.rb +4 -0
  22. data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -4
  23. data/lib/new_relic/agent/system_info.rb +25 -15
  24. data/lib/new_relic/agent/transaction.rb +23 -4
  25. data/lib/new_relic/agent/transaction_sampler.rb +1 -1
  26. data/lib/new_relic/cli/install.rb +1 -1
  27. data/lib/new_relic/control.rb +1 -0
  28. data/lib/new_relic/helper.rb +1 -29
  29. data/lib/new_relic/json_wrapper.rb +92 -0
  30. data/lib/new_relic/language_support.rb +4 -0
  31. data/lib/new_relic/rack/agent_hooks.rb +4 -0
  32. data/lib/new_relic/rack/browser_monitoring.rb +4 -0
  33. data/lib/new_relic/rack/developer_mode.rb +4 -1
  34. data/lib/new_relic/rack/error_collector.rb +5 -0
  35. data/lib/new_relic/rack/transaction_reset.rb +20 -0
  36. data/lib/new_relic/version.rb +1 -1
  37. data/lib/tasks/install.rake +0 -1
  38. data/newrelic_rpm.gemspec +1 -1
  39. data/test/agent_helper.rb +7 -8
  40. data/test/environments/norails/Gemfile +2 -1
  41. data/test/environments/rails21/Gemfile +2 -2
  42. data/test/environments/rails21/config/environment.rb +1 -3
  43. data/test/environments/rails21/config/environments/development.rb +0 -6
  44. data/test/environments/rails22/Gemfile +2 -2
  45. data/test/environments/rails22/config/environment.rb +0 -2
  46. data/test/environments/rails22/config/environments/development.rb +0 -6
  47. data/test/environments/rails23/Gemfile +2 -3
  48. data/test/environments/rails23/config/environment.rb +0 -9
  49. data/test/environments/rails23/config/environments/development.rb +0 -5
  50. data/test/environments/rails30/Gemfile +2 -2
  51. data/test/environments/rails31/Gemfile +2 -2
  52. data/test/environments/rails32/Gemfile +2 -1
  53. data/test/environments/rails40/Gemfile +2 -1
  54. data/test/intentional_fail.rb +1 -2
  55. data/test/multiverse/lib/multiverse/envfile.rb +1 -5
  56. data/test/multiverse/lib/multiverse/suite.rb +10 -27
  57. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +49 -67
  58. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +128 -0
  59. data/test/multiverse/suites/agent_only/marshaling_test.rb +7 -9
  60. data/test/multiverse/suites/agent_only/script/loading.rb +20 -0
  61. data/test/multiverse/suites/agent_only/start_up_test.rb +7 -0
  62. data/test/multiverse/suites/bare/Envfile +3 -0
  63. data/test/multiverse/suites/bare/standalone_instrumentation_test.rb +43 -0
  64. data/test/multiverse/suites/rails/Envfile +0 -2
  65. data/test/multiverse/suites/rails/app/views/views/_a_partial.html.erb +1 -0
  66. data/test/multiverse/suites/rails/app/views/views/index.html.erb +1 -1
  67. data/test/multiverse/suites/rails/error_tracing_test.rb +1 -1
  68. data/test/multiverse/suites/rails/request_statistics_test.rb +9 -4
  69. data/test/multiverse/suites/rails/view_instrumentation_test.rb +111 -106
  70. data/test/multiverse/suites/typhoeus/Envfile +1 -1
  71. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +16 -2
  72. data/test/multiverse/test/multiverse_test.rb +2 -2
  73. data/test/new_relic/agent/agent/connect_test.rb +1 -1
  74. data/test/new_relic/agent/agent/start_test.rb +1 -1
  75. data/test/new_relic/agent/agent/start_worker_thread_test.rb +1 -1
  76. data/test/new_relic/agent/agent_logger_test.rb +3 -7
  77. data/test/new_relic/agent/agent_test.rb +33 -57
  78. data/test/new_relic/agent/apdex_from_server_test.rb +1 -1
  79. data/test/new_relic/agent/audit_logger_test.rb +5 -8
  80. data/test/new_relic/agent/autostart_test.rb +1 -1
  81. data/test/new_relic/agent/browser_token_test.rb +1 -1
  82. data/test/new_relic/agent/busy_calculator_test.rb +2 -4
  83. data/test/new_relic/agent/commands/agent_command_router_test.rb +5 -5
  84. data/test/new_relic/agent/commands/agent_command_test.rb +1 -1
  85. data/test/new_relic/agent/commands/thread_profiler_session_test.rb +6 -6
  86. data/test/new_relic/agent/commands/xray_session_collection_test.rb +10 -10
  87. data/test/new_relic/agent/commands/xray_session_test.rb +1 -1
  88. data/test/new_relic/agent/configuration/default_source_test.rb +4 -4
  89. data/test/new_relic/agent/configuration/environment_source_test.rb +14 -2
  90. data/test/new_relic/agent/configuration/manager_test.rb +3 -3
  91. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +1 -1
  92. data/test/new_relic/agent/configuration/server_source_test.rb +1 -1
  93. data/test/new_relic/agent/configuration/yaml_source_test.rb +2 -2
  94. data/test/new_relic/agent/cpu_sampler_test.rb +1 -1
  95. data/test/new_relic/agent/cross_app_monitor_test.rb +3 -3
  96. data/test/new_relic/agent/cross_app_tracing_test.rb +5 -4
  97. data/test/new_relic/agent/database_test.rb +1 -1
  98. data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +1 -1
  99. data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +1 -1
  100. data/test/new_relic/agent/datastores/mongo/obfuscator_test.rb +1 -1
  101. data/test/new_relic/agent/datastores/mongo/statement_formatter_test.rb +2 -2
  102. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -1
  103. data/test/new_relic/agent/error_collector_test.rb +5 -3
  104. data/test/new_relic/agent/event_listener_test.rb +1 -1
  105. data/test/new_relic/agent/harvester_test.rb +1 -1
  106. data/test/new_relic/agent/http_clients/uri_util_test.rb +1 -1
  107. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
  108. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +1 -1
  109. data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +1 -1
  110. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +495 -495
  111. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +2 -2
  112. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +1 -1
  113. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
  114. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +1 -1
  115. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +4 -6
  116. data/test/new_relic/agent/instrumentation/queue_time_test.rb +1 -1
  117. data/test/new_relic/agent/instrumentation/rack_test.rb +1 -1
  118. data/test/new_relic/agent/instrumentation/sinatra/transaction_namer_test.rb +1 -1
  119. data/test/new_relic/agent/instrumentation/sinatra_test.rb +1 -1
  120. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +7 -7
  121. data/test/new_relic/agent/javascript_instrumentor_test.rb +47 -55
  122. data/test/new_relic/agent/memcache_instrumentation_test.rb +1 -1
  123. data/test/new_relic/agent/memory_logger_test.rb +1 -1
  124. data/test/new_relic/agent/method_interrobang_test.rb +2 -3
  125. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -4
  126. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  127. data/test/new_relic/agent/method_tracer_test.rb +6 -7
  128. data/test/new_relic/agent/method_visibility_test.rb +1 -1
  129. data/test/new_relic/agent/new_relic_service_test.rb +129 -19
  130. data/test/new_relic/agent/obfuscator_test.rb +1 -1
  131. data/test/new_relic/agent/pipe_channel_manager_test.rb +143 -145
  132. data/test/new_relic/agent/pipe_service_test.rb +2 -4
  133. data/test/new_relic/agent/request_sampler_test.rb +23 -19
  134. data/test/new_relic/agent/rpm_agent_test.rb +3 -3
  135. data/test/new_relic/agent/rules_engine_test.rb +1 -1
  136. data/test/new_relic/agent/sampled_buffer_test.rb +1 -1
  137. data/test/new_relic/agent/sampler_collection_test.rb +3 -3
  138. data/test/new_relic/agent/sampler_test.rb +1 -1
  139. data/test/new_relic/agent/shim_agent_test.rb +1 -1
  140. data/test/new_relic/agent/sql_sampler_test.rb +4 -6
  141. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +1 -1
  142. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +5 -5
  143. data/test/new_relic/agent/stats_engine/samplers_test.rb +2 -2
  144. data/test/new_relic/agent/stats_engine_test.rb +3 -3
  145. data/test/new_relic/agent/stats_hash_test.rb +2 -2
  146. data/test/new_relic/agent/stats_test.rb +1 -1
  147. data/test/new_relic/agent/threading/agent_thread_test.rb +2 -4
  148. data/test/new_relic/agent/threading/backtrace_node_test.rb +1 -1
  149. data/test/new_relic/agent/threading/backtrace_service_test.rb +5 -5
  150. data/test/new_relic/agent/threading/thread_profile_test.rb +1 -1
  151. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +1 -1
  152. data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +1 -1
  153. data/test/new_relic/agent/transaction/pop_test.rb +1 -1
  154. data/test/new_relic/agent/transaction/slowest_sample_buffer_test.rb +1 -1
  155. data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +1 -1
  156. data/test/new_relic/agent/transaction_interrobang_test.rb +2 -3
  157. data/test/new_relic/agent/transaction_sample_builder_test.rb +16 -14
  158. data/test/new_relic/agent/transaction_sampler_test.rb +16 -21
  159. data/test/new_relic/agent/transaction_state_test.rb +1 -1
  160. data/test/new_relic/agent/transaction_test.rb +61 -1
  161. data/test/new_relic/agent/transaction_timings_test.rb +1 -1
  162. data/test/new_relic/agent/worker_loop_test.rb +1 -1
  163. data/test/new_relic/agent_test.rb +2 -3
  164. data/test/new_relic/cli/deployments_test.rb +3 -3
  165. data/test/new_relic/coerce_test.rb +1 -1
  166. data/test/new_relic/collection_helper_test.rb +1 -1
  167. data/test/new_relic/control/class_methods_test.rb +2 -2
  168. data/test/new_relic/control/frameworks/rails_test.rb +1 -1
  169. data/test/new_relic/control_test.rb +9 -4
  170. data/test/new_relic/dependency_detection_test.rb +1 -1
  171. data/test/new_relic/dispatcher_test.rb +1 -1
  172. data/test/new_relic/environment_report_test.rb +4 -6
  173. data/test/new_relic/fake_collector.rb +1 -158
  174. data/test/new_relic/framework_test.rb +2 -1
  175. data/test/new_relic/http_client_test_cases.rb +2 -3
  176. data/test/new_relic/json_wrapper_test.rb +77 -0
  177. data/test/new_relic/language_support_test.rb +1 -1
  178. data/test/new_relic/license_test.rb +2 -2
  179. data/test/new_relic/load_test.rb +2 -8
  180. data/test/new_relic/local_environment_test.rb +1 -1
  181. data/test/new_relic/metric_data_test.rb +1 -1
  182. data/test/new_relic/metric_parser/metric_parser_test.rb +1 -1
  183. data/test/new_relic/metric_spec_test.rb +1 -1
  184. data/test/new_relic/multiverse_helpers.rb +26 -30
  185. data/test/new_relic/noticed_error_test.rb +1 -1
  186. data/test/new_relic/rack/agent_hooks_test.rb +1 -1
  187. data/test/new_relic/rack/all_test.rb +1 -1
  188. data/test/new_relic/rack/browser_monitoring_test.rb +4 -2
  189. data/test/new_relic/rack/deferred_instrumentation_test.rb +3 -5
  190. data/test/new_relic/rack/developer_mode_helper_test.rb +1 -1
  191. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  192. data/test/new_relic/rack/error_collector_test.rb +8 -8
  193. data/test/new_relic/rack/transaction_reset_test.rb +35 -0
  194. data/test/new_relic/transaction_analysis/segment_summary_test.rb +2 -2
  195. data/test/new_relic/transaction_analysis_test.rb +1 -1
  196. data/test/new_relic/transaction_sample/composite_segment_test.rb +1 -1
  197. data/test/new_relic/transaction_sample/fake_segment_test.rb +2 -4
  198. data/test/new_relic/transaction_sample/segment_test.rb +3 -7
  199. data/test/new_relic/transaction_sample/summary_segment_test.rb +1 -1
  200. data/test/new_relic/transaction_sample_subtest_test.rb +1 -1
  201. data/test/new_relic/transaction_sample_test.rb +4 -6
  202. data/test/new_relic/version_number_test.rb +1 -1
  203. data/test/performance/lib/performance/instrumentation/gc_stats.rb +1 -1
  204. data/test/performance/lib/performance/json_reporter.rb +1 -1
  205. data/test/performance/suites/marshalling.rb +76 -0
  206. data/test/test_helper.rb +6 -39
  207. metadata +19 -12
  208. metadata.gz.sig +0 -0
  209. data/test/new_relic/helper_test.rb +0 -32
@@ -7,7 +7,7 @@ if defined?(::Rails)
7
7
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
8
8
  require 'new_relic/agent/instrumentation/action_controller_subscriber'
9
9
 
10
- class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Test::Unit::TestCase
10
+ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < MiniTest::Unit::TestCase
11
11
  class TestController
12
12
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
13
13
 
@@ -7,7 +7,7 @@ if defined?(::Rails)
7
7
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
8
8
  require 'new_relic/agent/instrumentation/action_view_subscriber'
9
9
 
10
- class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Test::Unit::TestCase
10
+ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < MiniTest::Unit::TestCase
11
11
  def setup
12
12
  @subscriber = NewRelic::Agent::Instrumentation::ActionViewSubscriber.new
13
13
  @stats_engine = NewRelic::Agent.instance.stats_engine
@@ -4,7 +4,7 @@
4
4
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
5
5
  require 'new_relic/agent/instrumentation/active_record_helper'
6
6
 
7
- class NewRelic::Agent::Instrumentation::ActiveRecordHelperTest < Test::Unit::TestCase
7
+ class NewRelic::Agent::Instrumentation::ActiveRecordHelperTest < MiniTest::Unit::TestCase
8
8
  include NewRelic::Agent::Instrumentation
9
9
 
10
10
  def test_metric_for_name_find
@@ -6,7 +6,7 @@ if defined?(::Rails)
6
6
 
7
7
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
8
8
 
9
- class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::Unit::TestCase
9
+ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < MiniTest::Unit::TestCase
10
10
  require 'active_record_fixtures'
11
11
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
12
12
 
@@ -78,499 +78,499 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
78
78
  end
79
79
  end
80
80
 
81
- def test_metric_names_jruby
82
- # fails due to a bug in rails 3 - log does not provide the correct
83
- # transaction type - it returns 'SQL' instead of 'Foo Create', for example.
84
- return if rails3? || !defined?(JRuby)
85
- expected = %W[
86
- ActiveRecord/all
87
- ActiveRecord/find
88
- ActiveRecord/ActiveRecordFixtures::Order/find
89
- Database/SQL/insert
90
- RemoteService/sql/#{adapter}/localhost
91
- ]
92
-
93
- if NewRelic::Control.instance.rails_version < '2.1.0'
94
- expected += %W[ActiveRecord/save ActiveRecord/ActiveRecordFixtures::Order/save]
95
- end
96
-
97
- assert_calls_metrics(*expected) do
98
- m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
99
- m = ActiveRecordFixtures::Order.find(m.id)
100
- m.id = 999
101
- m.save!
102
- end
103
- metrics = NewRelic::Agent.instance.stats_engine.metrics
104
-
105
- compare_metrics expected, metrics
106
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
107
- # zero because jruby uses a different mysql adapter
108
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 0)
109
- end
110
-
111
- def test_metric_names_sqlite
112
- # fails due to a bug in rails 3 - log does not provide the correct
113
- # transaction type - it returns 'SQL' instead of 'Foo Create', for example.
114
- return if rails3? || !isSqlite? || defined?(JRuby)
115
-
116
- expected = %W[
117
- ActiveRecord/all
118
- ActiveRecord/find
119
- ActiveRecord/ActiveRecordFixtures::Order/find
120
- ActiveRecord/create
121
- ActiveRecord/ActiveRecordFixtures::Order/create]
122
-
123
- if NewRelic::Control.instance.rails_version < '2.1.0'
124
- expected += %W[ActiveRecord/save ActiveRecord/ActiveRecordFixtures::Order/save]
125
- end
126
-
127
- assert_calls_metrics(*expected) do
128
- m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
129
- m = ActiveRecordFixtures::Order.find(m.id)
130
- m.id = 999
131
- m.save!
132
- end
133
- metrics = NewRelic::Agent.instance.stats_engine.metrics
134
-
135
- compare_metrics expected, metrics
136
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
137
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 1)
138
- end
139
-
140
- def test_metric_names_standard
141
- # fails due to a bug in rails 3 - log does not provide the correct
142
- # transaction type - it returns 'SQL' instead of 'Foo Create', for example.
143
- return if defined?(JRuby) || isSqlite?
144
-
145
- expected = %W[
146
- ActiveRecord/all
147
- ActiveRecord/find
148
- ActiveRecord/create
149
- ActiveRecord/ActiveRecordFixtures::Order/find
150
- ActiveRecord/ActiveRecordFixtures::Order/create
151
- Database/SQL/other
152
- RemoteService/sql/#{adapter}/localhost]
153
-
154
- if NewRelic::Control.instance.rails_version < '2.1.0'
155
- expected += ['ActiveRecord/save',
156
- 'ActiveRecord/ActiveRecordFixtures::Order/save']
157
- end
158
-
159
- if NewRelic::Control.instance.rails_version >= '3.0.0'
160
- expected << 'Database/SQL/insert'
161
- end
162
-
163
- if NewRelic::Control.instance.rails_version >= '4.0'
164
- expected << 'Database/SQL/update'
165
- end
166
-
167
- assert_calls_metrics(*expected) do
168
- m = ActiveRecordFixtures::Order.create :id => 1, :name => 'donkey'
169
- m = ActiveRecordFixtures::Order.find(m.id)
170
- m.id = 999
171
- m.save!
172
- end
173
-
174
- metrics = NewRelic::Agent.instance.stats_engine.metrics
175
-
176
- compare_metrics expected, metrics
177
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
178
- if NewRelic::Control.instance.rails_version < '3.0.0'
179
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 1)
180
- else
181
- check_metric_count("Database/SQL/insert", 1)
182
- end
183
- end
184
-
185
- def test_join_metrics_jruby
186
- return unless defined?(JRuby)
187
- return if rails3?
188
-
189
- expected_metrics = %W[
190
- ActiveRecord/all
191
- ActiveRecord/destroy
192
- ActiveRecord/ActiveRecordFixtures::Order/destroy
193
- Database/SQL/insert
194
- Database/SQL/delete
195
- Database/SQL/show
196
- ActiveRecord/find
197
- ActiveRecord/ActiveRecordFixtures::Order/find
198
- ActiveRecord/ActiveRecordFixtures::Shipment/find
199
- RemoteService/sql/#{adapter}/localhost
200
- ]
201
-
202
- assert_calls_metrics(*expected_metrics) do
203
- m = ActiveRecordFixtures::Order.create :name => 'jeff'
204
- m = ActiveRecordFixtures::Order.find(m.id)
205
- s = m.shipments.create
206
- m.shipments.to_a
207
- m.destroy
208
- end
209
-
210
- metrics = NewRelic::Agent.instance.stats_engine.metrics
211
-
212
- compare_metrics expected_metrics, metrics
213
-
214
- check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
215
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
216
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
217
- check_metric_count("Database/SQL/insert", 3)
218
- check_metric_count("Database/SQL/delete", 1)
219
- end
220
-
221
- def test_join_metrics_sqlite
222
- return if (defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3)
223
- return if defined?(JRuby)
224
- return unless isSqlite?
225
-
226
- expected_metrics = %W[
227
- ActiveRecord/all
228
- ActiveRecord/destroy
229
- ActiveRecord/ActiveRecordFixtures::Order/destroy
230
- Database/SQL/insert
231
- Database/SQL/delete
232
- ActiveRecord/find
233
- ActiveRecord/ActiveRecordFixtures::Order/find
234
- ActiveRecord/ActiveRecordFixtures::Shipment/find
235
- ActiveRecord/create
236
- ActiveRecord/ActiveRecordFixtures::Shipment/create
237
- ActiveRecord/ActiveRecordFixtures::Order/create
238
- ]
239
-
240
- assert_calls_metrics(*expected_metrics) do
241
- m = ActiveRecordFixtures::Order.create :name => 'jeff'
242
- m = ActiveRecordFixtures::Order.find(m.id)
243
- s = m.shipments.create
244
- m.shipments.to_a
245
- m.destroy
246
- end
247
-
248
- metrics = NewRelic::Agent.instance.stats_engine.metrics
249
- compare_metrics expected_metrics, metrics
250
- if !(defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise Edition/)
251
- check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
252
- end
253
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
254
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
255
- check_metric_count("Database/SQL/insert", 3)
256
- check_metric_count("Database/SQL/delete", 1)
257
- end
258
-
259
- def test_join_metrics_standard
260
- return if (defined?(Rails) && Rails::VERSION::MAJOR.to_i >= 3)
261
- return if defined?(JRuby) || isSqlite?
262
-
263
- expected_metrics = %W[
264
- ActiveRecord/all
265
- RemoteService/sql/#{adapter}/localhost
266
- ActiveRecord/destroy
267
- ActiveRecord/ActiveRecordFixtures::Order/destroy
268
- Database/SQL/insert
269
- Database/SQL/delete
270
- ActiveRecord/find
271
- ActiveRecord/ActiveRecordFixtures::Order/find
272
- ActiveRecord/ActiveRecordFixtures::Shipment/find
273
- Database/SQL/other
274
- Database/SQL/show
275
- ActiveRecord/create
276
- ActiveRecord/ActiveRecordFixtures::Shipment/create
277
- ActiveRecord/ActiveRecordFixtures::Order/create
278
- ]
279
-
280
- assert_calls_metrics(*expected_metrics) do
281
- m = ActiveRecordFixtures::Order.create :name => 'jeff'
282
- m = ActiveRecordFixtures::Order.find(m.id)
283
- s = m.shipments.create
284
- m.shipments.to_a
285
- m.destroy
286
- end
287
-
288
- metrics = NewRelic::Agent.instance.stats_engine.metrics
289
-
290
- compare_metrics expected_metrics, metrics
291
- if !(defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise Edition/)
292
- check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
293
- end
294
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
295
- check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
296
- check_metric_count("Database/SQL/insert", 1)
297
- check_metric_count("Database/SQL/delete", 1)
298
- end
299
-
300
- def test_direct_sql
301
- assert_nil NewRelic::Agent::Transaction.current
302
- assert_equal 0, NewRelic::Agent.instance.stats_engine.metrics.size, NewRelic::Agent.instance.stats_engine.metrics.inspect
303
-
304
- expected_metrics = %W[
305
- ActiveRecord/all
306
- Database/SQL/select
307
- RemoteService/sql/#{adapter}/localhost
308
- ]
309
-
310
- assert_calls_unscoped_metrics(*expected_metrics) do
311
- ActiveRecordFixtures::Order.connection.select_rows "select * from #{ActiveRecordFixtures::Order.table_name}"
312
- end
313
-
314
- metrics = NewRelic::Agent.instance.stats_engine.metrics
315
- compare_metrics(expected_metrics, metrics)
316
-
317
- check_unscoped_metric_count('Database/SQL/select', 1)
318
-
319
- end
320
-
321
- def test_other_sql
322
- expected_metrics = %W[
323
- ActiveRecord/all
324
- Database/SQL/other
325
- RemoteService/sql/#{adapter}/localhost
326
- ]
327
- assert_calls_unscoped_metrics(*expected_metrics) do
328
- ActiveRecordFixtures::Order.connection.execute "begin"
329
- end
330
-
331
- metrics = NewRelic::Agent.instance.stats_engine.metrics
332
-
333
- compare_metrics expected_metrics, metrics
334
- check_unscoped_metric_count('Database/SQL/other', 1)
335
- end
336
-
337
- def test_show_sql
338
- return if isSqlite?
339
- return if isPostgres?
340
-
341
- expected_metrics = %W[ActiveRecord/all Database/SQL/show RemoteService/sql/#{adapter}/localhost]
342
- assert_calls_metrics(*expected_metrics) do
343
- ActiveRecordFixtures::Order.connection.execute "show tables"
344
- end
345
- metrics = NewRelic::Agent.instance.stats_engine.metrics
346
- compare_metrics expected_metrics, metrics
347
- check_unscoped_metric_count('Database/SQL/show', 1)
348
- end
349
-
350
- def test_blocked_instrumentation
351
- ActiveRecordFixtures::Order.add_delay
352
- NewRelic::Agent.disable_all_tracing do
353
- perform_action_with_newrelic_trace :name => 'bogosity' do
354
- all_finder(ActiveRecordFixtures::Order)
355
- end
356
- end
357
- assert_nil NewRelic::Agent.instance.transaction_sampler.last_sample
358
- metrics = NewRelic::Agent.instance.stats_engine.metrics
359
- compare_metrics [], metrics
360
- end
361
-
362
- def test_run_explains
363
- perform_action_with_newrelic_trace :name => 'bogosity' do
364
- ActiveRecordFixtures::Order.add_delay
365
- all_finder(ActiveRecordFixtures::Order)
366
- end
367
-
368
- # that's a mouthful. perhaps we should ponder our API.
369
- segment = last_segment(NewRelic::Agent.instance.transaction_sampler.last_sample)
370
- regex = /^SELECT (["`]?#{ActiveRecordFixtures::Order.table_name}["`]?.)?\* FROM ["`]?#{ActiveRecordFixtures::Order.table_name}["`]?$/
371
- assert_match regex, segment.params[:sql].strip
372
- end
373
-
374
- def test_prepare_to_send
375
- with_config(:'transaction_tracer.explain_enabled' => true,
376
- :'transaction_tracer.explain_threshold' => 0.0) do
377
- perform_action_with_newrelic_trace :name => 'bogosity' do
378
- ActiveRecordFixtures::Order.add_delay
379
- all_finder(ActiveRecordFixtures::Order)
380
- end
381
- sample = NewRelic::Agent.instance.transaction_sampler.last_sample
382
- assert_not_nil sample
383
-
384
- includes_gc = false
385
- sample.each_segment {|s| includes_gc ||= s.metric_name =~ /GC/ }
386
-
387
- sql_segment = last_segment(sample)
388
- assert_not_nil sql_segment, sample.to_s
389
- assert_match /^SELECT /, sql_segment.params[:sql]
390
- assert sql_segment.duration > 0.0, "Segment duration must be greater than zero."
391
- sample = sample.prepare_to_send!
392
- sql_segment = last_segment(sample)
393
- assert_match /^SELECT /, sql_segment.params[:sql]
394
- explanations = sql_segment.params[:explain_plan]
395
- if (isMysql? || isPostgres?) && !NewRelic::LanguageSupport.using_engine?('jruby')
396
- assert_not_nil explanations, "No explains in segment: #{sql_segment}"
397
- assert_equal(2, explanations.size,
398
- "No explains in segment: #{sql_segment}")
399
- end
400
- end
401
- end
402
-
403
- def test_transaction_mysql
404
- return unless isMysql? && !defined?(JRuby)
405
-
406
- with_config(:record_sql => :obfuscated,
407
- :'transaction_tracer.explain_enabled' => true,
408
- :'transaction_tracer.explain_threshold' => 0.0) do
409
- ActiveRecordFixtures.setup
410
- sample = NewRelic::Agent.instance.transaction_sampler.reset!
411
- perform_action_with_newrelic_trace :name => 'bogosity' do
412
- ActiveRecordFixtures::Order.add_delay
413
- all_finder(ActiveRecordFixtures::Order)
414
- end
415
-
416
- sample = NewRelic::Agent.instance.transaction_sampler.last_sample
417
- sample = sample.prepare_to_send!
418
- segment = last_segment(sample)
419
- explanation = segment.params[:explain_plan]
420
- assert_not_nil explanation, "No explains in segment: #{segment}"
421
- assert_equal 2, explanation.size,"No explains in segment: #{segment}"
422
-
423
- assert_equal 10, explanation[0].size
424
- ['id', 'select_type', 'table'].each do |c|
425
- assert explanation[0].include?(c)
426
- end
427
- ['1', 'SIMPLE', ActiveRecordFixtures::Order.table_name].each do |c|
428
- assert explanation[1][0].include?(c)
429
- end
430
-
431
- s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
432
- assert_equal 1, s.call_count
433
- end
434
- end
435
-
436
- def test_transaction_postgres
437
- return unless isPostgres?
438
-
439
- with_config(:record_sql => :obfuscated,
440
- :'transaction_tracer.explain_enabled' => true,
441
- :'transaction_tracer.explain_threshold' => 0.0) do
442
- # note that our current test builds do not use postgres, this is
443
- # here strictly for troubleshooting, not CI builds
444
- sample = NewRelic::Agent.instance.transaction_sampler.reset!
445
- perform_action_with_newrelic_trace :name => 'bogosity' do
446
- ActiveRecordFixtures::Order.add_delay
447
- all_finder(ActiveRecordFixtures::Order)
448
- end
449
-
450
- sample = NewRelic::Agent.instance.transaction_sampler.last_sample
451
-
452
- sample = sample.prepare_to_send!
453
- segment = last_segment(sample)
454
- explanations = segment.params[:explain_plan]
455
-
456
- assert_not_nil explanations, "No explains in segment: #{segment}"
457
- assert_equal 1, explanations.size,"No explains in segment: #{segment}"
458
- assert_equal 1, explanations.first.size
459
-
460
- assert_equal("Explain Plan", explanations[0][0])
461
- assert_match /Seq Scan on test_data/, explanations[0][1].join(";")
462
-
463
- s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
464
- assert_equal 1, s.call_count
465
- end
466
- end
467
-
468
- def test_transaction_other
469
- return if isMysql? || isPostgres?
470
-
471
- with_config(:record_sql => :obfuscated,
472
- :'transaction_tracer.explain_enabled' => true,
473
- :'transaction_tracer.explain_threshold' => 0.0) do
474
- sample = NewRelic::Agent.instance.transaction_sampler.reset!
475
- perform_action_with_newrelic_trace :name => 'bogosity' do
476
- ActiveRecordFixtures::Order.add_delay
477
- all_finder(ActiveRecordFixtures::Order)
478
- end
479
-
480
- sample = NewRelic::Agent.instance.transaction_sampler.last_sample
481
-
482
- sample = sample.prepare_to_send!
483
- segment = last_segment(sample)
484
-
485
- s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
486
- assert_equal 1, s.call_count
487
- end
488
- end
489
-
490
- # These are only valid for rails 2.1 and later
491
- if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("2.1.0")
492
- ActiveRecordFixtures::Order.class_eval do
493
- if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("4")
494
- scope :jeffs, lambda { where(:name => 'Jeff') }
495
- elsif NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("3.1")
496
- scope :jeffs, :conditions => { :name => 'Jeff' }
497
- else
498
- named_scope :jeffs, :conditions => { :name => 'Jeff' }
499
- end
500
- end
501
- def test_named_scope
502
- ActiveRecordFixtures::Order.create :name => 'Jeff'
503
-
504
- find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
505
-
506
- check_metric_count(find_metric, 0)
507
- assert_calls_metrics(find_metric) do
508
- if NewRelic::Control.instance.rails_version >= "4"
509
- x = ActiveRecordFixtures::Order.jeffs.load
510
- else
511
- x = ActiveRecordFixtures::Order.jeffs.find(:all)
512
- end
513
- end
514
- check_metric_count(find_metric, 1)
515
- end
516
- end
517
-
518
- # This is to make sure the all metric is recorded for exceptional cases
519
- def test_error_handling
520
- # have the AR select throw an error
521
- ActiveRecordFixtures::Order.connection.stubs(:log_info).with do | sql, x, y |
522
- raise "Error" if sql =~ /select/
523
- true
524
- end
525
-
526
- in_web_transaction do
527
- begin
528
- ActiveRecordFixtures::Order.connection.select_rows "select * from #{ActiveRecordFixtures::Order.table_name}"
529
- rescue RuntimeError => e
530
- # catch only the error we raise above
531
- raise unless e.message == 'Error'
532
- end
533
- end
534
-
535
- assert_metrics_recorded(
536
- 'ActiveRecord/all' => { :call_count => 1 },
537
- 'Database/SQL/select' => { :call_count => 1 }
538
- )
539
-
540
- if !NewRelic::LanguageSupport.using_engine?('jruby')
541
- assert_metrics_recorded("RemoteService/sql/#{adapter}/localhost" => { :call_count => 1 })
542
- end
543
- end
544
-
545
- def test_rescue_handling
546
- # Not sure why we get a transaction error with sqlite
547
- return if isSqlite?
548
-
549
- begin
550
- ActiveRecordFixtures::Order.transaction do
551
- raise ActiveRecord::ActiveRecordError.new('preserve-me!')
552
- end
553
- rescue ActiveRecord::ActiveRecordError => e
554
- assert_equal 'preserve-me!', e.message
555
- end
556
- end
557
-
558
- def test_remote_service_metric_respects_dynamic_connection_config
559
- return unless isMysql? && !NewRelic::LanguageSupport.using_engine?('jruby')
560
-
561
- ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
562
- assert_metrics_recorded(["RemoteService/sql/#{adapter}/localhost"])
563
-
564
- config = ActiveRecordFixtures::Shipment.connection.instance_eval { @config }
565
- config[:host] = '127.0.0.1'
566
- connection = ActiveRecordFixtures::Shipment.establish_connection(config)
567
-
568
- ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
569
- assert_metrics_recorded(["RemoteService/sql/#{adapter}/127.0.0.1"])
570
-
571
- config[:host] = 'localhost'
572
- ActiveRecordFixtures::Shipment.establish_connection(config)
573
- end
81
+ #def test_metric_names_jruby
82
+ # # fails due to a bug in rails 3 - log does not provide the correct
83
+ # # transaction type - it returns 'SQL' instead of 'Foo Create', for example.
84
+ # return if rails3? || !defined?(JRuby)
85
+ # expected = %W[
86
+ # ActiveRecord/all
87
+ # ActiveRecord/find
88
+ # ActiveRecord/ActiveRecordFixtures::Order/find
89
+ # Database/SQL/insert
90
+ # RemoteService/sql/#{adapter}/localhost
91
+ # ]
92
+
93
+ # if NewRelic::Control.instance.rails_version < '2.1.0'
94
+ # expected += %W[ActiveRecord/save ActiveRecord/ActiveRecordFixtures::Order/save]
95
+ # end
96
+
97
+ # assert_calls_metrics(*expected) do
98
+ # m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
99
+ # m = ActiveRecordFixtures::Order.find(m.id)
100
+ # m.id = 999
101
+ # m.save!
102
+ # end
103
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
104
+
105
+ # compare_metrics expected, metrics
106
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
107
+ # # zero because jruby uses a different mysql adapter
108
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 0)
109
+ #end
110
+
111
+ #def test_metric_names_sqlite
112
+ # # fails due to a bug in rails 3 - log does not provide the correct
113
+ # # transaction type - it returns 'SQL' instead of 'Foo Create', for example.
114
+ # return if rails3? || !isSqlite? || defined?(JRuby)
115
+
116
+ # expected = %W[
117
+ # ActiveRecord/all
118
+ # ActiveRecord/find
119
+ # ActiveRecord/ActiveRecordFixtures::Order/find
120
+ # ActiveRecord/create
121
+ # ActiveRecord/ActiveRecordFixtures::Order/create]
122
+
123
+ # if NewRelic::Control.instance.rails_version < '2.1.0'
124
+ # expected += %W[ActiveRecord/save ActiveRecord/ActiveRecordFixtures::Order/save]
125
+ # end
126
+
127
+ # assert_calls_metrics(*expected) do
128
+ # m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
129
+ # m = ActiveRecordFixtures::Order.find(m.id)
130
+ # m.id = 999
131
+ # m.save!
132
+ # end
133
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
134
+
135
+ # compare_metrics expected, metrics
136
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
137
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 1)
138
+ #end
139
+
140
+ #def test_metric_names_standard
141
+ # # fails due to a bug in rails 3 - log does not provide the correct
142
+ # # transaction type - it returns 'SQL' instead of 'Foo Create', for example.
143
+ # return if defined?(JRuby) || isSqlite?
144
+
145
+ # expected = %W[
146
+ # ActiveRecord/all
147
+ # ActiveRecord/find
148
+ # ActiveRecord/create
149
+ # ActiveRecord/ActiveRecordFixtures::Order/find
150
+ # ActiveRecord/ActiveRecordFixtures::Order/create
151
+ # Database/SQL/other
152
+ # RemoteService/sql/#{adapter}/localhost]
153
+
154
+ # if NewRelic::Control.instance.rails_version < '2.1.0'
155
+ # expected += ['ActiveRecord/save',
156
+ # 'ActiveRecord/ActiveRecordFixtures::Order/save']
157
+ # end
158
+
159
+ # if NewRelic::Control.instance.rails_version >= '3.0.0'
160
+ # expected << 'Database/SQL/insert'
161
+ # end
162
+
163
+ # if NewRelic::Control.instance.rails_version >= '4.0'
164
+ # expected << 'Database/SQL/update'
165
+ # end
166
+
167
+ # assert_calls_metrics(*expected) do
168
+ # m = ActiveRecordFixtures::Order.create :id => 1, :name => 'donkey'
169
+ # m = ActiveRecordFixtures::Order.find(m.id)
170
+ # m.id = 999
171
+ # m.save!
172
+ # end
173
+
174
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
175
+
176
+ # compare_metrics expected, metrics
177
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
178
+ # if NewRelic::Control.instance.rails_version < '3.0.0'
179
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 1)
180
+ # else
181
+ # check_metric_count("Database/SQL/insert", 1)
182
+ # end
183
+ #end
184
+
185
+ #def test_join_metrics_jruby
186
+ # return unless defined?(JRuby)
187
+ # return if rails3?
188
+
189
+ # expected_metrics = %W[
190
+ # ActiveRecord/all
191
+ # ActiveRecord/destroy
192
+ # ActiveRecord/ActiveRecordFixtures::Order/destroy
193
+ # Database/SQL/insert
194
+ # Database/SQL/delete
195
+ # Database/SQL/show
196
+ # ActiveRecord/find
197
+ # ActiveRecord/ActiveRecordFixtures::Order/find
198
+ # ActiveRecord/ActiveRecordFixtures::Shipment/find
199
+ # RemoteService/sql/#{adapter}/localhost
200
+ # ]
201
+
202
+ # assert_calls_metrics(*expected_metrics) do
203
+ # m = ActiveRecordFixtures::Order.create :name => 'jeff'
204
+ # m = ActiveRecordFixtures::Order.find(m.id)
205
+ # s = m.shipments.create
206
+ # m.shipments.to_a
207
+ # m.destroy
208
+ # end
209
+
210
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
211
+
212
+ # compare_metrics expected_metrics, metrics
213
+
214
+ # check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
215
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
216
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
217
+ # check_metric_count("Database/SQL/insert", 3)
218
+ # check_metric_count("Database/SQL/delete", 1)
219
+ #end
220
+
221
+ #def test_join_metrics_sqlite
222
+ # return if (defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3)
223
+ # return if defined?(JRuby)
224
+ # return unless isSqlite?
225
+
226
+ # expected_metrics = %W[
227
+ # ActiveRecord/all
228
+ # ActiveRecord/destroy
229
+ # ActiveRecord/ActiveRecordFixtures::Order/destroy
230
+ # Database/SQL/insert
231
+ # Database/SQL/delete
232
+ # ActiveRecord/find
233
+ # ActiveRecord/ActiveRecordFixtures::Order/find
234
+ # ActiveRecord/ActiveRecordFixtures::Shipment/find
235
+ # ActiveRecord/create
236
+ # ActiveRecord/ActiveRecordFixtures::Shipment/create
237
+ # ActiveRecord/ActiveRecordFixtures::Order/create
238
+ # ]
239
+
240
+ # assert_calls_metrics(*expected_metrics) do
241
+ # m = ActiveRecordFixtures::Order.create :name => 'jeff'
242
+ # m = ActiveRecordFixtures::Order.find(m.id)
243
+ # s = m.shipments.create
244
+ # m.shipments.to_a
245
+ # m.destroy
246
+ # end
247
+
248
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
249
+ # compare_metrics expected_metrics, metrics
250
+ # if !(defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise Edition/)
251
+ # check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
252
+ # end
253
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
254
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
255
+ # check_metric_count("Database/SQL/insert", 3)
256
+ # check_metric_count("Database/SQL/delete", 1)
257
+ #end
258
+
259
+ #def test_join_metrics_standard
260
+ # return if (defined?(Rails) && Rails::VERSION::MAJOR.to_i >= 3)
261
+ # return if defined?(JRuby) || isSqlite?
262
+
263
+ # expected_metrics = %W[
264
+ # ActiveRecord/all
265
+ # RemoteService/sql/#{adapter}/localhost
266
+ # ActiveRecord/destroy
267
+ # ActiveRecord/ActiveRecordFixtures::Order/destroy
268
+ # Database/SQL/insert
269
+ # Database/SQL/delete
270
+ # ActiveRecord/find
271
+ # ActiveRecord/ActiveRecordFixtures::Order/find
272
+ # ActiveRecord/ActiveRecordFixtures::Shipment/find
273
+ # Database/SQL/other
274
+ # Database/SQL/show
275
+ # ActiveRecord/create
276
+ # ActiveRecord/ActiveRecordFixtures::Shipment/create
277
+ # ActiveRecord/ActiveRecordFixtures::Order/create
278
+ # ]
279
+
280
+ # assert_calls_metrics(*expected_metrics) do
281
+ # m = ActiveRecordFixtures::Order.create :name => 'jeff'
282
+ # m = ActiveRecordFixtures::Order.find(m.id)
283
+ # s = m.shipments.create
284
+ # m.shipments.to_a
285
+ # m.destroy
286
+ # end
287
+
288
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
289
+
290
+ # compare_metrics expected_metrics, metrics
291
+ # if !(defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise Edition/)
292
+ # check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
293
+ # end
294
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
295
+ # check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
296
+ # check_metric_count("Database/SQL/insert", 1)
297
+ # check_metric_count("Database/SQL/delete", 1)
298
+ #end
299
+
300
+ #def test_direct_sql
301
+ # assert_nil NewRelic::Agent::Transaction.current
302
+ # assert_equal 0, NewRelic::Agent.instance.stats_engine.metrics.size, NewRelic::Agent.instance.stats_engine.metrics.inspect
303
+
304
+ # expected_metrics = %W[
305
+ # ActiveRecord/all
306
+ # Database/SQL/select
307
+ # RemoteService/sql/#{adapter}/localhost
308
+ # ]
309
+
310
+ # assert_calls_unscoped_metrics(*expected_metrics) do
311
+ # ActiveRecordFixtures::Order.connection.select_rows "select * from #{ActiveRecordFixtures::Order.table_name}"
312
+ # end
313
+
314
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
315
+ # compare_metrics(expected_metrics, metrics)
316
+
317
+ # check_unscoped_metric_count('Database/SQL/select', 1)
318
+
319
+ #end
320
+
321
+ #def test_other_sql
322
+ # expected_metrics = %W[
323
+ # ActiveRecord/all
324
+ # Database/SQL/other
325
+ # RemoteService/sql/#{adapter}/localhost
326
+ # ]
327
+ # assert_calls_unscoped_metrics(*expected_metrics) do
328
+ # ActiveRecordFixtures::Order.connection.execute "begin"
329
+ # end
330
+
331
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
332
+
333
+ # compare_metrics expected_metrics, metrics
334
+ # check_unscoped_metric_count('Database/SQL/other', 1)
335
+ #end
336
+
337
+ #def test_show_sql
338
+ # return if isSqlite?
339
+ # return if isPostgres?
340
+
341
+ # expected_metrics = %W[ActiveRecord/all Database/SQL/show RemoteService/sql/#{adapter}/localhost]
342
+ # assert_calls_metrics(*expected_metrics) do
343
+ # ActiveRecordFixtures::Order.connection.execute "show tables"
344
+ # end
345
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
346
+ # compare_metrics expected_metrics, metrics
347
+ # check_unscoped_metric_count('Database/SQL/show', 1)
348
+ #end
349
+
350
+ #def test_blocked_instrumentation
351
+ # ActiveRecordFixtures::Order.add_delay
352
+ # NewRelic::Agent.disable_all_tracing do
353
+ # perform_action_with_newrelic_trace :name => 'bogosity' do
354
+ # all_finder(ActiveRecordFixtures::Order)
355
+ # end
356
+ # end
357
+ # assert_nil NewRelic::Agent.instance.transaction_sampler.last_sample
358
+ # metrics = NewRelic::Agent.instance.stats_engine.metrics
359
+ # compare_metrics [], metrics
360
+ #end
361
+
362
+ #def test_run_explains
363
+ # perform_action_with_newrelic_trace :name => 'bogosity' do
364
+ # ActiveRecordFixtures::Order.add_delay
365
+ # all_finder(ActiveRecordFixtures::Order)
366
+ # end
367
+
368
+ # # that's a mouthful. perhaps we should ponder our API.
369
+ # segment = last_segment(NewRelic::Agent.instance.transaction_sampler.last_sample)
370
+ # regex = /^SELECT (["`]?#{ActiveRecordFixtures::Order.table_name}["`]?.)?\* FROM ["`]?#{ActiveRecordFixtures::Order.table_name}["`]?$/
371
+ # assert_match regex, segment.params[:sql].strip
372
+ #end
373
+
374
+ #def test_prepare_to_send
375
+ # with_config(:'transaction_tracer.explain_enabled' => true,
376
+ # :'transaction_tracer.explain_threshold' => 0.0) do
377
+ # perform_action_with_newrelic_trace :name => 'bogosity' do
378
+ # ActiveRecordFixtures::Order.add_delay
379
+ # all_finder(ActiveRecordFixtures::Order)
380
+ # end
381
+ # sample = NewRelic::Agent.instance.transaction_sampler.last_sample
382
+ # refute_nil sample
383
+
384
+ # includes_gc = false
385
+ # sample.each_segment {|s| includes_gc ||= s.metric_name =~ /GC/ }
386
+
387
+ # sql_segment = last_segment(sample)
388
+ # refute_nil sql_segment, sample.to_s
389
+ # assert_match /^SELECT /, sql_segment.params[:sql]
390
+ # assert sql_segment.duration > 0.0, "Segment duration must be greater than zero."
391
+ # sample = sample.prepare_to_send!
392
+ # sql_segment = last_segment(sample)
393
+ # assert_match /^SELECT /, sql_segment.params[:sql]
394
+ # explanations = sql_segment.params[:explain_plan]
395
+ # if (isMysql? || isPostgres?) && !NewRelic::LanguageSupport.using_engine?('jruby')
396
+ # refute_nil explanations, "No explains in segment: #{sql_segment}"
397
+ # assert_equal(2, explanations.size,
398
+ # "No explains in segment: #{sql_segment}")
399
+ # end
400
+ # end
401
+ #end
402
+
403
+ #def test_transaction_mysql
404
+ # return unless isMysql? && !defined?(JRuby)
405
+
406
+ # with_config(:record_sql => :obfuscated,
407
+ # :'transaction_tracer.explain_enabled' => true,
408
+ # :'transaction_tracer.explain_threshold' => 0.0) do
409
+ # ActiveRecordFixtures.setup
410
+ # sample = NewRelic::Agent.instance.transaction_sampler.reset!
411
+ # perform_action_with_newrelic_trace :name => 'bogosity' do
412
+ # ActiveRecordFixtures::Order.add_delay
413
+ # all_finder(ActiveRecordFixtures::Order)
414
+ # end
415
+
416
+ # sample = NewRelic::Agent.instance.transaction_sampler.last_sample
417
+ # sample = sample.prepare_to_send!
418
+ # segment = last_segment(sample)
419
+ # explanation = segment.params[:explain_plan]
420
+ # refute_nil explanation, "No explains in segment: #{segment}"
421
+ # assert_equal 2, explanation.size,"No explains in segment: #{segment}"
422
+
423
+ # assert_equal 10, explanation[0].size
424
+ # ['id', 'select_type', 'table'].each do |c|
425
+ # assert explanation[0].include?(c)
426
+ # end
427
+ # ['1', 'SIMPLE', ActiveRecordFixtures::Order.table_name].each do |c|
428
+ # assert explanation[1][0].include?(c)
429
+ # end
430
+
431
+ # s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
432
+ # assert_equal 1, s.call_count
433
+ # end
434
+ #end
435
+
436
+ #def test_transaction_postgres
437
+ # return unless isPostgres?
438
+
439
+ # with_config(:record_sql => :obfuscated,
440
+ # :'transaction_tracer.explain_enabled' => true,
441
+ # :'transaction_tracer.explain_threshold' => 0.0) do
442
+ # # note that our current test builds do not use postgres, this is
443
+ # # here strictly for troubleshooting, not CI builds
444
+ # sample = NewRelic::Agent.instance.transaction_sampler.reset!
445
+ # perform_action_with_newrelic_trace :name => 'bogosity' do
446
+ # ActiveRecordFixtures::Order.add_delay
447
+ # all_finder(ActiveRecordFixtures::Order)
448
+ # end
449
+
450
+ # sample = NewRelic::Agent.instance.transaction_sampler.last_sample
451
+
452
+ # sample = sample.prepare_to_send!
453
+ # segment = last_segment(sample)
454
+ # explanations = segment.params[:explain_plan]
455
+
456
+ # refute_nil explanations, "No explains in segment: #{segment}"
457
+ # assert_equal 1, explanations.size,"No explains in segment: #{segment}"
458
+ # assert_equal 1, explanations.first.size
459
+
460
+ # assert_equal("Explain Plan", explanations[0][0])
461
+ # assert_match /Seq Scan on test_data/, explanations[0][1].join(";")
462
+
463
+ # s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
464
+ # assert_equal 1, s.call_count
465
+ # end
466
+ #end
467
+
468
+ #def test_transaction_other
469
+ # return if isMysql? || isPostgres?
470
+
471
+ # with_config(:record_sql => :obfuscated,
472
+ # :'transaction_tracer.explain_enabled' => true,
473
+ # :'transaction_tracer.explain_threshold' => 0.0) do
474
+ # sample = NewRelic::Agent.instance.transaction_sampler.reset!
475
+ # perform_action_with_newrelic_trace :name => 'bogosity' do
476
+ # ActiveRecordFixtures::Order.add_delay
477
+ # all_finder(ActiveRecordFixtures::Order)
478
+ # end
479
+
480
+ # sample = NewRelic::Agent.instance.transaction_sampler.last_sample
481
+
482
+ # sample = sample.prepare_to_send!
483
+ # segment = last_segment(sample)
484
+
485
+ # s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
486
+ # assert_equal 1, s.call_count
487
+ # end
488
+ #end
489
+
490
+ ## These are only valid for rails 2.1 and later
491
+ #if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("2.1.0")
492
+ # ActiveRecordFixtures::Order.class_eval do
493
+ # if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("4")
494
+ # scope :jeffs, lambda { where(:name => 'Jeff') }
495
+ # elsif NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("3.1")
496
+ # scope :jeffs, :conditions => { :name => 'Jeff' }
497
+ # else
498
+ # named_scope :jeffs, :conditions => { :name => 'Jeff' }
499
+ # end
500
+ # end
501
+ # def test_named_scope
502
+ # ActiveRecordFixtures::Order.create :name => 'Jeff'
503
+
504
+ # find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
505
+
506
+ # check_metric_count(find_metric, 0)
507
+ # assert_calls_metrics(find_metric) do
508
+ # if NewRelic::Control.instance.rails_version >= "4"
509
+ # x = ActiveRecordFixtures::Order.jeffs.load
510
+ # else
511
+ # x = ActiveRecordFixtures::Order.jeffs.find(:all)
512
+ # end
513
+ # end
514
+ # check_metric_count(find_metric, 1)
515
+ # end
516
+ #end
517
+
518
+ ## This is to make sure the all metric is recorded for exceptional cases
519
+ #def test_error_handling
520
+ # # have the AR select throw an error
521
+ # ActiveRecordFixtures::Order.connection.stubs(:log_info).with do | sql, x, y |
522
+ # raise "Error" if sql =~ /select/
523
+ # true
524
+ # end
525
+
526
+ # in_web_transaction do
527
+ # begin
528
+ # ActiveRecordFixtures::Order.connection.select_rows "select * from #{ActiveRecordFixtures::Order.table_name}"
529
+ # rescue RuntimeError => e
530
+ # # catch only the error we raise above
531
+ # raise unless e.message == 'Error'
532
+ # end
533
+ # end
534
+
535
+ # assert_metrics_recorded(
536
+ # 'ActiveRecord/all' => { :call_count => 1 },
537
+ # 'Database/SQL/select' => { :call_count => 1 }
538
+ # )
539
+
540
+ # if !NewRelic::LanguageSupport.using_engine?('jruby')
541
+ # assert_metrics_recorded("RemoteService/sql/#{adapter}/localhost" => { :call_count => 1 })
542
+ # end
543
+ #end
544
+
545
+ #def test_rescue_handling
546
+ # # Not sure why we get a transaction error with sqlite
547
+ # return if isSqlite?
548
+
549
+ # begin
550
+ # ActiveRecordFixtures::Order.transaction do
551
+ # raise ActiveRecord::ActiveRecordError.new('preserve-me!')
552
+ # end
553
+ # rescue ActiveRecord::ActiveRecordError => e
554
+ # assert_equal 'preserve-me!', e.message
555
+ # end
556
+ #end
557
+
558
+ #def test_remote_service_metric_respects_dynamic_connection_config
559
+ # return unless isMysql? && !NewRelic::LanguageSupport.using_engine?('jruby')
560
+
561
+ # ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
562
+ # assert_metrics_recorded(["RemoteService/sql/#{adapter}/localhost"])
563
+
564
+ # config = ActiveRecordFixtures::Shipment.connection.instance_eval { @config }
565
+ # config[:host] = '127.0.0.1'
566
+ # connection = ActiveRecordFixtures::Shipment.establish_connection(config)
567
+
568
+ # ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
569
+ # assert_metrics_recorded(["RemoteService/sql/#{adapter}/127.0.0.1"])
570
+
571
+ # config[:host] = 'localhost'
572
+ # ActiveRecordFixtures::Shipment.establish_connection(config)
573
+ #end
574
574
 
575
575
  private
576
576
 
@@ -617,7 +617,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
617
617
  end
618
618
 
619
619
 
620
- class ActiveRecordQueryEncodingTest < Test::Unit::TestCase
620
+ class ActiveRecordQueryEncodingTest < MiniTest::Unit::TestCase
621
621
 
622
622
  class DatabaseAdapter
623
623
  # we patch in here