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
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
6
+ require 'new_relic/agent/deprecator'
7
+
8
+ class DeprecatorTest < Minitest::Test
9
+ def setup
10
+ @old_method = :foo
11
+ @new_method = :bar
12
+ @version = "3.11.0"
13
+ end
14
+
15
+ def teardown
16
+ ::NewRelic::Agent.logger.clear_already_logged
17
+ end
18
+
19
+ def test_deprecator_logs_a_warning_with_the_name_of_the_method
20
+ NewRelic::Agent.logger.expects(:warn).with do |messages|
21
+ messages.first.include? @old_method.to_s
22
+ end
23
+ NewRelic::Agent::Deprecator.deprecate(@old_method)
24
+ end
25
+
26
+ def test_deprecator_logs_once
27
+ NewRelic::Agent.logger.expects(:warn).with do |messages|
28
+ messages.first.include? @old_method.to_s
29
+ end
30
+ NewRelic::Agent::Deprecator.deprecate(@old_method)
31
+ NewRelic::Agent::Deprecator.deprecate(@old_method)
32
+ end
33
+
34
+ def test_deprecator_logs_the_new_method_if_given
35
+ NewRelic::Agent.logger.expects(:warn).with do |messages|
36
+ messages.last.include? @new_method.to_s
37
+ end
38
+ NewRelic::Agent::Deprecator.deprecate(@old_method, @new_method)
39
+ end
40
+
41
+ def test_deprecator_logs_the_version_if_given
42
+ NewRelic::Agent.logger.expects(:warn).with do |messages|
43
+ messages[1].include? @version.to_s
44
+ end
45
+ NewRelic::Agent::Deprecator.deprecate(@old_method, @new_method, @version)
46
+ end
47
+
48
+ def test_deprecator_reports_a_supportability_metric
49
+ NewRelic::Agent::Deprecator.deprecate(:deprecated_supportability_test)
50
+ assert_metrics_recorded("Supportability/Deprecated/deprecated_supportability_test")
51
+ end
52
+ end
@@ -19,6 +19,7 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
19
19
 
20
20
  def test_records_metrics_for_simple_template
21
21
  params = { :identifier => '/root/app/views/model/index.html.erb' }
22
+
22
23
  t0 = Time.now
23
24
  Time.stubs(:now).returns(t0, t0, t0 + 2, t0 + 2)
24
25
 
@@ -29,9 +30,8 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
29
30
  :virtual_path => 'model/index')
30
31
  @subscriber.finish('render_template.action_view', :id, params)
31
32
 
32
- metric = @stats_engine.lookup_stats('View/model/index.html.erb/Rendering')
33
- assert_equal(1, metric.call_count)
34
- assert_equal(2.0, metric.total_call_time)
33
+ expected = { :call_count => 1, :total_call_time => 2.0 }
34
+ assert_metrics_recorded('View/model/index.html.erb/Rendering' => expected)
35
35
  end
36
36
 
37
37
  def test_records_metrics_for_simple_file
@@ -46,9 +46,8 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
46
46
  :virtual_path => nil)
47
47
  @subscriber.finish('render_template.action_view', :id, params)
48
48
 
49
- metric = @stats_engine.lookup_stats('View/file/Rendering')
50
- assert_equal(1, metric.call_count)
51
- assert_equal(2.0, metric.total_call_time)
49
+ expected = { :call_count => 1, :total_call_time => 2.0 }
50
+ assert_metrics_recorded('View/file/Rendering' => expected)
52
51
  end
53
52
 
54
53
  def test_records_metrics_for_simple_inline
@@ -63,9 +62,8 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
63
62
  :virtual_path => nil)
64
63
  @subscriber.finish('render_template.action_view', :id, params)
65
64
 
66
- metric = @stats_engine.lookup_stats('View/inline template/Rendering')
67
- assert_equal(1, metric.call_count)
68
- assert_equal(2.0, metric.total_call_time)
65
+ expected = { :call_count => 1, :total_call_time => 2.0 }
66
+ assert_metrics_recorded('View/inline template/Rendering' => expected)
69
67
  end
70
68
 
