newrelic_rpm 3.10.0.279 → 3.11.0.283

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +61 -0
  3. data/lib/new_relic/agent.rb +14 -8
  4. data/lib/new_relic/agent/agent.rb +43 -28
  5. data/lib/new_relic/agent/agent_logger.rb +21 -20
  6. data/lib/new_relic/agent/configuration/default_source.rb +31 -1
  7. data/lib/new_relic/agent/database.rb +2 -1
  8. data/lib/new_relic/agent/datastores.rb +177 -0
  9. data/lib/new_relic/agent/datastores/metric_helper.rb +85 -0
  10. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +11 -20
  11. data/lib/new_relic/agent/deprecator.rb +18 -0
  12. data/lib/new_relic/agent/instrumentation/active_record.rb +20 -35
  13. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +116 -57
  14. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -20
  15. data/lib/new_relic/agent/instrumentation/data_mapper.rb +104 -172
  16. data/lib/new_relic/agent/instrumentation/memcache.rb +104 -52
  17. data/lib/new_relic/agent/instrumentation/metric_frame.rb +9 -0
  18. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +15 -2
  19. data/lib/new_relic/agent/instrumentation/mongo.rb +5 -18
  20. data/lib/new_relic/agent/instrumentation/sequel_helper.rb +36 -0
  21. data/lib/new_relic/agent/new_relic_service.rb +4 -0
  22. data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -17
  23. data/lib/new_relic/agent/threading/backtrace_service.rb +28 -5
  24. data/lib/new_relic/agent/transaction.rb +63 -34
  25. data/lib/new_relic/agent/transaction_event_aggregator.rb +0 -4
  26. data/lib/new_relic/agent/transaction_sampler.rb +11 -5
  27. data/lib/new_relic/rack/error_collector.rb +0 -1
  28. data/lib/new_relic/version.rb +1 -1
  29. data/lib/sequel/extensions/newrelic_instrumentation.rb +28 -56
  30. data/lib/sequel/plugins/newrelic_instrumentation.rb +28 -45
  31. data/newrelic_rpm.gemspec +0 -7
  32. data/test/agent_helper.rb +35 -16
  33. data/test/environments/rails31/Gemfile +1 -0
  34. data/test/environments/rails32/Gemfile +1 -0
  35. data/test/helpers/mongo_metric_builder.rb +2 -3
  36. data/test/multiverse/lib/multiverse/output_collector.rb +24 -9
  37. data/test/multiverse/lib/multiverse/suite.rb +5 -0
  38. data/test/multiverse/suites/active_record/Envfile +6 -4
  39. data/test/multiverse/suites/active_record/active_record_test.rb +32 -73
  40. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +0 -1
  41. data/test/multiverse/suites/activemerchant/activemerchant_test.rb +0 -3
  42. data/test/multiverse/suites/agent_only/agent_run_id_handling_test.rb +0 -1
  43. data/test/multiverse/suites/agent_only/audit_log_test.rb +0 -1
  44. data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +0 -2
  45. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +0 -1
  46. data/test/multiverse/suites/agent_only/custom_analytics_events_test.rb +0 -2
  47. data/test/multiverse/suites/agent_only/custom_queue_time_test.rb +0 -1
  48. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +0 -2
  49. data/test/multiverse/suites/agent_only/exclusive_time_test.rb +0 -2
  50. data/test/multiverse/suites/agent_only/harvest_timestamps_test.rb +0 -1
  51. data/test/multiverse/suites/agent_only/http_response_code_test.rb +0 -1
  52. data/test/multiverse/suites/agent_only/keepalive_test.rb +0 -1
  53. data/test/multiverse/suites/agent_only/key_transactions_test.rb +54 -9
  54. data/test/multiverse/suites/agent_only/labels_test.rb +0 -2
  55. data/test/multiverse/suites/agent_only/logging_test.rb +0 -1
  56. data/test/multiverse/suites/agent_only/marshaling_test.rb +0 -1
  57. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +0 -2
  58. data/test/multiverse/suites/agent_only/rename_rule_test.rb +5 -7
  59. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +0 -1
  60. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +0 -2
  61. data/test/multiverse/suites/agent_only/ssl_test.rb +0 -2
  62. data/test/multiverse/suites/agent_only/synthetics_test.rb +0 -1
  63. data/test/multiverse/suites/agent_only/testing_app.rb +21 -0
  64. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +1 -2
  65. data/test/multiverse/suites/agent_only/transaction_ignoring_test.rb +0 -2
  66. data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +0 -1
  67. data/test/multiverse/suites/agent_only/xray_sessions_test.rb +69 -34
  68. data/test/multiverse/suites/capistrano/deployment_test.rb +0 -1
  69. data/test/multiverse/suites/capistrano2/deployment_test.rb +0 -1
  70. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +0 -2
  71. data/test/multiverse/suites/curb/curb_test.rb +0 -2
  72. data/test/multiverse/suites/datamapper/Envfile +26 -3
  73. data/test/multiverse/suites/datamapper/config/newrelic.yml +1 -0
  74. data/test/multiverse/suites/datamapper/datamapper_test.rb +271 -37
  75. data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +0 -1
  76. data/test/multiverse/suites/delayed_job/Envfile +31 -8
  77. data/test/multiverse/suites/delayed_job/delayed_job_sampler_test.rb +0 -3
  78. data/test/multiverse/suites/delayed_job/unsupported_backend_test.rb +0 -3
  79. data/test/multiverse/suites/excon/excon_test.rb +0 -2
  80. data/test/multiverse/suites/grape/grape_test.rb +0 -3
  81. data/test/multiverse/suites/grape/grape_versioning_test.rb +0 -3
  82. data/test/multiverse/suites/grape/unsupported_version_test.rb +0 -3
  83. data/test/multiverse/suites/high_security/high_security_test.rb +0 -1
  84. data/test/multiverse/suites/httpclient/httpclient_test.rb +0 -2
  85. data/test/multiverse/suites/json/json_test.rb +0 -1
  86. data/test/multiverse/suites/marshalling/marshalling_test.rb +0 -1
  87. data/test/multiverse/suites/memcached/Envfile +52 -0
  88. data/test/multiverse/suites/memcached/dalli_test.rb +89 -0
  89. data/test/multiverse/suites/memcached/memcache_client_test.rb +25 -0
  90. data/test/multiverse/suites/memcached/memcache_test_cases.rb +302 -0
  91. data/test/multiverse/suites/memcached/memcached_test.rb +159 -0
  92. data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +26 -17
  93. data/test/multiverse/suites/mongo/mongo_connection_test.rb +0 -1
  94. data/test/multiverse/suites/mongo/mongo_instrumentation_test.rb +0 -1
  95. data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +0 -1
  96. data/test/multiverse/suites/net_http/net_http_test.rb +0 -2
  97. data/test/multiverse/suites/padrino/padrino_test.rb +0 -3
  98. data/test/multiverse/suites/rack/http_response_code_test.rb +0 -1
  99. data/test/multiverse/suites/rack/nested_non_rack_app_test.rb +1 -1
  100. data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +12 -12
  101. data/test/multiverse/suites/rack/rack_cascade_test.rb +0 -1
  102. data/test/multiverse/suites/rack/rack_env_mutation_test.rb +0 -1
  103. data/test/multiverse/suites/rack/rack_parameter_filtering_test.rb +0 -1
  104. data/test/multiverse/suites/rack/rack_unsupported_version_test.rb +0 -2
  105. data/test/multiverse/suites/rack/url_map_test.rb +3 -2
  106. data/test/multiverse/suites/rails/Envfile +3 -0
  107. data/test/multiverse/suites/rails/activejob_test.rb +0 -1
  108. data/test/multiverse/suites/rails/app.rb +0 -1
  109. data/test/multiverse/suites/rails/parameter_capture_test.rb +13 -0
  110. data/test/multiverse/suites/rails/rails3_app/app_rails3_plus.rb +5 -0
  111. data/test/multiverse/suites/rails/transaction_ignoring_test.rb +0 -2
  112. data/test/multiverse/suites/resque/instrumentation_test.rb +0 -2
  113. data/test/multiverse/suites/resque/resque_marshalling_test.rb +0 -1
  114. data/test/multiverse/suites/sequel/sequel_extension_test.rb +135 -0
  115. data/test/multiverse/suites/sequel/sequel_helpers.rb +62 -0
  116. data/test/multiverse/suites/sequel/sequel_plugin_test.rb +230 -0
  117. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +0 -2
  118. data/test/multiverse/suites/sinatra/ignoring_test.rb +0 -2
  119. data/test/multiverse/suites/sinatra/nested_middleware_test.rb +0 -2
  120. data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +0 -1
  121. data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +0 -2
  122. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +14 -12
  123. data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +0 -1
  124. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +0 -2
  125. data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +0 -2
  126. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +0 -2
  127. data/test/multiverse/suites/yajl/yajl_test.rb +0 -1
  128. data/test/new_relic/agent/agent/start_test.rb +2 -2
  129. data/test/new_relic/agent/agent_logger_test.rb +6 -3
  130. data/test/new_relic/agent/datastores/metric_helper_test.rb +61 -0
  131. data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +20 -21
  132. data/test/new_relic/agent/datastores_test.rb +195 -0
  133. data/test/new_relic/agent/deprecator_test.rb +52 -0
  134. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +20 -26
  135. data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +58 -53
  136. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +7 -20
  137. data/test/new_relic/agent/instrumentation/middleware_proxy_test.rb +19 -0
  138. data/test/new_relic/agent/instrumentation/sequel_helper_test.rb +36 -0
  139. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +1 -0
  140. data/test/new_relic/agent/method_tracer_test.rb +3 -4
  141. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
  142. data/test/new_relic/agent/threading/backtrace_service_test.rb +29 -4
  143. data/test/new_relic/agent/transaction_event_aggregator_test.rb +0 -4
  144. data/test/new_relic/agent/transaction_test.rb +100 -2
  145. data/test/new_relic/agent_test.rb +3 -3
  146. data/test/new_relic/http_client_test_cases.rb +0 -1
  147. data/test/new_relic/multiverse_helpers.rb +7 -0
  148. data/test/new_relic/transaction_ignoring_test_cases.rb +0 -2
  149. data/test/new_relic/transaction_sample_test.rb +11 -2
  150. data/test/performance/README.md +37 -17
  151. data/test/performance/lib/performance.rb +1 -0
  152. data/test/performance/lib/performance/baseline_compare_reporter.rb +11 -7
  153. data/test/performance/lib/performance/console_reporter.rb +29 -5
  154. data/test/performance/lib/performance/formatting_helpers.rb +22 -0
  155. data/test/performance/lib/performance/instrumentation/stackprof.rb +11 -1
  156. data/test/performance/lib/performance/result.rb +17 -6
  157. data/test/performance/lib/performance/runner.rb +7 -3
  158. data/test/performance/lib/performance/test_case.rb +89 -21
  159. data/test/performance/script/runner +13 -1
  160. data/test/performance/suites/active_record.rb +47 -0
  161. data/test/performance/suites/config.rb +4 -48
  162. data/test/performance/suites/marshalling.rb +20 -30
  163. data/test/performance/suites/queue_time.rb +1 -1
  164. data/test/performance/suites/rack_middleware.rb +1 -1
  165. data/test/performance/suites/rum_autoinsertion.rb +1 -1
  166. data/test/performance/suites/sql_obfuscation.rb +2 -2
  167. data/test/performance/suites/startup.rb +1 -1
  168. data/test/performance/suites/stats_hash.rb +7 -11
  169. data/test/performance/suites/thread_profiling.rb +20 -25
  170. data/test/performance/suites/trace_execution_scoped.rb +2 -2
  171. data/test/performance/suites/transaction_tracing.rb +4 -2
  172. data/test/test_helper.rb +5 -1
  173. metadata +53 -100
  174. data.tar.gz.sig +0 -0
  175. data/gem-public_cert.pem +0 -20
  176. data/lib/new_relic/agent/datastores/mongo/metric_generator.rb +0 -33
  177. data/test/multiverse/suites/sequel/sequel_instrumentation_test.rb +0 -289
  178. data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +0 -69
  179. data/test/new_relic/agent/memcache_instrumentation_test.rb +0 -155
  180. metadata.gz.sig +0 -2
