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.
- checksums.yaml +7 -0
- data/CHANGELOG +61 -0
- data/lib/new_relic/agent.rb +14 -8
- data/lib/new_relic/agent/agent.rb +43 -28
- data/lib/new_relic/agent/agent_logger.rb +21 -20
- data/lib/new_relic/agent/configuration/default_source.rb +31 -1
- data/lib/new_relic/agent/database.rb +2 -1
- data/lib/new_relic/agent/datastores.rb +177 -0
- data/lib/new_relic/agent/datastores/metric_helper.rb +85 -0
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +11 -20
- data/lib/new_relic/agent/deprecator.rb +18 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +20 -35
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +116 -57
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -20
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +104 -172
- data/lib/new_relic/agent/instrumentation/memcache.rb +104 -52
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +9 -0
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +15 -2
- data/lib/new_relic/agent/instrumentation/mongo.rb +5 -18
- data/lib/new_relic/agent/instrumentation/sequel_helper.rb +36 -0
- data/lib/new_relic/agent/new_relic_service.rb +4 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -17
- data/lib/new_relic/agent/threading/backtrace_service.rb +28 -5
- data/lib/new_relic/agent/transaction.rb +63 -34
- data/lib/new_relic/agent/transaction_event_aggregator.rb +0 -4
- data/lib/new_relic/agent/transaction_sampler.rb +11 -5
- data/lib/new_relic/rack/error_collector.rb +0 -1
- data/lib/new_relic/version.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +28 -56
- data/lib/sequel/plugins/newrelic_instrumentation.rb +28 -45
- data/newrelic_rpm.gemspec +0 -7
- data/test/agent_helper.rb +35 -16
- data/test/environments/rails31/Gemfile +1 -0
- data/test/environments/rails32/Gemfile +1 -0
- data/test/helpers/mongo_metric_builder.rb +2 -3
- data/test/multiverse/lib/multiverse/output_collector.rb +24 -9
- data/test/multiverse/lib/multiverse/suite.rb +5 -0
- data/test/multiverse/suites/active_record/Envfile +6 -4
- data/test/multiverse/suites/active_record/active_record_test.rb +32 -73
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +0 -1
- data/test/multiverse/suites/activemerchant/activemerchant_test.rb +0 -3
- data/test/multiverse/suites/agent_only/agent_run_id_handling_test.rb +0 -1
- data/test/multiverse/suites/agent_only/audit_log_test.rb +0 -1
- data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +0 -2
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +0 -1
- data/test/multiverse/suites/agent_only/custom_analytics_events_test.rb +0 -2
- data/test/multiverse/suites/agent_only/custom_queue_time_test.rb +0 -1
- data/test/multiverse/suites/agent_only/encoding_handling_test.rb +0 -2
- data/test/multiverse/suites/agent_only/exclusive_time_test.rb +0 -2
- data/test/multiverse/suites/agent_only/harvest_timestamps_test.rb +0 -1
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +0 -1
- data/test/multiverse/suites/agent_only/keepalive_test.rb +0 -1
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +54 -9
- data/test/multiverse/suites/agent_only/labels_test.rb +0 -2
- data/test/multiverse/suites/agent_only/logging_test.rb +0 -1
- data/test/multiverse/suites/agent_only/marshaling_test.rb +0 -1
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +0 -2
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +5 -7
- data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +0 -1
- data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +0 -2
- data/test/multiverse/suites/agent_only/ssl_test.rb +0 -2
- data/test/multiverse/suites/agent_only/synthetics_test.rb +0 -1
- data/test/multiverse/suites/agent_only/testing_app.rb +21 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +1 -2
- data/test/multiverse/suites/agent_only/transaction_ignoring_test.rb +0 -2
- data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +0 -1
- data/test/multiverse/suites/agent_only/xray_sessions_test.rb +69 -34
- data/test/multiverse/suites/capistrano/deployment_test.rb +0 -1
- data/test/multiverse/suites/capistrano2/deployment_test.rb +0 -1
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +0 -2
- data/test/multiverse/suites/curb/curb_test.rb +0 -2
- data/test/multiverse/suites/datamapper/Envfile +26 -3
- data/test/multiverse/suites/datamapper/config/newrelic.yml +1 -0
- data/test/multiverse/suites/datamapper/datamapper_test.rb +271 -37
- data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +0 -1
- data/test/multiverse/suites/delayed_job/Envfile +31 -8
- data/test/multiverse/suites/delayed_job/delayed_job_sampler_test.rb +0 -3
- data/test/multiverse/suites/delayed_job/unsupported_backend_test.rb +0 -3
- data/test/multiverse/suites/excon/excon_test.rb +0 -2
- data/test/multiverse/suites/grape/grape_test.rb +0 -3
- data/test/multiverse/suites/grape/grape_versioning_test.rb +0 -3
- data/test/multiverse/suites/grape/unsupported_version_test.rb +0 -3
- data/test/multiverse/suites/high_security/high_security_test.rb +0 -1
- data/test/multiverse/suites/httpclient/httpclient_test.rb +0 -2
- data/test/multiverse/suites/json/json_test.rb +0 -1
- data/test/multiverse/suites/marshalling/marshalling_test.rb +0 -1
- data/test/multiverse/suites/memcached/Envfile +52 -0
- data/test/multiverse/suites/memcached/dalli_test.rb +89 -0
- data/test/multiverse/suites/memcached/memcache_client_test.rb +25 -0
- data/test/multiverse/suites/memcached/memcache_test_cases.rb +302 -0
- data/test/multiverse/suites/memcached/memcached_test.rb +159 -0
- data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +26 -17
- data/test/multiverse/suites/mongo/mongo_connection_test.rb +0 -1
- data/test/multiverse/suites/mongo/mongo_instrumentation_test.rb +0 -1
- data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +0 -1
- data/test/multiverse/suites/net_http/net_http_test.rb +0 -2
- data/test/multiverse/suites/padrino/padrino_test.rb +0 -3
- data/test/multiverse/suites/rack/http_response_code_test.rb +0 -1
- data/test/multiverse/suites/rack/nested_non_rack_app_test.rb +1 -1
- data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +12 -12
- data/test/multiverse/suites/rack/rack_cascade_test.rb +0 -1
- data/test/multiverse/suites/rack/rack_env_mutation_test.rb +0 -1
- data/test/multiverse/suites/rack/rack_parameter_filtering_test.rb +0 -1
- data/test/multiverse/suites/rack/rack_unsupported_version_test.rb +0 -2
- data/test/multiverse/suites/rack/url_map_test.rb +3 -2
- data/test/multiverse/suites/rails/Envfile +3 -0
- data/test/multiverse/suites/rails/activejob_test.rb +0 -1
- data/test/multiverse/suites/rails/app.rb +0 -1
- data/test/multiverse/suites/rails/parameter_capture_test.rb +13 -0
- data/test/multiverse/suites/rails/rails3_app/app_rails3_plus.rb +5 -0
- data/test/multiverse/suites/rails/transaction_ignoring_test.rb +0 -2
- data/test/multiverse/suites/resque/instrumentation_test.rb +0 -2
- data/test/multiverse/suites/resque/resque_marshalling_test.rb +0 -1
- data/test/multiverse/suites/sequel/sequel_extension_test.rb +135 -0
- data/test/multiverse/suites/sequel/sequel_helpers.rb +62 -0
- data/test/multiverse/suites/sequel/sequel_plugin_test.rb +230 -0
- data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +0 -2
- data/test/multiverse/suites/sinatra/ignoring_test.rb +0 -2
- data/test/multiverse/suites/sinatra/nested_middleware_test.rb +0 -2
- data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +0 -1
- data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +0 -2
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +14 -12
- data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +0 -1
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +0 -2
- data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +0 -2
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +0 -2
- data/test/multiverse/suites/yajl/yajl_test.rb +0 -1
- data/test/new_relic/agent/agent/start_test.rb +2 -2
- data/test/new_relic/agent/agent_logger_test.rb +6 -3
- data/test/new_relic/agent/datastores/metric_helper_test.rb +61 -0
- data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +20 -21
- data/test/new_relic/agent/datastores_test.rb +195 -0
- data/test/new_relic/agent/deprecator_test.rb +52 -0
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +20 -26
- data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +58 -53
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +7 -20
- data/test/new_relic/agent/instrumentation/middleware_proxy_test.rb +19 -0
- data/test/new_relic/agent/instrumentation/sequel_helper_test.rb +36 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +1 -0
- data/test/new_relic/agent/method_tracer_test.rb +3 -4
- data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
- data/test/new_relic/agent/threading/backtrace_service_test.rb +29 -4
- data/test/new_relic/agent/transaction_event_aggregator_test.rb +0 -4
- data/test/new_relic/agent/transaction_test.rb +100 -2
- data/test/new_relic/agent_test.rb +3 -3
- data/test/new_relic/http_client_test_cases.rb +0 -1
- data/test/new_relic/multiverse_helpers.rb +7 -0
- data/test/new_relic/transaction_ignoring_test_cases.rb +0 -2
- data/test/new_relic/transaction_sample_test.rb +11 -2
- data/test/performance/README.md +37 -17
- data/test/performance/lib/performance.rb +1 -0
- data/test/performance/lib/performance/baseline_compare_reporter.rb +11 -7
- data/test/performance/lib/performance/console_reporter.rb +29 -5
- data/test/performance/lib/performance/formatting_helpers.rb +22 -0
- data/test/performance/lib/performance/instrumentation/stackprof.rb +11 -1
- data/test/performance/lib/performance/result.rb +17 -6
- data/test/performance/lib/performance/runner.rb +7 -3
- data/test/performance/lib/performance/test_case.rb +89 -21
- data/test/performance/script/runner +13 -1
- data/test/performance/suites/active_record.rb +47 -0
- data/test/performance/suites/config.rb +4 -48
- data/test/performance/suites/marshalling.rb +20 -30
- data/test/performance/suites/queue_time.rb +1 -1
- data/test/performance/suites/rack_middleware.rb +1 -1
- data/test/performance/suites/rum_autoinsertion.rb +1 -1
- data/test/performance/suites/sql_obfuscation.rb +2 -2
- data/test/performance/suites/startup.rb +1 -1
- data/test/performance/suites/stats_hash.rb +7 -11
- data/test/performance/suites/thread_profiling.rb +20 -25
- data/test/performance/suites/trace_execution_scoped.rb +2 -2
- data/test/performance/suites/transaction_tracing.rb +4 -2
- data/test/test_helper.rb +5 -1
- metadata +53 -100
- data.tar.gz.sig +0 -0
- data/gem-public_cert.pem +0 -20
- data/lib/new_relic/agent/datastores/mongo/metric_generator.rb +0 -33
- data/test/multiverse/suites/sequel/sequel_instrumentation_test.rb +0 -289
- data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +0 -69
- data/test/new_relic/agent/memcache_instrumentation_test.rb +0 -155
- metadata.gz.sig +0 -2
@@ -14,9 +14,7 @@ require 'logger'
|
|
14
14
|
require 'stringio'
|
15
15
|
|
16
16
|
require 'fake_collector'
|
17
|
-
require 'multiverse_helpers'
|
18
17
|
require File.join(File.dirname(__FILE__), "test_worker")
|
19
|
-
require File.join(File.dirname(__FILE__), "..", "..", "..", "agent_helper")
|
20
18
|
|
21
19
|
class SidekiqTest < Minitest::Test
|
22
20
|
JOB_COUNT = 5
|
@@ -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 File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper'))
|
6
|
-
|
7
5
|
class MiddlewareApp < Sinatra::Base
|
8
6
|
get '/middle' do
|
9
7
|
"From the middlewarez"
|
@@ -4,7 +4,6 @@
|
|
4
4
|
|
5
5
|
require 'sinatra'
|
6
6
|
require File.expand_path(File.join(File.dirname(__FILE__), 'sinatra_test_cases'))
|
7
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper'))
|
8
7
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'helpers', 'exceptions'))
|
9
8
|
|
10
9
|
include NewRelic::TestHelpers::Exceptions
|
@@ -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
|
class SinatraErrorTracingTestApp < Sinatra::Base
|
8
6
|
configure do
|
9
7
|
set :show_exceptions, false
|
@@ -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
|
class SinatraTestApp < Sinatra::Base
|
8
6
|
get '/hello/:name' do |name|
|
9
7
|
name ||= 'world'
|
@@ -44,16 +42,18 @@ class SinatraMetricExplosionTest < Minitest::Test
|
|
44
42
|
|
45
43
|
def test_transaction_name_from_route
|
46
44
|
get '/hello/world'
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
assert_metrics_recorded([
|
46
|
+
'Controller/Sinatra/SinatraTestApp/GET hello/([^/?#]+)',
|
47
|
+
'Apdex/Sinatra/SinatraTestApp/GET hello/([^/?#]+)'
|
48
|
+
])
|
50
49
|
end
|
51
50
|
|
52
51
|
def test_transaction_name_from_path
|
53
52
|
get '/wrong'
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
assert_metrics_recorded([
|
54
|
+
'Controller/Sinatra/SinatraTestApp/GET (unknown)',
|
55
|
+
'Apdex/Sinatra/SinatraTestApp/GET (unknown)'
|
56
|
+
])
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_transaction_name_does_not_explode
|
@@ -63,7 +63,7 @@ class SinatraMetricExplosionTest < Minitest::Test
|
|
63
63
|
get '/hello/isitmeyourelookingfor?'
|
64
64
|
get '/another_controller'
|
65
65
|
|
66
|
-
metric_names = ::NewRelic::Agent.agent.stats_engine.
|
66
|
+
metric_names = ::NewRelic::Agent.agent.stats_engine.to_h.keys.map(&:to_s)
|
67
67
|
metric_names -= [
|
68
68
|
'CPU/User Time',
|
69
69
|
"Middleware/all",
|
@@ -72,6 +72,7 @@ class SinatraMetricExplosionTest < Minitest::Test
|
|
72
72
|
]
|
73
73
|
|
74
74
|
name_beginnings_to_ignore = [
|
75
|
+
"ApdexAll",
|
75
76
|
"Supportability",
|
76
77
|
"GC/Transaction",
|
77
78
|
"Nested/Controller",
|
@@ -87,8 +88,9 @@ class SinatraMetricExplosionTest < Minitest::Test
|
|
87
88
|
def test_does_not_break_when_no_verb_matches
|
88
89
|
post '/some/garbage'
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
assert_metrics_recorded([
|
92
|
+
'Controller/Sinatra/SinatraTestApp/POST (unknown)',
|
93
|
+
'Apdex/Sinatra/SinatraTestApp/POST (unknown)'
|
94
|
+
])
|
93
95
|
end
|
94
96
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
4
|
|
5
5
|
require File.expand_path(File.join(File.dirname(__FILE__), 'sinatra_test_cases'))
|
6
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper'))
|
7
6
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'helpers', 'exceptions'))
|
8
7
|
|
9
8
|
class SinatraModularTestApp < Sinatra::Base
|
@@ -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
|
class SinatraRouteTestApp < Sinatra::Base
|
8
6
|
configure do
|
9
7
|
# create a condition (sintra's version of a before_filter) that returns the
|
@@ -6,8 +6,6 @@
|
|
6
6
|
# module Sinatra apps. The sinatra_class_test and sinatra_modular_test files
|
7
7
|
# both maintain the same app structure in both forms, and this exercises them.
|
8
8
|
|
9
|
-
require 'multiverse_helpers'
|
10
|
-
|
11
9
|
module SinatraTestCases
|
12
10
|
include Rack::Test::Methods
|
13
11
|
include MultiverseHelpers
|
@@ -6,8 +6,6 @@ require "typhoeus"
|
|
6
6
|
require "newrelic_rpm"
|
7
7
|
require "http_client_test_cases"
|
8
8
|
|
9
|
-
require File.join(File.dirname(__FILE__), "..", "..", "..", "agent_helper")
|
10
|
-
|
11
9
|
if NewRelic::Agent::Instrumentation::TyphoeusTracing.is_supported_version?
|
12
10
|
|
13
11
|
class TyphoeusTest < Minitest::Test
|
@@ -2,7 +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
5
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'new_relic', 'marshalling_test_cases')
|
7
6
|
|
8
7
|
# This is the problematic thing that overrides our JSON marshalling
|
@@ -91,7 +91,7 @@ class NewRelic::Agent::Agent::StartTest < Minitest::Test
|
|
91
91
|
def test_install_exit_handler_positive
|
92
92
|
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
93
93
|
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
|
94
|
-
self.expects(:
|
94
|
+
self.expects(:sinatra_classic_app?).returns(false)
|
95
95
|
# we are overriding at_exit above, to immediately return, so we can
|
96
96
|
# test the shutdown logic. It's somewhat unfortunate, but we can't
|
97
97
|
# kill the interpreter during a test.
|
@@ -112,7 +112,7 @@ class NewRelic::Agent::Agent::StartTest < Minitest::Test
|
|
112
112
|
with_config(:send_data_one_exit => true) do
|
113
113
|
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
114
114
|
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
|
115
|
-
self.expects(:
|
115
|
+
self.expects(:sinatra_classic_app?).returns(true)
|
116
116
|
install_exit_handler
|
117
117
|
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
118
118
|
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(true)
|
@@ -350,12 +350,15 @@ class AgentLoggerTest < Minitest::Test
|
|
350
350
|
|
351
351
|
def test_clear_already_logged
|
352
352
|
logger = create_basic_logger
|
353
|
-
logger.log_once(:warn, :
|
353
|
+
logger.log_once(:warn, :positive, "thoughts")
|
354
|
+
logger.log_once(:warn, :positive, "thoughts")
|
355
|
+
|
356
|
+
assert_logged "thoughts"
|
354
357
|
|
355
|
-
refute_empty logger.already_logged
|
356
358
|
logger.clear_already_logged
|
359
|
+
logger.log_once(:warn, :positive, "thoughts")
|
357
360
|
|
358
|
-
|
361
|
+
assert_logged "thoughts", "thoughts"
|
359
362
|
end
|
360
363
|
|
361
364
|
#
|
@@ -0,0 +1,61 @@
|
|
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/datastores/metric_helper'
|
7
|
+
|
8
|
+
module NewRelic
|
9
|
+
module Agent
|
10
|
+
class Datastores::MetricHelperTest < Minitest::Test
|
11
|
+
def setup
|
12
|
+
@product = "JonanDB"
|
13
|
+
@collection = "wiggles"
|
14
|
+
@operation = "select"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_statement_metric_for
|
18
|
+
expected = "Datastore/statement/JonanDB/wiggles/select"
|
19
|
+
result = Datastores::MetricHelper.statement_metric_for(@product, @collection, @operation)
|
20
|
+
assert_equal expected, result
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_operation_metric_for
|
24
|
+
expected = "Datastore/operation/JonanDB/select"
|
25
|
+
result = Datastores::MetricHelper.operation_metric_for(@product, @operation)
|
26
|
+
assert_equal expected, result
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_metrics_for_in_web_context
|
30
|
+
Transaction.stubs(:recording_web_transaction?).returns(true)
|
31
|
+
expected = [
|
32
|
+
"Datastore/statement/JonanDB/wiggles/select",
|
33
|
+
"Datastore/operation/JonanDB/select",
|
34
|
+
"Datastore/JonanDB/allWeb",
|
35
|
+
"Datastore/JonanDB/all",
|
36
|
+
"Datastore/allWeb",
|
37
|
+
"Datastore/all"
|
38
|
+
]
|
39
|
+
|
40
|
+
result = Datastores::MetricHelper.metrics_for(@product, @operation, @collection)
|
41
|
+
assert_equal expected, result
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_metrics_for_outside_web_context
|
45
|
+
Transaction.stubs(:recording_web_transaction?).returns(false)
|
46
|
+
expected = [
|
47
|
+
"Datastore/statement/JonanDB/wiggles/select",
|
48
|
+
"Datastore/operation/JonanDB/select",
|
49
|
+
"Datastore/JonanDB/allOther",
|
50
|
+
"Datastore/JonanDB/all",
|
51
|
+
"Datastore/allOther",
|
52
|
+
"Datastore/all"
|
53
|
+
]
|
54
|
+
|
55
|
+
result = Datastores::MetricHelper.metrics_for(@product, @operation, @collection)
|
56
|
+
assert_equal expected, result
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -21,33 +21,37 @@ class NewRelic::Agent::Datastores::Mongo::MetricTranslatorTest < Minitest::Test
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_build_metrics_includes_web
|
24
|
-
|
25
|
-
|
24
|
+
in_web_transaction do
|
25
|
+
metrics = build_test_metrics('test')
|
26
|
+
assert_includes metrics, 'Datastore/allWeb'
|
27
|
+
end
|
26
28
|
end
|
27
29
|
|
28
30
|
def test_build_metrics_includes_other
|
29
|
-
|
30
|
-
|
31
|
+
in_background_transaction do
|
32
|
+
metrics = build_test_metrics('test')
|
33
|
+
assert_includes metrics, 'Datastore/allOther'
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
37
|
def test_build_metrics_includes_all_for_web
|
34
|
-
|
35
|
-
|
38
|
+
in_web_transaction do
|
39
|
+
metrics = build_test_metrics('test')
|
40
|
+
assert_includes metrics, 'Datastore/all'
|
41
|
+
end
|
36
42
|
end
|
37
43
|
|
38
44
|
def test_build_metrics_includes_all_for_other
|
39
|
-
|
40
|
-
|
45
|
+
in_background_transaction do
|
46
|
+
metrics = build_test_metrics('test')
|
47
|
+
assert_includes metrics, 'Datastore/all'
|
48
|
+
end
|
41
49
|
end
|
42
50
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def test_build_metrics_doesnt_include_activerecord_all_on_other
|
49
|
-
metrics = build_test_metrics('test', :other)
|
50
|
-
assert_not_includes metrics, 'ActiveRecord/all'
|
51
|
+
def test_build_metrics_is_graceful_if_exceptions_are_raised
|
52
|
+
NewRelic::Agent::Datastores::MetricHelper.stubs(:metrics_for).raises("Boom")
|
53
|
+
metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, {})
|
54
|
+
assert_empty metrics
|
51
55
|
end
|
52
56
|
|
53
57
|
def test_metrics_for_find
|
@@ -313,9 +317,4 @@ class NewRelic::Agent::Datastores::Mongo::MetricTranslatorTest < Minitest::Test
|
|
313
317
|
assert_equal expected, metrics
|
314
318
|
assert_metrics_recorded(["Supportability/Mongo/UnknownCollection"])
|
315
319
|
end
|
316
|
-
|
317
|
-
def test_instance_metric
|
318
|
-
metric = NewRelic::Agent::Datastores::Mongo::MetricTranslator.instance_metric('localhost', '27017', @database_name)
|
319
|
-
assert_equal 'Datastore/instance/MongoDB/localhost:27017/multiverse', metric
|
320
|
-
end
|
321
320
|
end
|
@@ -0,0 +1,195 @@
|
|
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 'new_relic/agent/datastores'
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
7
|
+
|
8
|
+
class NewRelic::Agent::DatastoresTest < Minitest::Test
|
9
|
+
class MyFirstDatabase
|
10
|
+
THE_OBJECT = Object.new
|
11
|
+
|
12
|
+
def find
|
13
|
+
THE_OBJECT
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
end
|
18
|
+
|
19
|
+
def internal
|
20
|
+
end
|
21
|
+
|
22
|
+
private :internal
|
23
|
+
|
24
|
+
NewRelic::Agent::Datastores.trace self, :find, "MyFirstDatabase"
|
25
|
+
NewRelic::Agent::Datastores.trace self, :save, "MyFirstDatabase", "create"
|
26
|
+
NewRelic::Agent::Datastores.trace self, :internal, "MyFirstDatabase"
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup
|
30
|
+
NewRelic::Agent.drop_buffered_data
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_still_calls_through
|
34
|
+
assert_equal MyFirstDatabase::THE_OBJECT, MyFirstDatabase.new.find
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_in_web_transaction
|
38
|
+
in_web_transaction("txn") do
|
39
|
+
MyFirstDatabase.new.find
|
40
|
+
end
|
41
|
+
|
42
|
+
assert_metrics("find", "Web")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_in_other_transaction
|
46
|
+
in_background_transaction("txn") do
|
47
|
+
MyFirstDatabase.new.find
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_metrics("find", "Other")
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_outside_transaction
|
54
|
+
MyFirstDatabase.new.find
|
55
|
+
assert_metrics_recorded([
|
56
|
+
"Datastore/operation/MyFirstDatabase/find",
|
57
|
+
"Datastore/MyFirstDatabase/allOther",
|
58
|
+
"Datastore/MyFirstDatabase/all",
|
59
|
+
"Datastore/allOther",
|
60
|
+
"Datastore/all"])
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_separate_operation_name
|
64
|
+
in_background_transaction("txn") do
|
65
|
+
MyFirstDatabase.new.save
|
66
|
+
end
|
67
|
+
|
68
|
+
assert_metrics("create", "Other")
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_safe_to_reinstrument
|
72
|
+
MyFirstDatabase.class_eval do
|
73
|
+
NewRelic::Agent::Datastores.trace self, :find, "MyFirstDatabase", "find"
|
74
|
+
end
|
75
|
+
|
76
|
+
assert_equal MyFirstDatabase::THE_OBJECT, MyFirstDatabase.new.find
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_method_retains_visbility
|
80
|
+
private_methods = MyFirstDatabase.private_instance_methods.map(&:to_sym)
|
81
|
+
assert_includes private_methods, :internal
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_wrap_doesnt_interfere
|
85
|
+
result = NewRelic::Agent::Datastores.wrap("MyFirstDatabase", "op") do
|
86
|
+
"yo"
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_equal "yo", result
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_wrap
|
93
|
+
in_background_transaction("txn") do
|
94
|
+
NewRelic::Agent::Datastores.wrap("MyFirstDatabase", "op", "coll") do
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
assert_statement_metrics("op", "coll", "Other")
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_wrap_with_only_operation
|
102
|
+
in_background_transaction("txn") do
|
103
|
+
NewRelic::Agent::Datastores.wrap("MyFirstDatabase", "op") do
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
assert_metrics("op", "Other")
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_wrap_with_no_operation
|
111
|
+
in_background_transaction("txn") do
|
112
|
+
NewRelic::Agent::Datastores.wrap("MyFirstDatabase", nil) do
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
refute_metrics_recorded([
|
117
|
+
"Datastore/operation/MyFirstDatabase/",
|
118
|
+
"Datastore/MyFirstDatabase/allOther",
|
119
|
+
"Datastore/MyFirstDatabase/all",
|
120
|
+
"Datastore/allOther",
|
121
|
+
"Datastore/all"])
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_wrap_calls_notice
|
125
|
+
noticed = nil
|
126
|
+
notice = Proc.new do |*args|
|
127
|
+
noticed = args
|
128
|
+
end
|
129
|
+
|
130
|
+
NewRelic::Agent::Datastores.wrap("MyFirstDatabase", "op", "coll", notice) do
|
131
|
+
"yo"
|
132
|
+
end
|
133
|
+
|
134
|
+
result, scoped_metric, elapsed = noticed
|
135
|
+
|
136
|
+
assert_equal "yo", result
|
137
|
+
assert_equal "Datastore/statement/MyFirstDatabase/coll/op", scoped_metric
|
138
|
+
assert_instance_of Float, elapsed
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_notice_sql
|
142
|
+
query = "SELECT * FROM SomeThings"
|
143
|
+
metric = "Datastore/statement/MyFirstDatabase/SomeThing/find"
|
144
|
+
elapsed = 1.0
|
145
|
+
|
146
|
+
agent = NewRelic::Agent.instance
|
147
|
+
agent.transaction_sampler.expects(:notice_sql).with(query, nil, elapsed)
|
148
|
+
agent.sql_sampler.expects(:notice_sql).with(query, metric, nil, elapsed)
|
149
|
+
|
150
|
+
NewRelic::Agent::Datastores.notice_sql(query, metric, elapsed)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_notice_statement
|
154
|
+
query = "key"
|
155
|
+
elapsed = 1.0
|
156
|
+
|
157
|
+
agent = NewRelic::Agent.instance
|
158
|
+
agent.transaction_sampler.expects(:notice_nosql_statement).with(query, elapsed)
|
159
|
+
|
160
|
+
NewRelic::Agent::Datastores.notice_statement(query, elapsed)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_dont_notice_statement_based_on_record_sql_setting
|
164
|
+
query = "key"
|
165
|
+
elapsed = 1.0
|
166
|
+
|
167
|
+
agent = NewRelic::Agent.instance
|
168
|
+
agent.transaction_sampler.expects(:notice_nosql_statement).never
|
169
|
+
|
170
|
+
with_config(:'transaction_tracer.record_sql' => 'none') do
|
171
|
+
NewRelic::Agent::Datastores.notice_statement(query, elapsed)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def assert_statement_metrics(operation, collection, type)
|
176
|
+
assert_metrics_recorded([
|
177
|
+
"Datastore/statement/MyFirstDatabase/#{collection}/#{operation}",
|
178
|
+
["Datastore/statement/MyFirstDatabase/#{collection}/#{operation}", "txn"],
|
179
|
+
"Datastore/operation/MyFirstDatabase/#{operation}",
|
180
|
+
"Datastore/MyFirstDatabase/all#{type}",
|
181
|
+
"Datastore/MyFirstDatabase/all",
|
182
|
+
"Datastore/all#{type}",
|
183
|
+
"Datastore/all"])
|
184
|
+
end
|
185
|
+
|
186
|
+
def assert_metrics(operation, type)
|
187
|
+
assert_metrics_recorded([
|
188
|
+
"Datastore/operation/MyFirstDatabase/#{operation}",
|
189
|
+
["Datastore/operation/MyFirstDatabase/#{operation}", "txn"],
|
190
|
+
"Datastore/MyFirstDatabase/all#{type}",
|
191
|
+
"Datastore/MyFirstDatabase/all",
|
192
|
+
"Datastore/all#{type}",
|
193
|
+
"Datastore/all"])
|
194
|
+
end
|
195
|
+
end
|