71
69
  def test_records_metrics_for_simple_text
@@ -76,9 +74,8 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
76
74
  @subscriber.start('render_template.action_view', :id, params)
77
75
  @subscriber.finish('render_template.action_view', :id, params)
78
76
 
79
- metric = @stats_engine.lookup_stats('View/text template/Rendering')
80
- assert_equal(1, metric.call_count)
81
- assert_equal(2.0, metric.total_call_time)
77
+ expected = { :call_count => 1, :total_call_time => 2.0 }
78
+ assert_metrics_recorded('View/text template/Rendering' => expected)
82
79
  end
83
80
 
84
81
  def test_records_metrics_for_simple_partial
@@ -93,9 +90,8 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
93
90
  :virtual_path => 'model/_form')
94
91
  @subscriber.finish('render_partial.action_view', :id, params)
95
92
 
96
- metric = @stats_engine.lookup_stats('View/model/_form.html.erb/Partial')
97
- assert_equal(1, metric.call_count)
98
- assert_equal(2.0, metric.total_call_time)
93
+ expected = { :call_count => 1, :total_call_time => 2.0 }
94
+ assert_metrics_recorded('View/model/_form.html.erb/Partial' => expected)
99
95
  end
100
96
 
101
97
  def test_records_metrics_for_simple_collection
@@ -110,9 +106,8 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
110
106
  :virtual_path => 'model/_user')
111
107
  @subscriber.finish('render_collection.action_view', :id, params)
112
108
 
113
- metric = @stats_engine.lookup_stats('View/model/_user.html.erb/Partial')
114
- assert_equal(1, metric.call_count)
115
- assert_equal(2.0, metric.total_call_time)
109
+ expected = { :call_count => 1, :total_call_time => 2.0 }
110
+ assert_metrics_recorded('View/model/_user.html.erb/Partial' => expected)
116
111
  end
117
112
 
118
113
  def test_records_metrics_for_layout
@@ -124,9 +119,8 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
124
119
  @subscriber.finish('!render_template.action_view', :id,
125
120
  :virtual_path => 'layouts/application')
126
121
 
127
- metric = @stats_engine.lookup_stats('View/layouts/application/Rendering')
128
- assert_equal(1, metric.call_count)
129
- assert_equal(2.0, metric.total_call_time)
122
+ expected = { :call_count => 1, :total_call_time => 2.0 }
123
+ assert_metrics_recorded('View/layouts/application/Rendering' => expected)
130
124
  end
131
125
 
132
126
  def test_records_scoped_metric
@@ -141,9 +135,10 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
141
135
  @subscriber.finish('render_template.action_view', :id, params)
142
136
  end
143
137
 
144
- metric = @stats_engine.lookup_stats('View/model/index.html.erb/Rendering',
145
- 'test_txn')
146
- assert_equal(1, metric.call_count)
138
+ expected = { :call_count => 1 }
139
+ assert_metrics_recorded(
140
+ ['View/model/index.html.erb/Rendering', 'test_txn'] => expected
141
+ )
147
142
  end
148
143
 
149
144
  def test_records_nothing_if_tracing_disabled
@@ -154,8 +149,7 @@ class NewRelic::Agent::Instrumentation::ActionViewSubscriberTest < Minitest::Tes
154
149
  @subscriber.finish('render_collection.action_view', :id, params)
155
150
  end
156
151
 
157
- metric = @stats_engine.lookup_stats('View/model/_user.html.erb/Partial')
158
- assert_nil metric
152
+ assert_metrics_not_recorded('View/model/_user.html.erb/Partial')
159
153
  end
160
154
 
161
155
  def test_creates_txn_segment_for_simple_render
@@ -4,69 +4,74 @@
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 < Minitest::Test
8
- include NewRelic::Agent::Instrumentation
7
+ module NewRelic::Agent::Instrumentation
8
+ class ActiveRecordHelperTest < Minitest::Test
9
9
 