@@ -55,7 +55,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
55
55
  service.metric_data(new_engine.harvest!)
56
56
  end
57
57
 
58
- assert_equal(3.0, engine.lookup_stats(metric).total_call_time)
58
+ assert_metrics_recorded(metric => { :total_call_time => 3.0 })
59
59
  engine.reset!
60
60
  end
61
61
 
@@ -34,6 +34,15 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
34
34
  assert @service.running?
35
35
  end
36
36
 
37
+ def test_doesnt_start_on_resque
38
+ with_config(:dispatcher => :resque) do
39
+ fake_worker_loop(@service)
40
+
41
+ @service.subscribe(BacktraceService::ALL_TRANSACTIONS)
42
+ refute @service.running?
43
+ end
44
+ end
45
+
37
46
  def test_stops_when_subscription_is_removed
38
47
  fake_worker_loop(@service)
39
48
 
@@ -325,6 +334,21 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
325
334
  fake_transaction_finished('foo', (t0 + 1).to_f, 2.0, thread)
326
335
  end
327
336
 
337
+ def test_on_transaction_finished_delivers_background_backtraces
338
+ fake_worker_loop(@service)
339
+
340
+ thread0 = fake_thread(:background)
341
+
342
+ profile = @service.subscribe('foo')
343
+
344
+ t0 = Time.now
345
+ @service.poll
346
+
347
+ profile.expects(:aggregate).with(thread0.backtrace, :background, thread0).once
348
+
349
+ fake_transaction_finished('foo', t0.to_f, 1, thread0, :background)
350
+ end
351
+
328
352
  def test_does_not_deliver_non_request_backtraces_to_subscribed_profiles
