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
@@ -52,9 +52,25 @@ module NewRelic::Agent
|
|
52
52
|
if expected_vendors_hash.nil?
|
53
53
|
refute aws_info.loaded?
|
54
54
|
else
|
55
|
-
actual =
|
55
|
+
actual = stringify_keys_in_object(aws_info.to_collector_hash)
|
56
56
|
assert_equal expected_vendors_hash["aws"], actual
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
# recurses through hashes and arrays and stringifies keys
|
61
|
+
def stringify_keys_in_object(object)
|
62
|
+
case object
|
63
|
+
when Hash
|
64
|
+
object.inject({}) do |memo, (k, v)|
|
65
|
+
memo[k.to_s] = stringify_keys_in_object(v)
|
66
|
+
memo
|
67
|
+
end
|
68
|
+
when Array
|
69
|
+
object.map {|o| stringify_keys_in_object(o)}
|
70
|
+
else
|
71
|
+
object
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
59
75
|
end
|
60
76
|
end
|
@@ -3,13 +3,14 @@
|
|
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__),'..','..','test_helper'))
|
6
|
+
|
6
7
|
class NewRelic::Agent::BusyCalculatorTest < Minitest::Test
|
7
8
|
attr_reader :now
|
9
|
+
|
8
10
|
def setup
|
9
11
|
@now = Time.now.to_f
|
10
12
|
NewRelic::Agent::BusyCalculator.reset
|
11
13
|
NewRelic::Agent.agent.stats_engine.clear_stats
|
12
|
-
@instance_busy = NewRelic::Agent.agent.stats_engine.get_stats_no_scope('Instance/Busy')
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_normal
|
@@ -21,9 +22,9 @@ class NewRelic::Agent::BusyCalculatorTest < Minitest::Test
|
|
21
22
|
assert_equal 5, NewRelic::Agent::BusyCalculator.accumulator
|
22
23
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
23
24
|
|
24
|
-
|
25
|
-
assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
|
25
|
+
assert_metrics_recorded 'Instance/Busy' => {:call_count => 1, :total_call_time => 0.50}
|
26
26
|
end
|
27
|
+
|
27
28
|
def test_split
|
28
29
|
# start the timewindow 10 seconds ago
|
29
30
|
# start a request at 5 seconds, don't finish
|
@@ -31,9 +32,9 @@ class NewRelic::Agent::BusyCalculatorTest < Minitest::Test
|
|
31
32
|
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 5.0)
|
32
33
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
33
34
|
|
34
|
-
|
35
|
-
assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
|
35
|
+
assert_metrics_recorded 'Instance/Busy' => {:call_count => 1, :total_call_time => 0.50}
|
36
36
|
end
|
37
|
+
|
37
38
|
def test_reentrancy
|
38
39
|
# start the timewindow 10 seconds ago
|
39
40
|
# start a request at 5 seconds, don't finish, but make two more
|
@@ -48,9 +49,9 @@ class NewRelic::Agent::BusyCalculatorTest < Minitest::Test
|
|
48
49
|
NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 1.0)
|
49
50
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
50
51
|
|
51
|
-
|
52
|
-
assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
|
52
|
+
assert_metrics_recorded 'Instance/Busy' => {:call_count => 1, :total_call_time => 0.50}
|
53
53
|
end
|
54
|
+
|
54
55
|
def test_concurrency
|
55
56
|
# start the timewindow 10 seconds ago
|
56
57
|
# start a request at 10 seconds, 5 seconds long
|
@@ -70,23 +71,21 @@ class NewRelic::Agent::BusyCalculatorTest < Minitest::Test
|
|
70
71
|
NewRelic::Agent::BusyCalculator.stubs(:time_now).returns(now - 1.0)
|
71
72
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
72
73
|
|
73
|
-
|
74
|
-
# 3 + 6 = 9, or 90%
|
75
|
-
assert_in_delta 0.90, @instance_busy.total_call_time, 0.1
|
76
|
-
|
74
|
+
assert_metrics_recorded 'Instance/Busy' => {:call_count => 1, :total_call_time => 1.0}
|
77
75
|
end
|
76
|
+
|
78
77
|
def test_dont_ignore_zero_counts
|
79
|
-
assert_equal 0, @instance_busy.call_count, "Problem with test--instance busy not starting off at zero."
|
80
78
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
81
79
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
82
80
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
83
|
-
|
81
|
+
|
82
|
+
assert_metrics_recorded 'Instance/Busy' => {:call_count => 3}
|
84
83
|
end
|
84
|
+
|
85
85
|
def test_can_turn_off_recording
|
86
86
|
with_config(:report_instance_busy => false) do
|
87
|
-
assert_equal 0, @instance_busy.call_count, "Problem with test--instance busy not starting off at zero."
|
88
87
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
89
|
-
|
88
|
+
assert_metrics_not_recorded 'Instance/Busy'
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
@@ -94,5 +93,4 @@ class NewRelic::Agent::BusyCalculatorTest < Minitest::Test
|
|
94
93
|
NewRelic::Agent::TransactionState.tl_clear_for_testing
|
95
94
|
NewRelic::Agent::BusyCalculator.dispatcher_finish
|
96
95
|
end
|
97
|
-
|
98
96
|
end
|
@@ -300,7 +300,7 @@ module NewRelic::Agent::Configuration
|
|
300
300
|
assert_equal(testcase["expected"].sort_by { |h| h["label_type"] },
|
301
301
|
@manager.parse_labels_from_string.sort_by { |h| h["label_type"] },
|
302
302
|
"failed on #{testcase["name"]}")
|
303
|
-
end
|
303
|
+
end
|
304
304
|
end
|
305
305
|
|
306
306
|
def test_parse_labels_from_dictionary_with_hard_failure
|
@@ -441,12 +441,6 @@ module NewRelic::Agent::Configuration
|
|
441
441
|
|
442
442
|
def assert_parsed_labels(expected)
|
443
443
|
result = @manager.parsed_labels
|
444
|
-
|
445
|
-
# 1.8.7 hash ordering means we can't directly compare. Lean on the
|
446
|
-
# structure and flattened array sorting to do the comparison we need.
|
447
|
-
result = result.map(&:to_a).sort
|
448
|
-
expected = expected.map(&:to_a).sort
|
449
|
-
|
450
444
|
assert_equal expected, result
|
451
445
|
end
|
452
446
|
|
@@ -447,11 +447,11 @@ class NewRelic::Agent::DatabaseTest < Minitest::Test
|
|
447
447
|
|
448
448
|
def test_capture_query_mis_encoded
|
449
449
|
query = INVALID_UTF8_STRING
|
450
|
-
original_encoding =
|
450
|
+
original_encoding = query.encoding
|
451
451
|
expected_query = INVALID_UTF8_STRING.dup
|
452
452
|
expected_query.force_encoding('ASCII-8BIT') if expected_query.respond_to?(:force_encoding)
|
453
453
|
captured = NewRelic::Agent::Database.capture_query(query)
|
454
|
-
assert_equal(original_encoding,
|
454
|
+
assert_equal(original_encoding, query.encoding) # input query encoding should remain untouched
|
455
455
|
assert_equal(expected_query, captured)
|
456
456
|
end
|
457
457
|
|
@@ -479,12 +479,4 @@ class NewRelic::Agent::DatabaseTest < Minitest::Test
|
|
479
479
|
assert_equal expected_sql, sql
|
480
480
|
end
|
481
481
|
|
482
|
-
# Ruby 1.8 doesn't have String#encoding
|
483
|
-
def encoding_from_string(str)
|
484
|
-
if str.respond_to?(:encoding)
|
485
|
-
str.encoding
|
486
|
-
else
|
487
|
-
nil
|
488
|
-
end
|
489
|
-
end
|
490
482
|
end
|
@@ -64,112 +64,109 @@ module NewRelic
|
|
64
64
|
]
|
65
65
|
}
|
66
66
|
|
67
|
-
|
67
|
+
def test_doesnt_modify_incoming_statement
|
68
|
+
formatted = EventFormatter.format('find', DATABASE, FIND_COMMAND)
|
69
|
+
refute_same FIND_COMMAND, formatted
|
70
|
+
end
|
68
71
|
|
69
|
-
|
72
|
+
def test_can_disable_statement_capturing_queries
|
73
|
+
with_config(:'mongo.capture_queries' => false) do
|
70
74
|
formatted = EventFormatter.format('find', DATABASE, FIND_COMMAND)
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_can_disable_statement_capturing_queries
|
75
|
-
with_config(:'mongo.capture_queries' => false) do
|
76
|
-
formatted = EventFormatter.format('find', DATABASE, FIND_COMMAND)
|
77
|
-
assert_nil formatted
|
78
|
-
end
|
75
|
+
assert_nil formatted
|
79
76
|
end
|
77
|
+
end
|
80
78
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
79
|
+
def test_event_formatter_obfuscates_by_default
|
80
|
+
expected = {
|
81
|
+
:operation => :find,
|
82
|
+
:database => DATABASE,
|
83
|
+
:collection => "tribbles",
|
84
|
+
"find" => "tribbles",
|
85
|
+
"filter" => { "_id" => { "$gt" => "?" }, "name" => "?" },
|
86
|
+
"sort" => { "_id" => 1 },
|
87
|
+
"limit" => 2,
|
88
|
+
"skip" => 2,
|
89
|
+
"comment" => "test",
|
90
|
+
"hint" => { "_id" => 1 },
|
91
|
+
"max" => { "_id" => 6 },
|
92
|
+
"maxScan" => 5000,
|
93
|
+
"maxTimeMS" => 6000,
|
94
|
+
"min" => { "_id" => 0 },
|
95
|
+
"readPreference" => { "mode" => "secondaryPreferred" },
|
96
|
+
"returnKey" => false,
|
97
|
+
"showRecordId" => false,
|
98
|
+
"snapshot" => false
|
99
|
+
}
|
100
|
+
|
101
|
+
formatted = EventFormatter.format(:find, DATABASE, FIND_COMMAND)
|
102
|
+
assert_equal expected, formatted
|
103
|
+
end
|
102
104
|
|
105
|
+
def test_event_formatter_raw_selectors
|
106
|
+
with_config(:'mongo.obfuscate_queries' => false) do
|
103
107
|
formatted = EventFormatter.format(:find, DATABASE, FIND_COMMAND)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
def test_event_formatter_raw_selectors
|
108
|
-
with_config(:'mongo.obfuscate_queries' => false) do
|
109
|
-
formatted = EventFormatter.format(:find, DATABASE, FIND_COMMAND)
|
110
|
-
expected = FIND_COMMAND.merge(
|
111
|
-
:operation => :find,
|
112
|
-
:database => DATABASE,
|
113
|
-
:collection => 'tribbles'
|
114
|
-
)
|
115
|
-
assert_equal expected, formatted
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_event_formatter_blacklists_inserts
|
120
|
-
expected = {
|
121
|
-
:operation => :insert,
|
122
|
-
:database => DATABASE,
|
123
|
-
:collection => "tribbles",
|
124
|
-
"insert" => "tribbles",
|
125
|
-
"ordered" => true
|
126
|
-
}
|
127
|
-
|
128
|
-
formatted = EventFormatter.format(:insert, DATABASE, INSERT_COMMAND)
|
129
|
-
assert_equal expected, formatted
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_event_formatter_blacklists_updates
|
133
|
-
expected = {
|
134
|
-
:operation => :update,
|
108
|
+
expected = FIND_COMMAND.merge(
|
109
|
+
:operation => :find,
|
135
110
|
:database => DATABASE,
|
136
|
-
:collection =>
|
137
|
-
|
138
|
-
"ordered" => true
|
139
|
-
}
|
140
|
-
|
141
|
-
formatted = EventFormatter.format(:update, DATABASE, UPDATE_COMMAND)
|
111
|
+
:collection => 'tribbles'
|
112
|
+
)
|
142
113
|
assert_equal expected, formatted
|
143
114
|
end
|
115
|
+
end
|
144
116
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
117
|
+
def test_event_formatter_blacklists_inserts
|
118
|
+
expected = {
|
119
|
+
:operation => :insert,
|
120
|
+
:database => DATABASE,
|
121
|
+
:collection => "tribbles",
|
122
|
+
"insert" => "tribbles",
|
123
|
+
"ordered" => true
|
124
|
+
}
|
125
|
+
|
126
|
+
formatted = EventFormatter.format(:insert, DATABASE, INSERT_COMMAND)
|
127
|
+
assert_equal expected, formatted
|
128
|
+
end
|
153
129
|
|
154
|
-
|
155
|
-
|
156
|
-
|
130
|
+
def test_event_formatter_blacklists_updates
|
131
|
+
expected = {
|
132
|
+
:operation => :update,
|
133
|
+
:database => DATABASE,
|
134
|
+
:collection => "tribbles",
|
135
|
+
"update" => "tribbles",
|
136
|
+
"ordered" => true
|
137
|
+
}
|
138
|
+
|
139
|
+
formatted = EventFormatter.format(:update, DATABASE, UPDATE_COMMAND)
|
140
|
+
assert_equal expected, formatted
|
141
|
+
end
|
157
142
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
143
|
+
def test_event_formatter_obfuscates_pipeline
|
144
|
+
expected = {
|
145
|
+
:operation => :aggregate,
|
146
|
+
:database => DATABASE,
|
147
|
+
:collection => "tribbles",
|
148
|
+
"aggregate" => "tribbles",
|
149
|
+
"pipeline" => [
|
150
|
+
{"$group" => {"_id" => "?", "max" => {"$max" => "?"}}},
|
151
|
+
{"$match" => {"max" => {"$gte" => "?"}}}
|
152
|
+
]
|
153
|
+
}
|
154
|
+
|
155
|
+
formatted = EventFormatter.format(:aggregate, DATABASE, AGGREGATE_COMMAND)
|
156
|
+
assert_equal expected, formatted
|
157
|
+
end
|
169
158
|
|
170
|
-
|
171
|
-
|
172
|
-
|
159
|
+
def test_event_formatter_blacklists_deletes
|
160
|
+
expected = {
|
161
|
+
:operation => :delete,
|
162
|
+
:database => DATABASE,
|
163
|
+
:collection => "tribbles",
|
164
|
+
"delete" => "tribbles",
|
165
|
+
"ordered" => true
|
166
|
+
}
|
167
|
+
|
168
|
+
formatted = EventFormatter.format(:delete, DATABASE, DELETE_COMMAND)
|
169
|
+
assert_equal expected, formatted
|
173
170
|
end
|
174
171
|
end
|
175
172
|
end
|
@@ -104,25 +104,23 @@ class NewRelic::Agent::Datastores::RedisTest < Minitest::Test
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
assert_equal expected, result
|
115
|
-
end
|
107
|
+
def test_format_command_handles_binary_strings
|
108
|
+
binary_string = (0..255).to_a.pack("c*")
|
109
|
+
expected = 'set "key" <binary data>'
|
110
|
+
|
111
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
112
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, 'key', binary_string])
|
113
|
+
assert_equal expected, result
|
116
114
|
end
|
115
|
+
end
|
117
116
|
|
118
|
-
|
119
|
-
|
120
|
-
|
117
|
+
def test_format_command_in_pipeline_handles_binary_strings
|
118
|
+
binary_string = (0..255).to_a.pack("c*")
|
119
|
+
expected = 'set "key" <binary data>'
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
121
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
122
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, 'key', binary_string])
|
123
|
+
assert_equal expected, result
|
126
124
|
end
|
127
125
|
end
|
128
126
|
end
|
@@ -23,49 +23,47 @@ class EncodingNormalizerTest < Minitest::Test
|
|
23
23
|
assert_equal({'key' => 1.5}, result)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
26
|
+
def test_normalize_string_returns_input_if_correctly_encoded_utf8
|
27
|
+
string = "i want a pony"
|
28
|
+
result = EncodingNormalizer.normalize_string(string)
|
29
|
+
assert_same(string, result)
|
30
|
+
assert_equal(Encoding.find('UTF-8'), result.encoding)
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
def test_normalize_string_returns_munged_copy_if_ascii_8bit
|
34
|
+
string = (0..255).to_a.pack("C*")
|
35
|
+
result = EncodingNormalizer.normalize_string(string)
|
36
|
+
refute_same(string, result)
|
37
|
+
assert_equal(Encoding.find('ISO-8859-1'), result.encoding)
|
38
|
+
assert_equal(string, result.dup.force_encoding('ASCII-8BIT'))
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
def test_normalize_string_returns_munged_copy_if_invalid_utf8
|
42
|
+
string = (0..255).to_a.pack("C*").force_encoding('UTF-8')
|
43
|
+
result = EncodingNormalizer.normalize_string(string)
|
44
|
+
refute_same(result, string)
|
45
|
+
assert_equal(Encoding.find('ISO-8859-1'), result.encoding)
|
46
|
+
assert_equal(string, result.dup.force_encoding('UTF-8'))
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
def test_normalize_string_returns_munged_copy_if_other_convertible_encoding
|
50
|
+
string = "i want a pony".encode('UTF-16LE')
|
51
|
+
result = EncodingNormalizer.normalize_string(string)
|
52
|
+
refute_same(result, string)
|
53
|
+
assert_equal(Encoding.find('UTF-8'), result.encoding)
|
54
|
+
assert_equal(string, result.encode('UTF-16LE'))
|
55
|
+
end
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
57
|
+
def test_normalize_string_returns_munged_copy_if_other_non_convertible_enocding
|
58
|
+
# Attempting to convert from UTF-7 to UTF-8 in Ruby will raise an
|
59
|
+
# Encoding::ConverterNotFoundError, which is what we're trying to
|
60
|
+
# replicate for this test case.
|
61
|
+
# The following UTF-7 string decodes to 'Jyväskylä', a city in Finland
|
62
|
+
string = "Jyv+AOQ-skyl+AOQ-".force_encoding("UTF-7")
|
63
|
+
assert string.valid_encoding?
|
64
|
+
result = EncodingNormalizer.normalize_string(string)
|
65
|
+
refute_same(result, string)
|
66
|
+
assert_equal(Encoding.find('ISO-8859-1'), result.encoding)
|
67
|
+
assert_equal('Jyv+AOQ-skyl+AOQ-'.force_encoding('ISO-8859-1'), result)
|
70
68
|
end
|
71
69
|
end
|