10
- def test_metric_for_name_find
11
- metric_name = 'ActiveRecord/Model/find'
12
- assert_equal metric_name, ActiveRecordHelper.metric_for_name('Model Find')
13
- assert_equal metric_name, ActiveRecordHelper.metric_for_name('Model Load')
14
- assert_equal metric_name, ActiveRecordHelper.metric_for_name('Model Count')
15
- assert_equal metric_name, ActiveRecordHelper.metric_for_name('Model Exists')
16
- end
10
+ def test_metrics_for_find
11
+ metrics = ActiveRecordHelper.metrics_for('Namespace::Model Load', nil, nil)
12
+ expected = expected_statement_metrics("find", "Namespace::Model/find")
13
+ assert_equal(expected, metrics)
14
+ end
17
15
 
18
- def test_metric_for_name_with_namespace
19
- assert_equal('ActiveRecord/Namespace::Model/find',
20
- ActiveRecordHelper.metric_for_name('Namespace::Model Load'))
21
- end
16
+ def test_metrics_for_destroy
17
+ metrics = ActiveRecordHelper.metrics_for('Model Destroy', nil, nil)
18
+ expected = expected_statement_metrics("destroy", "Model/destroy")
19
+ assert_equal(expected, metrics)
20
+ end
22
21
 
23
- def test_metric_for_name_destroy
24
- assert_equal('ActiveRecord/Model/destroy',
25
- ActiveRecordHelper.metric_for_name('Model Destroy'))
26
- end
22
+ def test_metrics_for_create
23
+ metrics = ActiveRecordHelper.metrics_for('Model Create', nil, nil)
24
+ expected = expected_statement_metrics("create", "Model/create")
25
+ assert_equal(expected, metrics)
26
+ end
27
27
 
28
- def test_metric_for_name_create
29
- assert_equal('ActiveRecord/Model/create',
30
- ActiveRecordHelper.metric_for_name('Model Create'))
31
- end
28
+ def test_metrics_for_update
29
+ metrics = ActiveRecordHelper.metrics_for('Model Update', nil, nil)
30
+ expected = expected_statement_metrics("update", "Model/update")
31
+ assert_equal(expected, metrics)
32
+ end
32
33
 
33
- def test_metric_for_name_update
34
- assert_equal('ActiveRecord/Model/save',
35
- ActiveRecordHelper.metric_for_name('Model Update'))
36
- end
34
+ def test_metric_for_name_columns
35
+ metrics = ActiveRecordHelper.metrics_for('Model Columns', nil, nil)
36
+ expected = expected_statement_metrics("columns", "Model/columns")
37
+ assert_equal(expected, metrics)
38
+ end
37
39
 
38
- def test_metric_for_name_columns
39
- assert_nil ActiveRecordHelper.metric_for_name('Model Columns')
40
- end
40
+ def test_metric_with_product_name_from_adapter
41
+ metrics = ActiveRecordHelper.metrics_for('Model Load', nil, "mysql")
42
+ expected = expected_statement_metrics("find", "Model/find", "MySQL")
43
+ assert_equal(expected, metrics)
44
+ end
41
45
 
42
- def test_metric_for_name_with_integer_returns_nil
43
- assert_nil ActiveRecordHelper.metric_for_name(1)
44
- end
46
+ def test_metrics_from_sql
47
+ metrics = ActiveRecordHelper.metrics_for('invalid', "SELECT * FROM boo", nil)
48
+ expected = expected_operation_metrics("select")
49
+ assert_equal(expected, metrics)
50
+ end
45
51
 
46
- def test_rollup_metrics_for_lists_rollups
47
- NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
48
- base_metric = 'ActiveRecord/Namespace::Model/find'
49
- rollup_metrics = ActiveRecordHelper.rollup_metrics_for(base_metric)
50
- expected_metrics = ['Datastore/all', 'ActiveRecord/all', 'ActiveRecord/find']
51
- assert_equal(expected_metrics.sort, rollup_metrics.sort)
52
- end
52
+ def test_metric_for_name_with_integer_returns_nil
53
+ metrics = ActiveRecordHelper.metrics_for(1, '', nil)
54
+ expected = expected_operation_metrics("other")
55
+ assert_equal(expected, metrics)
56
+ end
53
57
 