329
353
  fake_worker_loop(@service)
330
354
 
@@ -351,7 +375,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
351
375
  @service.poll
352
376
 
353
377
  profile.expects(:aggregate).once
354
- fake_transaction_finished('foo', t0.to_f, 1.0)
378
+ fake_transaction_finished('foo', t0.to_f, 1.0, Thread.current)
355
379
  end
356
380
 
357
381
  def test_service_increments_profile_poll_counts
@@ -471,11 +495,12 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
471
495
  end
472
496
  end
473
497
 
474
- def fake_transaction_finished(name, start_timestamp, duration, thread=nil)
498
+ def fake_transaction_finished(name, start_timestamp, duration, thread, bucket=:request)
475
499
  payload = {
476
- :name => name,
500
+ :name => name,
501
+ :bucket => bucket,
477
502
  :start_timestamp => start_timestamp,
478
- :duration => duration
503
+ :duration => duration
479
504
  }
480
505
  payload[:thread] = thread if thread
481
506
  @event_listener.notify(:transaction_finished, payload)
@@ -91,7 +91,6 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
91
91
  txn_metrics.record_unscoped('External/allWeb', 14)
92
92
  txn_metrics.record_unscoped('Datastore/all', 15)
93
93
  txn_metrics.record_unscoped("GC/Transaction/all", 16)
