newrelic_rpm 3.18.1.330 → 4.0.0.332
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -74
- data/CHANGELOG.md +77 -0
- data/CONTRIBUTING.md +14 -6
- data/LICENSE +1 -88
- data/lib/new_relic/agent.rb +2 -103
- data/lib/new_relic/agent/agent.rb +3 -32
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +2 -6
- data/lib/new_relic/agent/configuration/default_source.rb +1 -8
- data/lib/new_relic/agent/configuration/yaml_source.rb +1 -12
- data/lib/new_relic/agent/cross_app_monitor.rb +2 -1
- data/lib/new_relic/agent/cross_app_tracing.rb +4 -2
- data/lib/new_relic/agent/datastores/mongo.rb +1 -1
- data/lib/new_relic/agent/datastores/redis.rb +1 -1
- data/lib/new_relic/agent/encoding_normalizer.rb +1 -20
- data/lib/new_relic/agent/error_collector.rb +8 -21
- data/lib/new_relic/agent/inbound_request_monitor.rb +4 -1
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +14 -30
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -1
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +4 -5
- data/lib/new_relic/agent/instrumentation/curb.rb +2 -2
- data/lib/new_relic/agent/instrumentation/excon.rb +3 -3
- data/lib/new_relic/agent/instrumentation/grape.rb +3 -3
- data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -2
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +2 -2
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +2 -2
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +3 -7
- data/lib/new_relic/agent/instrumentation/queue_time.rb +13 -15
- data/lib/new_relic/agent/instrumentation/rack.rb +4 -50
- data/lib/new_relic/agent/instrumentation/rake.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque.rb +1 -2
- data/lib/new_relic/agent/instrumentation/sinatra.rb +0 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
- data/lib/new_relic/agent/javascript_instrumentor.rb +3 -2
- data/lib/new_relic/agent/method_tracer.rb +1 -60
- data/lib/new_relic/agent/new_relic_service.rb +3 -2
- data/lib/new_relic/agent/new_relic_service/encoders.rb +5 -6
- data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +7 -16
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -3
- data/lib/new_relic/agent/pipe_service.rb +1 -3
- data/lib/new_relic/agent/rules_engine.rb +2 -17
- data/lib/new_relic/agent/stats_engine.rb +0 -2
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +0 -48
- data/lib/new_relic/agent/supported_versions.rb +12 -19
- data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
- data/lib/new_relic/agent/transaction.rb +0 -3
- data/lib/new_relic/agent/transaction/attributes.rb +1 -10
- data/lib/new_relic/agent/vm.rb +1 -4
- data/lib/new_relic/agent/vm/jruby_vm.rb +1 -3
- data/lib/new_relic/agent/vm/mri_vm.rb +2 -10
- data/lib/new_relic/control.rb +1 -2
- data/lib/new_relic/control/frameworks/rails.rb +1 -1
- data/lib/new_relic/control/frameworks/rails3.rb +1 -2
- data/lib/new_relic/control/frameworks/rails4.rb +1 -1
- data/lib/new_relic/control/frameworks/rails5.rb +1 -1
- data/lib/new_relic/control/instance_methods.rb +1 -1
- data/{vendor/gems/dependency_detection-0.0.1.build/lib → lib/new_relic}/dependency_detection.rb +0 -1
- data/lib/new_relic/helper.rb +6 -13
- data/lib/new_relic/language_support.rb +44 -139
- data/lib/new_relic/metric_spec.rb +0 -17
- data/lib/new_relic/noticed_error.rb +18 -27
- data/lib/new_relic/version.rb +3 -48
- data/lib/tasks/versions.rake +7 -5
- data/newrelic_rpm.gemspec +1 -16
- data/test/agent_helper.rb +4 -2
- data/test/environments/lib/environments/runner.rb +5 -14
- data/test/environments/norails/Gemfile +0 -8
- data/test/environments/rails21/Gemfile +0 -8
- data/test/environments/rails21/config/database.yml +1 -1
- data/test/environments/rails22/Gemfile +0 -8
- data/test/environments/rails22/config/database.yml +1 -1
- data/test/environments/rails23/Gemfile +1 -7
- data/test/environments/rails23/config/database.yml +1 -1
- data/test/environments/rails30/Gemfile +0 -1
- data/test/environments/rails30/config/database.yml +1 -1
- data/test/environments/rails31/Gemfile +0 -3
- data/test/environments/rails31/config/database.yml +1 -1
- data/test/environments/rails32/Gemfile +0 -3
- data/test/environments/rails32/config/database.yml +1 -1
- data/test/environments/rails40/Gemfile +0 -26
- data/test/environments/rails40/config/database.yml +1 -1
- data/test/environments/rails41/Gemfile +0 -18
- data/test/environments/rails41/config/database.yml +1 -1
- data/test/environments/rails42/Gemfile +0 -22
- data/test/environments/rails42/config/database.yml +1 -1
- data/test/environments/rails50/Gemfile +0 -13
- data/test/environments/rails50/config/database.yml +1 -1
- data/test/helpers/logging.rb +37 -0
- data/test/helpers/minitest.rb +50 -0
- data/test/helpers/misc.rb +87 -0
- data/test/helpers/transaction_sample.rb +44 -0
- data/test/multiverse/lib/multiverse/suite.rb +6 -91
- data/test/multiverse/script/runner +1 -1
- data/test/multiverse/suites/active_record/Envfile +1 -28
- data/test/multiverse/suites/active_record/active_record_test.rb +6 -6
- data/test/multiverse/suites/active_record/config/database.rb +2 -3
- data/test/multiverse/suites/active_record/config/database.yml +0 -2
- data/test/multiverse/suites/activemerchant/Envfile +4 -18
- data/test/multiverse/suites/agent_only/encoding_handling_test.rb +7 -15
- data/test/multiverse/suites/agent_only/error_events_test.rb +1 -7
- data/test/multiverse/suites/agent_only/harvest_timestamps_test.rb +4 -20
- data/test/multiverse/suites/agent_only/labels_test.rb +1 -1
- data/test/multiverse/suites/agent_only/marshaling_test.rb +5 -10
- data/test/multiverse/suites/agent_only/script/public_api_when_disabled.rb +0 -11
- data/test/multiverse/suites/agent_only/start_up_test.rb +3 -3
- data/test/multiverse/suites/agent_only/synthetics_test.rb +1 -1
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +0 -3
- data/test/multiverse/suites/agent_only/xray_sessions_test.rb +0 -3
- data/test/multiverse/suites/capistrano/Envfile +2 -4
- data/test/multiverse/suites/capistrano2/Envfile +0 -4
- data/test/multiverse/suites/curb/Envfile +3 -7
- data/test/multiverse/suites/datamapper/Envfile +2 -2
- data/test/multiverse/suites/datamapper/datamapper_test.rb +2 -2
- data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +0 -1
- data/test/multiverse/suites/delayed_job/Envfile +28 -41
- data/test/multiverse/suites/excon/Envfile +0 -3
- data/test/multiverse/suites/grape/Envfile +0 -4
- data/test/multiverse/suites/grape/grape_versioning_test.rb +2 -2
- data/test/multiverse/suites/grape/grape_versioning_test_api.rb +2 -2
- data/test/multiverse/suites/json/Envfile +1 -9
- data/test/multiverse/suites/marshalling/Envfile +0 -9
- data/test/multiverse/suites/memcached/Envfile +5 -23
- data/test/multiverse/suites/mongo/Envfile +9 -11
- data/test/multiverse/suites/padrino/Envfile +0 -6
- data/test/multiverse/suites/rack/http_response_code_test.rb +0 -1
- data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +5 -10
- 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/response_content_type_test.rb +0 -1
- data/test/multiverse/suites/rails/Envfile +1 -19
- data/test/multiverse/suites/rails/activejob_test.rb +1 -2
- data/test/multiverse/suites/rails/error_tracing_test.rb +0 -13
- data/test/multiverse/suites/rails/gc_instrumentation_test.rb +12 -32
- data/test/multiverse/suites/rake/Envfile +15 -22
- data/test/multiverse/suites/redis/redis_instrumentation_test.rb +1 -1
- data/test/multiverse/suites/sequel/database.rb +1 -4
- data/test/multiverse/suites/sidekiq/Envfile +13 -23
- data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +3 -3
- data/test/multiverse/suites/typhoeus/Envfile +0 -19
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -3
- data/test/multiverse/suites/yajl/Envfile +5 -0
- data/test/multiverse/suites/yajl/yajl_test.rb +1 -3
- data/test/new_relic/agent/agent/start_test.rb +3 -3
- data/test/new_relic/agent/agent_logger_test.rb +2 -2
- data/test/new_relic/agent/agent_test.rb +2 -2
- data/test/new_relic/agent/attribute_processing_test.rb +3 -4
- data/test/new_relic/agent/audit_logger_test.rb +4 -6
- data/test/new_relic/agent/aws_info_test.rb +17 -1
- data/test/new_relic/agent/busy_calculator_test.rb +14 -16
- data/test/new_relic/agent/configuration/manager_test.rb +1 -7
- data/test/new_relic/agent/cross_app_monitor_test.rb +1 -1
- data/test/new_relic/agent/database_test.rb +2 -10
- data/test/new_relic/agent/datastores/mongo/event_formatter_test.rb +90 -93
- data/test/new_relic/agent/datastores/redis_test.rb +14 -16
- data/test/new_relic/agent/encoding_normalizer_test.rb +38 -40
- data/test/new_relic/agent/error_collector_test.rb +16 -49
- data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +0 -6
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/mongodb_command_subscriber_test.rb +101 -103
- data/test/new_relic/agent/instrumentation/rack_test.rb +11 -14
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +0 -10
- data/test/new_relic/agent/javascript_instrumentor_test.rb +2 -2
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +0 -10
- data/test/new_relic/agent/method_tracer_test.rb +35 -76
- data/test/new_relic/agent/new_relic_service_test.rb +86 -102
- data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -9
- data/test/new_relic/agent/pipe_service_test.rb +2 -3
- data/test/new_relic/agent/rpm_agent_test.rb +0 -4
- data/test/new_relic/agent/sampled_buffer_test.rb +2 -2
- data/test/new_relic/agent/samplers/cpu_sampler_test.rb +28 -0
- data/test/new_relic/agent/samplers/memory_sampler_test.rb +66 -0
- data/test/new_relic/agent/sized_buffer_test.rb +1 -1
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +2 -14
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +44 -66
- data/test/new_relic/agent/stats_test.rb +6 -8
- data/test/new_relic/agent/synthetics_event_buffer_test.rb +1 -1
- data/test/new_relic/agent/transaction/attributes_test.rb +4 -12
- data/test/new_relic/agent/transaction_test.rb +2 -10
- data/test/new_relic/agent/utilization_data_test.rb +17 -1
- data/test/new_relic/agent/vm/mri_vm_test.rb +5 -7
- data/test/new_relic/agent_test.rb +0 -43
- data/test/new_relic/coerce_test.rb +1 -3
- data/test/new_relic/fake_collector.rb +3 -3
- data/test/new_relic/fake_external_server.rb +1 -1
- data/test/new_relic/fake_server.rb +1 -1
- data/test/new_relic/http_client_test_cases.rb +3 -3
- data/test/new_relic/language_support_test.rb +6 -12
- data/test/new_relic/latest_changes_test.rb +0 -11
- data/test/new_relic/license_test.rb +3 -8
- data/test/new_relic/multiverse_helpers.rb +1 -1
- data/test/new_relic/noticed_error_test.rb +11 -7
- data/test/new_relic/rack/browser_monitoring_test.rb +1 -3
- data/test/nullverse/nullverse_helper.rb +1 -1
- data/test/performance/lib/performance.rb +1 -1
- data/test/performance/lib/performance/instrumentation/gc_stats.rb +4 -6
- data/test/performance/lib/performance/instrumentation/perf_tools.rb +1 -1
- data/test/performance/lib/performance/instrumentation/stackprof.rb +1 -1
- data/test/performance/lib/performance/platform.rb +1 -8
- data/test/performance/script/runner +1 -3
- data/test/performance/suites/active_record.rb +3 -24
- data/test/test_helper.rb +9 -216
- metadata +9 -45
- data/lib/conditional_vendored_dependency_detection.rb +0 -7
- data/lib/new_relic/agent/hash_extensions.rb +0 -41
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +0 -39
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +0 -51
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +0 -47
- data/lib/new_relic/agent/instrumentation/rails4/errors.rb +0 -46
- data/lib/new_relic/agent/stats_engine/samplers.rb +0 -22
- data/lib/new_relic/agent/vm/rubinius_vm.rb +0 -140
- data/lib/new_relic/json_wrapper.rb +0 -78
- data/lib/new_relic/okjson.rb +0 -602
- data/lib/new_relic/rack/error_collector.rb +0 -27
- data/lib/new_relic/timer_lib.rb +0 -31
- data/test/helpers/runtime_detection.rb +0 -17
- data/test/multiverse/suites/no_json/Envfile +0 -12
- data/test/multiverse/suites/no_json/config/newrelic.yml +0 -27
- data/test/multiverse/suites/no_json/marshal_config_test.rb +0 -22
- data/test/new_relic/agent/hash_extensions_test.rb +0 -59
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +0 -22
- data/test/new_relic/agent/stats_engine/samplers_test.rb +0 -98
- data/test/new_relic/agent/vm/rubinius_vm_test.rb +0 -69
- data/test/new_relic/json_wrapper_test.rb +0 -32
- data/test/new_relic/rack/deferred_instrumentation_test.rb +0 -33
- data/test/new_relic/rack/error_collector_test.rb +0 -83
- data/test/new_relic/version_number_test.rb +0 -101
- data/test/script/before_install/revert_rubygems.sh +0 -15
- data/test/script/before_install/update_bundler.sh +0 -12
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +0 -7
@@ -48,17 +48,6 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
|
|
48
48
|
assert_equal 1, events.length
|
49
49
|
end
|
50
50
|
|
51
|
-
def test_drops_deprecated_options
|
52
|
-
expects_logging(:warn, any_parameters)
|
53
|
-
error = @error_collector.create_noticed_error(StandardError.new("message"),
|
54
|
-
:referer => "lalalalala",
|
55
|
-
:request => stub('request'),
|
56
|
-
:request_params => {:x => 'y'})
|
57
|
-
|
58
|
-
|
59
|
-
assert_empty error.attributes_from_notice_error
|
60
|
-
end
|
61
|
-
|
62
51
|
def test_exclude
|
63
52
|
@error_collector.ignore(["IOError"])
|
64
53
|
|
@@ -124,9 +113,15 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
|
|
124
113
|
end
|
125
114
|
|
126
115
|
def test_increments_count_on_errors
|
127
|
-
|
128
|
-
|
129
|
-
|
116
|
+
@error_collector.notice_error(StandardError.new("Boo"))
|
117
|
+
assert_metrics_recorded(
|
118
|
+
'Errors/all' => { :call_count => 1}
|
119
|
+
)
|
120
|
+
|
121
|
+
@error_collector.notice_error(StandardError.new("Boo"))
|
122
|
+
assert_metrics_recorded(
|
123
|
+
'Errors/all' => { :call_count => 2}
|
124
|
+
)
|
130
125
|
end
|
131
126
|
|
132
127
|
def test_increment_error_count_record_summary_and_web_txn_metric
|
@@ -250,33 +245,15 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
|
|
250
245
|
end
|
251
246
|
|
252
247
|
def test_extract_stack_trace
|
253
|
-
|
254
|
-
:original_exception => nil,
|
255
|
-
:backtrace => nil)
|
256
|
-
|
257
|
-
assert_equal('<no stack trace>', @error_collector.extract_stack_trace(exception))
|
248
|
+
assert_equal('<no stack trace>', @error_collector.extract_stack_trace(Exception.new))
|
258
249
|
end
|
259
250
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
def test_extract_stack_trace_uses_original_exception_second
|
268
|
-
nested_exception = mock('exception', :backtrace => "Bar STACK")
|
269
|
-
exception = mock('exception', :cause => nil, :original_exception => nested_exception)
|
270
|
-
|
271
|
-
assert_equal('Bar STACK', @error_collector.extract_stack_trace(exception))
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_extract_stack_trace_uses_backtrace_last
|
275
|
-
exception = mock('exception', :cause => nil,
|
276
|
-
:original_exception => nil,
|
277
|
-
:backtrace => "Baz STACK")
|
278
|
-
|
279
|
-
assert_equal('Baz STACK', @error_collector.extract_stack_trace(exception))
|
251
|
+
if defined?(Rails) && Rails::VERSION::MAJOR < 5
|
252
|
+
def test_extract_stack_trace_from_original_exception
|
253
|
+
orig = mock('original', :backtrace => "STACK STACK STACK")
|
254
|
+
exception = mock('exception', :original_exception => orig)
|
255
|
+
assert_equal('STACK STACK STACK', @error_collector.extract_stack_trace(exception))
|
256
|
+
end
|
280
257
|
end
|
281
258
|
|
282
259
|
def test_skip_notice_error_is_true_if_the_error_collector_is_disabled
|
@@ -410,16 +387,6 @@ class NewRelic::Agent::ErrorCollectorTest < Minitest::Test
|
|
410
387
|
|
411
388
|
private
|
412
389
|
|
413
|
-
def expects_error_count_increase(increase)
|
414
|
-
count = get_error_stats
|
415
|
-
yield
|
416
|
-
assert_equal increase, get_error_stats - count
|
417
|
-
end
|
418
|
-
|
419
|
-
def get_error_stats
|
420
|
-
NewRelic::Agent.get_stats("Errors/all").call_count
|
421
|
-
end
|
422
|
-
|
423
390
|
def wrapped_filter_proc
|
424
391
|
Proc.new do |e|
|
425
392
|
if e.is_a? IOError
|
@@ -62,11 +62,5 @@ module NewRelic::Agent::Instrumentation
|
|
62
62
|
assert_equal "other", operation
|
63
63
|
assert_nil collection
|
64
64
|
end
|
65
|
-
|
66
|
-
def test_rollup_metrics_for_is_deprecated
|
67
|
-
NewRelic::Agent::Deprecator.expects(:deprecate)
|
68
|
-
result = ActiveRecordHelper.rollup_metrics_for("boo")
|
69
|
-
assert_equal ["Datastore/allOther", "Datastore/all"], result
|
70
|
-
end
|
71
65
|
end
|
72
66
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
MIN_RAILS_VERSION = 4
|
6
6
|
|
7
|
-
if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= MIN_RAILS_VERSION && !NewRelic::LanguageSupport.
|
7
|
+
if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= MIN_RAILS_VERSION && !NewRelic::LanguageSupport.jruby?
|
8
8
|
|
9
9
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
10
10
|
require 'new_relic/agent/instrumentation/active_record_subscriber'
|
@@ -7,108 +7,106 @@ require 'new_relic/agent/instrumentation/mongodb_command_subscriber'
|
|
7
7
|
|
8
8
|
class NewRelic::Agent::Instrumentation::MongodbCommandSubscriberTest < Minitest::Test
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
@subscriber.succeeded(@succeeded_event)
|
112
|
-
end
|
10
|
+
def setup
|
11
|
+
freeze_time
|
12
|
+
@started_event = mock('started event')
|
13
|
+
@started_event.stubs(:operation_id).returns(1)
|
14
|
+
@started_event.stubs(:command_name).returns('find')
|
15
|
+
@started_event.stubs(:database_name).returns('mongodb-test')
|
16
|
+
@started_event.stubs(:command).returns({ 'find' => 'users', 'filter' => { 'name' => 'test' }})
|
17
|
+
address = stub('address', :host => "127.0.0.1", :port => 27017)
|
18
|
+
@started_event.stubs(:address).returns(address)
|
19
|
+
|
20
|
+
@succeeded_event = mock('succeeded event')
|
21
|
+
@succeeded_event.stubs(:operation_id).returns(1)
|
22
|
+
@succeeded_event.stubs(:duration).returns(2)
|
23
|
+
|
24
|
+
@subscriber = NewRelic::Agent::Instrumentation::MongodbCommandSubscriber.new
|
25
|
+
|
26
|
+
NewRelic::Agent::Hostname.stubs(:get).returns("nerd-server")
|
27
|
+
@stats_engine = NewRelic::Agent.instance.stats_engine
|
28
|
+
@stats_engine.clear_stats
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_records_metrics_for_simple_find
|
32
|
+
in_transaction { simulate_query }
|
33
|
+
|
34
|
+
metric_name = 'Datastore/statement/MongoDB/users/find'
|
35
|
+
assert_metrics_recorded(
|
36
|
+
metric_name => { :call_count => 1, :total_call_time => 2.0 }
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_records_scoped_metrics
|
41
|
+
in_transaction('test_txn') { simulate_query }
|
42
|
+
|
43
|
+
metric_name = 'Datastore/statement/MongoDB/users/find'
|
44
|
+
assert_metrics_recorded(
|
45
|
+
[ metric_name, 'test_txn' ] => { :call_count => 1, :total_call_time => 2 }
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_records_nothing_if_tracing_disabled
|
50
|
+
NewRelic::Agent.disable_all_tracing { simulate_query }
|
51
|
+
metric_name = 'Datastore/statement/MongoDB/users/find'
|
52
|
+
assert_metrics_not_recorded([ metric_name ])
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_records_rollup_metrics
|
56
|
+
in_web_transaction { simulate_query }
|
57
|
+
|
58
|
+
assert_metrics_recorded(
|
59
|
+
'Datastore/operation/MongoDB/find' => { :call_count => 1, :total_call_time => 2 },
|
60
|
+
'Datastore/allWeb' => { :call_count => 1, :total_call_time => 2 },
|
61
|
+
'Datastore/all' => { :call_count => 1, :total_call_time => 2 }
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_not_raise_due_to_an_exception_during_instrumentation_callback
|
66
|
+
@subscriber.stubs(:metrics).raises(StandardError)
|
67
|
+
in_transaction { simulate_query }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_records_instance_metrics_for_tcp_connection
|
71
|
+
in_transaction { simulate_query }
|
72
|
+
assert_metrics_recorded('Datastore/instance/MongoDB/nerd-server/27017')
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_records_instance_metrics_for_unix_domain_socket
|
76
|
+
address = stub('address', :host => "/tmp/mongodb-27017.sock", :port => nil)
|
77
|
+
@started_event.stubs(:address).returns(address)
|
78
|
+
in_transaction { simulate_query }
|
79
|
+
assert_metrics_recorded('Datastore/instance/MongoDB/nerd-server//tmp/mongodb-27017.sock')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_records_unknown_unknown_metric_when_error_gathering_instance_data
|
83
|
+
@started_event.stubs(:address).returns(nil)
|
84
|
+
in_transaction { simulate_query }
|
85
|
+
assert_metrics_recorded('Datastore/instance/MongoDB/unknown/unknown')
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_records_tt_segment_parameters_for_datastore_instance
|
89
|
+
in_transaction { simulate_query }
|
90
|
+
|
91
|
+
tt = last_transaction_trace
|
92
|
+
|
93
|
+
node = find_node_with_name_matching tt, /^Datastore\//
|
94
|
+
|
95
|
+
assert_equal(NewRelic::Agent::Hostname.get, node[:host])
|
96
|
+
assert_equal('27017', node[:port_path_or_id])
|
97
|
+
assert_equal('mongodb-test', node[:database_name])
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_does_not_record_unknown_unknown_metric_when_data_empty
|
101
|
+
address = stub('address', :host => "", :port => "")
|
102
|
+
@started_event.stubs(:address).returns(address)
|
103
|
+
in_transaction { simulate_query }
|
104
|
+
assert_metrics_not_recorded('Datastore/instance/MongoDB/unknown/unknown')
|
105
|
+
end
|
106
|
+
|
107
|
+
def simulate_query
|
108
|
+
@subscriber.started(@started_event)
|
109
|
+
advance_time @succeeded_event.duration
|
110
|
+
@subscriber.succeeded(@succeeded_event)
|
113
111
|
end
|
114
112
|
end
|
@@ -13,33 +13,30 @@ class MinimalRackApp
|
|
13
13
|
def call(env)
|
14
14
|
@return_value
|
15
15
|
end
|
16
|
-
|
17
|
-
include NewRelic::Agent::Instrumentation::Rack
|
18
16
|
end
|
19
17
|
|
20
18
|
class NewRelic::Agent::Instrumentation::RackTest < Minitest::Test
|
19
|
+
|
20
|
+
def generate_minimal_rack_app mock_response
|
21
|
+
generator = NewRelic::Agent::Instrumentation::MiddlewareProxy.for_class(MinimalRackApp)
|
22
|
+
generator.new(mock_response)
|
23
|
+
end
|
24
|
+
|
21
25
|
def test_basic_rack_app
|
22
26
|
# should return what we send in, even when instrumented
|
23
|
-
x =
|
27
|
+
x = generate_minimal_rack_app([200, {}, ["whee"]])
|
24
28
|
assert_equal [200, {}, ["whee"]], x.call({})
|
25
|
-
assert_metrics_recorded(['Controller/Middleware/Rack/MinimalRackApp'])
|
29
|
+
assert_metrics_recorded(['Controller/Middleware/Rack/MinimalRackApp/call'])
|
26
30
|
end
|
27
31
|
|
28
32
|
def test_basic_rack_app_404
|
29
|
-
x =
|
30
|
-
assert_equal [404, {}, ["whee"]], x.call({})
|
31
|
-
assert_metrics_recorded(['Controller/Middleware/Rack/MinimalRackApp'])
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_basic_rack_app_ignores_404
|
35
|
-
NewRelic::Agent::Transaction.expects(:abort_transaction!)
|
36
|
-
x = MinimalRackApp.new([404, {}, ["whee"]])
|
33
|
+
x = generate_minimal_rack_app([404, {}, ["whee"]])
|
37
34
|
assert_equal [404, {}, ["whee"]], x.call({})
|
38
|
-
assert_metrics_recorded(['Controller/Middleware/Rack/MinimalRackApp'])
|
35
|
+
assert_metrics_recorded(['Controller/Middleware/Rack/MinimalRackApp/call'])
|
39
36
|
end
|
40
37
|
|
41
38
|
def test_does_not_double_instrument_middlewares
|
42
|
-
x =
|
39
|
+
x = generate_minimal_rack_app([200, {}, ["whee"]])
|
43
40
|
wrapped_x = NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(x)
|
44
41
|
|
45
42
|
assert_same(x, wrapped_x)
|
@@ -140,16 +140,6 @@ class NewRelic::Agent::Instrumentation::TaskInstrumentationTest < Minitest::Test
|
|
140
140
|
assert_equal(10, attributes_for(sample, :agent)['request.parameters.level'])
|
141
141
|
end
|
142
142
|
|
143
|
-
def test_abort_transaction
|
144
|
-
perform_action_with_newrelic_trace(:name => 'hello', :force => true) do
|
145
|
-
self.class.inspect
|
146
|
-
NewRelic::Agent.abort_transaction!
|
147
|
-
end
|
148
|
-
# We record the controller metric still, but abort any transaction recording.
|
149
|
-
assert_metrics_recorded(['Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/hello'])
|
150
|
-
assert_nil(@agent.transaction_sampler.last_sample)
|
151
|
-
end
|
152
|
-
|
153
143
|
def test_perform_action_with_newrelic_trace_saves_params
|
154
144
|
account = 'Redrocks'
|
155
145
|
with_config(:capture_params => true) do
|
@@ -144,7 +144,7 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
|
|
144
144
|
|
145
145
|
def test_browser_timing_header_safe_when_json_dump_fails
|
146
146
|
in_transaction do
|
147
|
-
|
147
|
+
::JSON.stubs(:dump).raises("Serialize? Hahahaha")
|
148
148
|
assert_equal "", instrumentor.browser_timing_header
|
149
149
|
end
|
150
150
|
end
|
@@ -323,7 +323,7 @@ class NewRelic::Agent::JavascriptInstrumentorTest < Minitest::Test
|
|
323
323
|
|
324
324
|
def unpack_to_object(text)
|
325
325
|
unpacked_atts = instrumentor.obfuscator.deobfuscate(text)
|
326
|
-
|
326
|
+
::JSON.load(unpacked_atts)
|
327
327
|
end
|
328
328
|
|
329
329
|
def formatted_for_matching(value)
|
@@ -64,16 +64,6 @@ module NewRelic
|
|
64
64
|
check_for_illegal_keys!(:rainbow_dash, test_keys)
|
65
65
|
end
|
66
66
|
|
67
|
-
def test_check_for_illegal_keys_deprecated
|
68
|
-
log = with_array_logger do
|
69
|
-
check_for_illegal_keys!(:rarity, :force => true)
|
70
|
-
end.array
|
71
|
-
|
72
|
-
assert_equal(1, log.size)
|
73
|
-
|
74
|
-
assert_match(/Deprecated options when adding method tracer to rarity: force/, log[0])
|
75
|
-
end
|
76
|
-
|
77
67
|
def test_traced_method_exists_positive
|
78
68
|
self.expects(:_traced_method_name)
|
79
69
|
self.expects(:method_defined?).returns(true)
|
@@ -120,9 +120,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
|
124
|
-
check_time 0.05, stats.total_call_time
|
125
|
-
assert_equal 1, stats.call_count
|
123
|
+
assert_metrics_recorded metric => {:call_count => 1, :total_call_time => 0.05}
|
126
124
|
end
|
127
125
|
|
128
126
|
def test_trace_execution_scoped_with_no_metrics_skips_out
|
@@ -142,20 +140,6 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
142
140
|
end
|
143
141
|
end
|
144
142
|
|
145
|
-
def test_basic__original_api
|
146
|
-
metric = "hello"
|
147
|
-
in_transaction do |txn|
|
148
|
-
self.class.trace_method_execution(metric, true, true, true) do
|
149
|
-
advance_time(0.05)
|
150
|
-
end
|
151
|
-
assert_equal metric, @scope_listener.scopes.last
|
152
|
-
end
|
153
|
-
|
154
|
-
stats = @stats_engine.get_stats(metric)
|
155
|
-
check_time 0.05, stats.total_call_time
|
156
|
-
assert_equal 1, stats.call_count
|
157
|
-
end
|
158
|
-
|
159
143
|
METRIC = "metric"
|
160
144
|
def test_add_method_tracer
|
161
145
|
@metric_name = METRIC
|
@@ -172,10 +156,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
172
156
|
# ignore 'no tracer' errors from remove method tracer
|
173
157
|
end
|
174
158
|
|
175
|
-
|
176
|
-
stats = @stats_engine.get_stats(METRIC)
|
177
|
-
check_time 0.05, stats.total_call_time
|
178
|
-
assert_equal 1, stats.call_count
|
159
|
+
assert_metrics_recorded METRIC => {:call_count => 1, :total_call_time => 0.05}
|
179
160
|
end
|
180
161
|
|
181
162
|
def test_add_method_tracer__default
|
@@ -185,16 +166,17 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
185
166
|
simple_method
|
186
167
|
end
|
187
168
|
|
188
|
-
|
189
|
-
|
169
|
+
metric = "Custom/#{self.class.name}/simple_method"
|
170
|
+
assert_metrics_recorded metric => {:call_count => 1}
|
190
171
|
end
|
191
172
|
|
192
173
|
def test_add_class_method_tracer
|
193
174
|
in_transaction do
|
194
175
|
MyClass.class_method
|
195
176
|
end
|
196
|
-
|
197
|
-
|
177
|
+
|
178
|
+
metric = "Custom/MyClass/Class/class_method"
|
179
|
+
assert_metrics_recorded metric => {:call_count => 1}
|
198
180
|
end
|
199
181
|
|
200
182
|
def test_add_anonymous_class_method_tracer
|
@@ -208,8 +190,8 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
208
190
|
cls.new.instance_method
|
209
191
|
end
|
210
192
|
|
211
|
-
|
212
|
-
|
193
|
+
metric = "Custom/AnonymousClass/instance_method"
|
194
|
+
assert_metrics_recorded metric => {:call_count => 1}
|
213
195
|
end
|
214
196
|
|
215
197
|
def test_add_method_tracer__reentry
|
@@ -221,8 +203,8 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
221
203
|
simple_method
|
222
204
|
end
|
223
205
|
|
224
|
-
|
225
|
-
|
206
|
+
metric = "Custom/#{self.class.name}/simple_method"
|
207
|
+
assert_metrics_recorded metric => {:call_count => 1}
|
226
208
|
end
|
227
209
|
|
228
210
|
def test_method_traced?
|
@@ -266,10 +248,11 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
266
248
|
mock.catcher(5)
|
267
249
|
end
|
268
250
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
251
|
+
assert_metrics_recorded({
|
252
|
+
"catcher" => {:call_count => 2},
|
253
|
+
"thrower" => {:call_count => 6}
|
254
|
+
})
|
255
|
+
|
273
256
|
sample = @old_sampler.harvest!
|
274
257
|
refute_nil sample
|
275
258
|
end
|
@@ -292,9 +275,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
292
275
|
# ignore 'no tracer' errors from remove method tracer
|
293
276
|
end
|
294
277
|
|
295
|
-
|
296
|
-
check_time 0.05, stats.total_call_time
|
297
|
-
assert_equal 1, stats.call_count
|
278
|
+
assert_metrics_recorded METRIC => {:call_count => 1, :total_call_time => 0.05}
|
298
279
|
end
|
299
280
|
|
300
281
|
def test_add_tracer_with_dynamic_metric
|
@@ -314,9 +295,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
314
295
|
# ignore 'no tracer' errors from remove method tracer
|
315
296
|
end
|
316
297
|
|
317
|
-
|
318
|
-
check_time 0.05, stats.total_call_time
|
319
|
-
assert_equal 1, stats.call_count
|
298
|
+
assert_metrics_recorded expected_metric => {:call_count => 1, :total_call_time => 0.05}
|
320
299
|
end
|
321
300
|
|
322
301
|
def test_trace_method_with_block
|
@@ -329,9 +308,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
329
308
|
assert_equal METRIC, @scope_listener.scopes.last
|
330
309
|
end
|
331
310
|
|
332
|
-
|
333
|
-
check_time 0.15, stats.total_call_time
|
334
|
-
assert_equal 1, stats.call_count
|
311
|
+
assert_metrics_recorded METRIC => {:call_count => 1, :total_call_time => 0.15}
|
335
312
|
end
|
336
313
|
|
337
314
|
def test_trace_module_method
|
@@ -346,8 +323,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
346
323
|
|
347
324
|
method_to_be_traced 1,2,3,false,METRIC
|
348
325
|
|
349
|
-
|
350
|
-
assert stats.call_count == 0
|
326
|
+
assert_metrics_not_recorded METRIC
|
351
327
|
end
|
352
328
|
|
353
329
|
def self.static_method(x, testcase, is_traced)
|
@@ -371,11 +347,13 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
371
347
|
advance_time 0.05
|
372
348
|
end
|
373
349
|
end
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
350
|
+
|
351
|
+
|
352
|
+
assert_metrics_recorded({
|
353
|
+
'first' => {:call_count => 1, :total_call_time => 0.05},
|
354
|
+
'second' => {:call_count => 1, :total_call_time => 0.05},
|
355
|
+
'third' => {:call_count => 1, :total_call_time => 0.05}
|
356
|
+
})
|
379
357
|
end
|
380
358
|
|
381
359
|
def test_multiple_metrics__unscoped
|
@@ -383,11 +361,12 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
383
361
|
self.class.trace_execution_unscoped metrics do
|
384
362
|
advance_time 0.05
|
385
363
|
end
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
364
|
+
|
365
|
+
assert_metrics_recorded({
|
366
|
+
'first' => {:call_count => 1, :total_call_time => 0.05},
|
367
|
+
'second' => {:call_count => 1, :total_call_time => 0.05},
|
368
|
+
'third' => {:call_count => 1, :total_call_time => 0.05}
|
369
|
+
})
|
391
370
|
assert @scope_listener.scopes.empty?
|
392
371
|
end
|
393
372
|
|
@@ -406,8 +385,7 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
406
385
|
rescue StandardError
|
407
386
|
end
|
408
387
|
|
409
|
-
|
410
|
-
assert_equal 1, stats.call_count
|
388
|
+
assert_metrics_recorded metric => {:call_count => 1}
|
411
389
|
end
|
412
390
|
|
413
391
|
def test_add_multiple_tracers
|
@@ -450,31 +428,12 @@ class NewRelic::Agent::MethodTracerTest < Minitest::Test
|
|
450
428
|
|
451
429
|
public_api_methods = [
|
452
430
|
'trace_execution_unscoped',
|
453
|
-
'trace_execution_scoped'
|
454
|
-
'trace_method_execution', # deprecated
|
455
|
-
'trace_method_execution_with_scope', # deprecated
|
456
|
-
'trace_method_execution_no_scope', # deprecated
|
457
|
-
'get_stats_scoped', # deprecated
|
458
|
-
'get_stats_unscoped' # deprecated
|
431
|
+
'trace_execution_scoped'
|
459
432
|
]
|
460
433
|
|
461
434
|
assert_equal(public_api_methods.sort, added_methods.map(&:to_s).sort)
|
462
435
|
end
|
463
436
|
|
464
|
-
def test_get_stats_unscoped
|
465
|
-
host_class = Class.new { include ::NewRelic::Agent::MethodTracer }
|
466
|
-
expected_stats = NewRelic::Agent.get_stats('foobar')
|
467
|
-
stats = host_class.new.get_stats_unscoped('foobar')
|
468
|
-
assert_same(expected_stats, stats)
|
469
|
-
end
|
470
|
-
|
471
|
-
def test_get_stats_scoped
|
472
|
-
host_class = Class.new { include ::NewRelic::Agent::MethodTracer }
|
473
|
-
expected_stats = NewRelic::Agent.get_stats('foobar', true)
|
474
|
-
stats = host_class.new.get_stats_scoped('foobar', false)
|
475
|
-
assert_same(expected_stats, stats)
|
476
|
-
end
|
477
|
-
|
478
437
|
def trace_no_push_scope
|
479
438
|
self.class.add_method_tracer :method_to_be_traced, 'X', :push_scope => false
|
480
439
|
method_to_be_traced 1,2,3,true,nil
|