54
- def test_rollup_metrics_for_skips_operation_rollup_given_metric_without_model
55
- NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
56
- rollup_metrics = ActiveRecordHelper.rollup_metrics_for('ActiveRecord/find')
57
- expected_metrics = ['Datastore/all', 'ActiveRecord/all']
58
- assert_equal(expected_metrics, rollup_metrics)
59
- end
58
+ def test_rollup_metrics_for_is_deprecated
59
+ NewRelic::Agent::Deprecator.expects(:deprecate)
60
+ result = ActiveRecordHelper.rollup_metrics_for("boo")
61
+ assert_equal ["Datastore/allOther", "Datastore/all"], result
62
+ end
60
63
 
61
- def test_rollup_metrics_for_omits_database_all_outside_web_transaction
62
- NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
63
- base_metric = 'ActiveRecord/Namespace::Model/find'
64
- rollup_metrics = ActiveRecordHelper.rollup_metrics_for(base_metric)
65
- assert_equal(['Datastore/all', 'Datastore/allOther', 'ActiveRecord/find'], rollup_metrics)
66
- end
64
+ def expected_statement_metrics(operation, statement, product = "ActiveRecord")
65
+ ["Datastore/statement/#{product}/#{statement}"] +
66
+ expected_operation_metrics(operation, product)
67
+ end
67
68
 
68
- def test_remote_service_metric
69
- assert_equal('RemoteService/sql/mysql/server',
70
- ActiveRecordHelper.remote_service_metric('mysql', 'server'))
69
+ def expected_operation_metrics(operation, product = "ActiveRecord")
70
+ ["Datastore/operation/#{product}/#{operation}",
71
+ "Datastore/#{product}/allOther",
72
+ "Datastore/#{product}/all",
73
+ "Datastore/allOther",
74
+ "Datastore/all"]
75
+ end
71
76
  end
72
77
  end
@@ -35,7 +35,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Minitest::T
35
35
 
36
36
  simulate_query(2)
37
37
 
38
- metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
38
+ metric_name = 'Datastore/statement/ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
39
39
  assert_metrics_recorded(
40
40
  metric_name => { :call_count => 1, :total_call_time => 2.0 }
41
41
  )
@@ -46,7 +46,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Minitest::T
46
46
 
47
47
  in_transaction('test_txn') { simulate_query(2) }
48
48
 
49
- metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
49
+ metric_name = 'Datastore/statement/ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
50
50
  assert_metrics_recorded(
51
51
  [metric_name, 'test_txn'] => { :call_count => 1, :total_call_time => 2 }
52
52
  )
@@ -57,7 +57,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Minitest::T
57
57
 
58
58
  NewRelic::Agent.disable_all_tracing { simulate_query(2) }
59
59
 
60
- metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
60
+ metric_name = 'Datastore/statement/ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
61
61
  assert_metrics_not_recorded([metric_name])
62
62
  end
63
63
 
@@ -67,22 +67,9 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Minitest::T
67
67
  in_web_transaction { simulate_query(2) }
68
68
 
69
69
  assert_metrics_recorded(
70
- 'ActiveRecord/find' => { :call_count => 1, :total_call_time => 2 },
71
- 'ActiveRecord/all' => { :call_count => 1, :total_call_time => 2 }
72
- )
73
- end
74
-
75
- def test_records_remote_service_metric
76
- connection_pool = stub(:connections => [ @connection ])
77
- connection_pool_list = [connection_pool]
78
- ::ActiveRecord::Base.connection_handler.stubs(:connection_pool_list).returns(connection_pool_list)
79
-
80
- freeze_time
81
-
82
- simulate_query(2)
83
-
84
- assert_metrics_recorded(
85
- 'RemoteService/sql/mysql/server' => { :call_count => 1, :total_call_time => 2.0 }
70
+ 'Datastore/operation/ActiveRecord/find' => { :call_count => 1, :total_call_time => 2 },
71
+ 'Datastore/allWeb' => { :call_count => 1, :total_call_time => 2 },
72
+ 'Datastore/all' => { :call_count => 1, :total_call_time => 2 }
86
73
  )