94
- txn_metrics.record_unscoped('Memcache/allWeb', 17)
95
94
 
96
95
  with_sampler_config do
97
96
  generate_request('name', :metrics => txn_metrics)
@@ -100,7 +99,6 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
100
99
  assert_equal 14, event_data["externalDuration"]
101
100
  assert_equal 15, event_data["databaseDuration"]
102
101
  assert_equal 16, event_data["gcCumulative"]
103
- assert_equal 17, event_data["memcacheDuration"]
104
102
 
105
103
  assert_equal 1, event_data["externalCallCount"]
106
104
  assert_equal 1, event_data["databaseCallCount"]
@@ -112,7 +110,6 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
112
110
  txn_metrics.record_unscoped('External/allOther', 12)
113
111
  txn_metrics.record_unscoped('Datastore/all', 13)
114
112
  txn_metrics.record_unscoped("GC/Transaction/all", 14)
115
- txn_metrics.record_unscoped('Memcache/allOther', 15)
116
113
 
117
114
  with_sampler_config do
118
115
  generate_request('name', :metrics => txn_metrics)
@@ -121,7 +118,6 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
121
118
  assert_equal 12, event_data["externalDuration"]
122
119
  assert_equal 13, event_data["databaseDuration"]
123
120
  assert_equal 14, event_data["gcCumulative"]
124
- assert_equal 15, event_data["memcacheDuration"]
125
121
 
126
122
  assert_equal 1, event_data["databaseCallCount"]
127
123
  assert_equal 1, event_data["externalCallCount"]
@@ -132,6 +132,7 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
132
132
  KEY_TRANSACTION_CONFIG = {
133
133
  :web_transactions_apdex => {
134
134
  'Controller/slow/txn' => 4,
135
+ 'OtherTransaction/back/ground' => 8
135
136
  },
136
137
  :apdex => 1
137
138
  }
@@ -150,6 +151,7 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
150
151
 
151
152
  # apdex_s is 2 because the transaction itself records apdex
152
153
  assert_metrics_recorded(
154
+ 'ApdexAll' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
153
155
  'Apdex' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
154
156
  'Apdex/slow/txn' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 }
155
157
  )
@@ -170,12 +172,47 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
170
172
 
171
173
  # apdex_s is 2 because the transaction itself records apdex
172
174
  assert_metrics_recorded(
175
+ 'ApdexAll' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
173
176
  'Apdex' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
174
177
  'Apdex/other/txn' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 }
175
178
  )
176
179
  end
177
180
  end
178
181
 
182
+ def test_update_apdex_records_for_background_key_transaction
183
+ t0 = freeze_time
184
+ with_config(KEY_TRANSACTION_CONFIG) do
185
+ in_background_transaction('OtherTransaction/back/ground') do
186
+ state = NewRelic::Agent::TransactionState.tl_get
187
+ txn = state.current_transaction
188
+ txn.record_apdex(state, t0 + 7.5)
189
+ txn.record_apdex(state, t0 + 9.5)
190
+ txn.record_apdex(state, t0 + 32.5)
191
+ end
192
+
193
+ assert_metrics_recorded(
194
+ 'ApdexAll' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
195
+ 'ApdexOther' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
196
+ 'ApdexOther/Transaction/back/ground' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 }
197
+ )
198
+ end
199
+ end
200
+
201
+ def test_skips_apdex_records_for_background_non_key_transaction
202
+ t0 = freeze_time
203
+ with_config(KEY_TRANSACTION_CONFIG) do
204
+ in_background_transaction('OtherTransaction/other/task') do
205
+ state = NewRelic::Agent::TransactionState.tl_get
206
+ txn = state.current_transaction
207
+ txn.record_apdex(state, t0 + 7.5)
208
+ txn.record_apdex(state, t0 + 9.5)
209
+ txn.record_apdex(state, t0 + 32.5)
210
+ end
211
+
212
+ refute_metrics_recorded(['ApdexOther', 'ApdexOther/Transaction/other/task'])
213
+ end
214
+ end
215
+
179
216
  def test_record_apdex_stores_apdex_t_in_min_and_max
180
217
  with_config(:apdex_t => 2.5) do
181
218
  in_web_transaction('Controller/some/txn') do
@@ -187,11 +224,42 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
187
224
 
188
225
  expected = { :min_call_time => 2.5, :max_call_time => 2.5 }
189
226
  assert_metrics_recorded(
190
- 'Apdex' => expected,
227
+ 'ApdexAll' => expected,
228
+ 'Apdex' => expected,
191
229
  'Apdex/some/txn' => expected
192
230
  )
193
231
  end
194
232
 