87
74
  end
88
75
 
@@ -97,7 +84,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Minitest::T
97
84
  sampler = NewRelic::Agent.instance.transaction_sampler
98
85
  sampler.last_sample.root_segment.each_segment{|s| last_segment = s }
99
86
 
100
- assert_equal('ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find',
87
+ assert_equal('Datastore/statement/ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find',
101
88
  last_segment.metric_name)
102
89
  assert_equal('SELECT * FROM sandwiches',
103
90
  last_segment.params[:sql])
@@ -56,6 +56,25 @@ class NewRelic::Agent::Instrumentation::MiddlewareProxyTest < Minitest::Test
56
56
  assert_equal(['abc', 123], wrapped_instance.target.initialize_args)
57
57
  end
58
58
 
59
+ def test_anonymous_class_naming
60
+ middleware_class = Class.new
61
+ wrapped_instance = NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(middleware_class.new)
62
+
63
+ name = wrapped_instance.transaction_options[:transaction_name]
64
+ assert_equal("Middleware/Rack/AnonymousClass/call", name)
65
+ end
66
+
67
+ class BaseForAnonymous
68
+ end
69
+
70
+ def test_anonymous_derived_class_naming
71
+ middleware_class = Class.new(BaseForAnonymous)
72
+ wrapped_instance = NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(middleware_class.new)
73
+
74
+ name = wrapped_instance.transaction_options[:transaction_name]
75
+ assert_equal("Middleware/Rack/#{BaseForAnonymous.name}/call", name)
76
+ end
77
+
59
78
  def test_does_not_wrap_sinatra_apps
60
79
  sinatra_dummy_module = Module.new
61
80
  sinatra_dummy_class = Class.new(Object)
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
+ require 'new_relic/agent/instrumentation/sequel_helper'
7
+
8
+ module NewRelic
9
+ module Agent
10
+ class SequelHelperTest < Minitest::Test
11
+ def test_product_name_from_adapter
12
+ expected_default = "Sequel"
13
+ default = Hash.new(expected_default)
14
+
15
+ adapter_to_name = {
16
+ :ibmdb => "IBMDB2",
17
+ :firebird => "Firebird",
18
+ :informix => "Informix",
19
+ :jdbc => "JDBC",
20
+ :mysql => "MySQL",
21
+ :mysql2 => "MySQL",
22
+ :oracle => "Oracle",
23
+ :postgres => "Postgres",
24
+ :sqlite => "SQLite"
25
+ }
26
+
27
+ default.merge(adapter_to_name).each do |adapter, name|
28
+ assert_equal name, NewRelic::Agent::Instrumentation::SequelHelper.product_name_from_adapter(adapter)
29
+ end
30
+
31
+ default_result = NewRelic::Agent::Instrumentation::SequelHelper.product_name_from_adapter("YouDontKnowThisAdapter")
32
+ assert_equal expected_default, default_result
33
+ end
34
+ end
35
+ end
36
+ end
@@ -50,6 +50,7 @@ class NewRelic::Agent::Instrumentation::TaskInstrumentationTest < Minitest::Test
50
50
  'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
51
51
  'Apdex/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
52
52
  'HttpDispatcher',
53
+ 'ApdexAll',
53
54
  'Apdex'
54
55
  ])
55
56
  end
@@ -115,7 +115,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
115
115
  advance_time 0.05
116
116
  end
117
117
 
118
- assert_empty @stats_engine.metrics
118
+ assert_metrics_recorded_exclusive([])
119
119
  end
120
120
 
121
121
  def test_trace_execution_scoped_records_metric_data_from_callback
@@ -212,9 +212,8 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
212
212
 
213
213
  method_c1
214
214
 
215
- refute_nil @stats_engine.lookup_stats("c1")
216
- assert_nil @stats_engine.lookup_stats("c2")
217
- refute_nil @stats_engine.lookup_stats("c3")
215
+ assert_metrics_recorded(['c1', 'c3'])
216
+ assert_metrics_not_recorded('c2')
218
217
 
219
218
  assert_equal ['c2', 'c1'], @scope_listener.scopes
220
219
  end