233
+ def test_records_apdex_all_for_both_transaction_types
234
+ t0 = freeze_time
235
+ with_config(KEY_TRANSACTION_CONFIG) do
236
+ in_background_transaction('OtherTransaction/back/ground') do
237
+ state = NewRelic::Agent::TransactionState.tl_get
238
+ txn = state.current_transaction
239
+ txn.record_apdex(state, t0 + 7.5)
240
+ txn.record_apdex(state, t0 + 9.5)
241
+ txn.record_apdex(state, t0 + 32.5)
242
+ end
243
+
244
+ in_web_transaction('Controller/slow/txn') do
245
+ state = NewRelic::Agent::TransactionState.tl_get
246
+ txn = state.current_transaction
247
+ txn.record_apdex(state, t0 + 3.5)
248
+ txn.record_apdex(state, t0 + 5.5)
249
+ txn.record_apdex(state, t0 + 16.5)
250
+ end
251
+
252
+ # apdex_s is 2 because the transaction itself records apdex
253
+ assert_metrics_recorded(
254
+ 'ApdexAll' => { :apdex_s => 4, :apdex_t => 2, :apdex_f => 2 },
255
+ 'Apdex' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
256
+ 'Apdex/slow/txn' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
257
+ 'ApdexOther' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 },
258
+ 'ApdexOther/Transaction/back/ground' => { :apdex_s => 2, :apdex_t => 1, :apdex_f => 1 }
259
+ )
260
+ end
261
+ end
262
+
195
263
  class SillyError < StandardError
196
264
  end
197
265
 
@@ -429,7 +497,7 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
429
497
  end
430
498
  end
431
499
 
432
- def test_background_transaction_event_doesnt_include_apdex_perf_zone
500
+ def test_default_background_transaction_event_doesnt_include_apdex_perf_zone
433
501
  apdex = nil
434
502
  NewRelic::Agent.subscribe(:transaction_finished) do |payload|
435
503
  apdex = payload[:apdex_perf_zone]
@@ -443,6 +511,29 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
443
511
  end
444
512
  end
445
513
 
514
+ def test_background_transaction_event_include_apdex_perf_zone_if_key_transaction
515
+ apdex = nil
516
+ NewRelic::Agent.subscribe(:transaction_finished) do |payload|
517
+ apdex = payload[:apdex_perf_zone]
518
+ end
519
+
520
+ freeze_time
521
+
522
+ txn_name = 'OtherTransaction/back/ground'
523
+ key_transactions = { txn_name => 1.0 }
524
+
525
+ with_config(:apdex_t => 1.0, :web_transactions_apdex => key_transactions) do
526
+ in_background_transaction(txn_name) { advance_time 0.5 }
527
+ assert_equal('S', apdex)
528
+
529
+ in_background_transaction(txn_name) { advance_time 1.5 }
530
+ assert_equal('T', apdex)
531
+
532
+ in_background_transaction(txn_name) { advance_time 4.5 }
533
+ assert_equal('F', apdex)
534
+ end
535
+ end
536
+
446
537
  def test_guid_in_finish_event_payload_if_incoming_synthetics_header
447
538
  keys = []
448
539
  NewRelic::Agent.subscribe(:transaction_finished) do |payload|
@@ -1186,4 +1277,11 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
1186
1277
 
1187
1278
  assert_metrics_recorded(["Errors/all"])
1188
1279
  end
1280
+
1281
+ def test_instrumentation_state
1282
+ in_transaction do |txn|
1283
+ txn.instrumentation_state[:a] = 42
1284
+ assert_equal(42, txn.instrumentation_state[:a])
1285
+ end
1286
+ end
1189
1287
  end
@@ -310,7 +310,7 @@ module NewRelic
310
310
  new_name = NewRelic::Agent.get_transaction_name + "2"
311
311
  NewRelic::Agent.set_transaction_name(new_name)
312
312
  end
313
- assert engine.lookup_stats('OtherTransaction/Background/a_new_name2')
313
+ assert_metrics_recorded 'OtherTransaction/Background/a_new_name2'
314
314
  end
315
315
 
316
316
  def test_set_transaction_name_applies_proper_scopes
@@ -343,7 +343,7 @@ module NewRelic
343
343
  NewRelic::Agent.set_transaction_name('new_name')
344
344
  end
345
345
  end
346
- assert_nil engine.lookup_stats('Controller/new_name')
346
+ refute_metrics_recorded('Controller/new_name')
347
347
  end
348
348
 
349
349
  def test_set_transaction_name_applies_category
@@ -374,7 +374,7 @@ module NewRelic
374
374
  Transactor.new.task_txn do
375
375
  NewRelic::Agent.set_transaction_name('new_name')
376
376
  end
377
- assert engine.lookup_stats('OtherTransaction/Background/new_name')
377
+ assert_metrics_recorded 'OtherTransaction/Background/new_name'
378
378
  end
379
379
 
380
380
  # It's not uncommon for customers to conclude a rescue block with a call to
@@ -5,7 +5,6 @@
5
5
  require "newrelic_rpm"
6
6
  require "fake_external_server"
7
7
  require "evil_server"
8
- require 'multiverse_helpers'
9
8
 
10
9
  module HttpClientTestCases
11
10
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation,
@@ -4,6 +4,13 @@
4
4
 
5
5
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "agent_helper"))
6
6
 
7
+ class Minitest::Test
8
+ def after_teardown
9
+ unfreeze_time
10
+ super
11
+ end
12
+ end
13
+
7
14
  module MultiverseHelpers
8
15
 
9
16
  #
@@ -2,8 +2,6 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- require 'multiverse_helpers'
6
-
7
5
  module TransactionIgnoringTestCases
8
6
 
9
7
  include MultiverseHelpers
@@ -24,7 +24,7 @@ class NewRelic::TransactionSampleTest < Minitest::Test
24
24
  @connection_stub.stubs(:execute).returns(dummy_mysql_explain_result({'foo' => 'bar'}))
25
25
 
26
26
  NewRelic::Agent::Database.stubs(:get_connection).returns @connection_stub
27
- @t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
27
+ @t = make_sql_transaction(::SQL_STATEMENT)
28
28
 
29
29
  if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
30
30
  @marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
@@ -314,7 +314,7 @@ class NewRelic::TransactionSampleTest < Minitest::Test
314
314
 
315
315
  t = nil
316
316
  with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
317
- t = make_sql_transaction(query, query)
317
+ t = make_sql_transaction(query)
318
318
  t.prepare_to_send!
319
319
  end
320
320
 
@@ -322,6 +322,15 @@ class NewRelic::TransactionSampleTest < Minitest::Test
322
322
  assert_equal(["SELECT * FROM table WHERE col1=? AND col2=?"], sql_statements)
323
323
  end
324
324
 
325
+ def test_multiple_calls_to_notice_sequel_appends_sql
326
+ queries = ["BEGIN", "INSERT items(title) VALUES('title')", "COMMIT"]
327
+
328
+ t = make_sql_transaction(*queries)
329
+ sql_statements = extract_captured_sql(t)
330
+
331
+ assert_equal [queries.join("\n")], sql_statements
332
+ end
333
+
325
334
  def trace_tree(transaction=@t)
326
335
  if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
327
336
  trace_tree = compress(JSON.dump(transaction.to_array))
@@ -30,7 +30,7 @@ Run one specific suite:
30
30
  $ rake test:performance[TransactionTracingPerfTests]
31
31
  ```
32
32
 
33
- Run one specif suite and test (test name matching is via regex):
33
+ Run one specific suite and test (test name matching is via regex):
34
34
 
35
35
  ```
36
36
  $ rake test:performance[TransactionTracingPerfTests,test_short_transactions]
@@ -39,7 +39,7 @@ $ rake test:performance[TransactionTracingPerfTests,test_short_transactions]
39
39
  ### Invoking via the runner directly
40
40
 
41
41
  More advanced options can be specified by invoking the runner script directly.
42
- See `test/performance/script/runner -h` for a full list of options.
42
+ See `./test/performance/script/runner -h` for a full list of options.
43
43
 
44
44
  Run all tests, report detailed results in a human-readable form
45
45
 
@@ -47,16 +47,35 @@ Run all tests, report detailed results in a human-readable form
47
47
  $ ./test/performance/script/runner
48
48
  ```
49
49
 
50
+ List all available test suites and names:
51
+
52
+ ```
53
+ $ ./test/performance/script/runner -l
54
+ ```
55
+
50
56
  Run a specific test (test name matching is via regex):
51
57
 
52
58
  ```
53
59
  $ ./test/performance/script/runner -n short
54
60
  ```
55
61
 
56
- Run all the tests, brief output (just timings):
62
+ To compare results for a specific test between two versions of the code, use the
63
+ `-B` (for Baseline) and `-C` for (for Compare) switches:
57
64
 
58
65
  ```
59
- $ ./test/performance/script/runner -b
66
+ $ ./test/performance/script/runner -n short -B
67
+ 1 tests, 0 failures, 8.199975 s total
68
+ Saved 1 results as baseline.
69
+
70
+ ... switch to another branch and run again with -C ...
71
+
72
+ $ ./test/performance/script/runner -n short -C
73
+ 1 tests, 0 failures, 8.220509 s total
74
+ +-----------------------------------------------------+-----------+-----------+-------+---------------+--------------+--------------+
75
+ | name | before | after | delta | allocs_before | allocs_after | allocs_delta |
76
+ |-----------------------------------------------------+-----------+-----------+-------+---------------+--------------+--------------|
77
+ | TransactionTracingPerfTests#test_short_transactions | 214.27 µs | 210.31 µs | -1.8% | 97 | 97 | 0.0% |
78
+ +-----------------------------------------------------+-----------+-----------+-------+---------------+--------------+--------------+
60
79
  ```
61
80
 
62
81
  Run all the tests, produce machine readable JSON output (for eventual ingestion into a storage system):
@@ -65,16 +84,16 @@ Run all the tests, produce machine readable JSON output (for eventual ingestion
65
84
  $ ./test/performance/script/runner -j | json_reformat
66
85
  ```
67
86
 
68
- Run a specific test using the perftools.rb CPU profiler, producing a call-graph style dot file:
87
+ Run a specific test under a profiler (either stackprof or perftools.rb, depending on your Ruby version):
69
88
 
70
89
  ```
71
- $ ./test/performance/script/runner -n short -i PerfToolsProfile
90
+ $ ./test/performance/script/runner -n short --profile
72
91
  ```
73
92
 
74
- Run with fewer iterations, and do object allocation profiling (again to a call-graph dot file):
93
+ Run with a set number of iterations, and do object allocation profiling (again to a call-graph dot file):
75
94
 
76
95
  ```
77
- $ CPUPROFILE_OBJECTS=1 ./test/performance/script/runner -n short -i PerfToolsProfile -N 1000
96
+ $ ./test/performance/script/runner -n short -a -N 1000
78
97
  ```
79
98
 
80
99
  ## Pointing at a different copy of the agent
@@ -100,16 +119,17 @@ under `test/performance/suites`, subclass `Performance::TestCase`, and write
100
119
  test methods that start with `test_`. You can also write `setup` and `teardown`
101
120
  methods that will be run before/after each test.
102
121
 
103
- Generally in your test, you'll want to do some operation N times (where N is
104
- large). You should base your N on the return value of
105
- `Performance::TestCase#iterations`, which is controlled by the `-N` command-line
106
- flag to `runner`. You may scale this value linearly as appropriate for your test
107
- if need be, but the idea is to have a single knob to turn that will change the
108
- iteration count for all tests.
122
+ Within your `test_` method, you must call `measure` and pass it a block
123
+ containing the code that you'd like to actually measure the timing of. This
124
+ allows you to do test-specific setup that doesn't get counted towards your
125
+ test timing.
126
+
127
+ The block that you pass to `measure` will automatically be run in a loop for a
128
+ fixed amount of time by the performance runner harness (5s by default), and the
129
+ number of iterations performed will be recorded so that measurements can be
130
+ normalized to per-iteration values.
109
131
 
110
- The invocation of each `test_*` method will be timed, so any setup / teardown
111
- you need for your test that you don't want included in the timing should be
112
- confined to the `setup` and `teardown` methods.
132
+ You can look at the [existing tests](suites) for examples.
113
133
 
114
134
  ## Test Isolation
115
135