newrelic_rpm 6.7.0.359 → 6.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/CHANGELOG.md +493 -4
- data/CONTRIBUTING.md +106 -19
- data/Gemfile +6 -2
- data/Guardfile +18 -1
- data/LICENSE +208 -38
- data/README.md +81 -85
- data/ROADMAP.md +24 -0
- data/Rakefile +2 -0
- data/THIRD_PARTY_NOTICES.md +213 -0
- data/bin/nrdebug +1 -1
- data/init.rb +1 -1
- data/install.rb +1 -1
- data/lib/new_relic/agent/adaptive_sampler.rb +1 -1
- data/lib/new_relic/agent/agent.rb +63 -44
- data/lib/new_relic/agent/agent_logger.rb +5 -1
- data/lib/new_relic/agent/attribute_filter.rb +8 -8
- data/lib/new_relic/agent/attribute_processing.rb +1 -1
- data/lib/new_relic/agent/attributes.rb +152 -0
- data/lib/new_relic/agent/audit_logger.rb +11 -1
- data/lib/new_relic/agent/autostart.rb +20 -15
- data/lib/new_relic/agent/chained_call.rb +1 -1
- data/lib/new_relic/agent/commands/agent_command.rb +1 -1
- data/lib/new_relic/agent/commands/agent_command_router.rb +1 -1
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -1
- data/lib/new_relic/agent/configuration/default_source.rb +138 -17
- data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -1
- data/lib/new_relic/agent/configuration/environment_source.rb +1 -1
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +1 -1
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
- data/lib/new_relic/agent/configuration/manager.rb +1 -1
- data/lib/new_relic/agent/configuration/manual_source.rb +1 -1
- data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -1
- data/lib/new_relic/agent/configuration/security_policy_source.rb +1 -1
- data/lib/new_relic/agent/configuration/server_source.rb +2 -2
- data/lib/new_relic/agent/configuration/yaml_source.rb +12 -7
- data/lib/new_relic/agent/configuration.rb +1 -1
- data/lib/new_relic/agent/connect/request_builder.rb +4 -12
- data/lib/new_relic/agent/connect/response_handler.rb +1 -1
- data/lib/new_relic/agent/custom_event_aggregator.rb +1 -1
- data/lib/new_relic/agent/database/explain_plan_helpers.rb +1 -1
- data/lib/new_relic/agent/database/obfuscation_helpers.rb +2 -2
- data/lib/new_relic/agent/database/obfuscator.rb +1 -1
- data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +1 -1
- data/lib/new_relic/agent/database.rb +2 -3
- data/lib/new_relic/agent/database_adapter.rb +33 -0
- data/lib/new_relic/agent/datastores/metric_helper.rb +1 -1
- data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +3 -3
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +9 -9
- data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +1 -1
- data/lib/new_relic/agent/datastores/mongo.rb +2 -2
- data/lib/new_relic/agent/datastores/redis.rb +1 -1
- data/lib/new_relic/agent/datastores.rb +1 -1
- data/lib/new_relic/agent/deprecator.rb +1 -1
- data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +3 -2
- data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +61 -46
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +84 -0
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
- data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +25 -102
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
- data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
- data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
- data/lib/new_relic/agent/distributed_tracing.rb +156 -7
- data/lib/new_relic/agent/encoding_normalizer.rb +1 -1
- data/lib/new_relic/agent/error_collector.rb +34 -17
- data/lib/new_relic/agent/error_event_aggregator.rb +8 -6
- data/lib/new_relic/agent/error_trace_aggregator.rb +1 -1
- data/lib/new_relic/agent/event_aggregator.rb +1 -1
- data/lib/new_relic/agent/event_buffer.rb +1 -1
- data/lib/new_relic/agent/event_listener.rb +1 -1
- data/lib/new_relic/agent/event_loop.rb +1 -1
- data/lib/new_relic/agent/external.rb +8 -8
- data/lib/new_relic/agent/guid_generator.rb +28 -0
- data/lib/new_relic/agent/harvester.rb +1 -1
- data/lib/new_relic/agent/heap.rb +1 -1
- data/lib/new_relic/agent/hostname.rb +8 -2
- data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +25 -20
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +29 -14
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +18 -22
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +11 -12
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +17 -5
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +5 -7
- data/lib/new_relic/agent/http_clients/uri_util.rb +12 -11
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +6 -8
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -1
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +12 -4
- data/lib/new_relic/agent/instrumentation/active_job.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +85 -38
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +17 -6
- data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +35 -11
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +8 -3
- data/lib/new_relic/agent/instrumentation/active_storage.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +9 -5
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +10 -9
- data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
- data/lib/new_relic/agent/instrumentation/bunny.rb +48 -29
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/curb.rb +66 -19
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +3 -1
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +7 -4
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -2
- data/lib/new_relic/agent/instrumentation/excon.rb +2 -2
- data/lib/new_relic/agent/instrumentation/grape.rb +6 -11
- data/lib/new_relic/agent/instrumentation/http.rb +7 -4
- data/lib/new_relic/agent/instrumentation/httpclient.rb +6 -4
- data/lib/new_relic/agent/instrumentation/ignore_actions.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +7 -3
- data/lib/new_relic/agent/instrumentation/memcache.rb +4 -2
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +1 -1
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +9 -7
- data/lib/new_relic/agent/instrumentation/mongo.rb +10 -4
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +36 -3
- data/lib/new_relic/agent/instrumentation/net.rb +48 -28
- data/lib/new_relic/agent/instrumentation/net_prepend.rb +40 -0
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +26 -2
- data/lib/new_relic/agent/instrumentation/padrino.rb +3 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rack.rb +3 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails_middleware.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rake.rb +2 -1
- data/lib/new_relic/agent/instrumentation/redis.rb +12 -6
- data/lib/new_relic/agent/instrumentation/resque.rb +4 -1
- data/lib/new_relic/agent/instrumentation/sequel.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sequel_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +48 -24
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -2
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +24 -7
- data/lib/new_relic/agent/instrumentation.rb +1 -1
- data/lib/new_relic/agent/internal_agent_error.rb +1 -1
- data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
- data/lib/new_relic/agent/log_once.rb +1 -1
- data/lib/new_relic/agent/logging.rb +19 -5
- data/lib/new_relic/agent/memory_logger.rb +1 -1
- data/lib/new_relic/agent/messaging.rb +6 -74
- data/lib/new_relic/agent/method_tracer.rb +10 -8
- data/lib/new_relic/agent/method_tracer_helpers.rb +3 -3
- data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
- data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
- data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +2 -2
- data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +3 -5
- data/lib/new_relic/agent/monitors.rb +27 -0
- data/lib/new_relic/agent/new_relic_service/encoders.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/marshaller.rb +1 -1
- data/lib/new_relic/agent/new_relic_service/security_policy_settings.rb +1 -1
- data/lib/new_relic/agent/new_relic_service.rb +34 -10
- data/lib/new_relic/agent/noticible_error.rb +22 -0
- data/lib/new_relic/agent/null_logger.rb +1 -1
- data/lib/new_relic/agent/obfuscator.rb +1 -1
- data/lib/new_relic/agent/parameter_filtering.rb +1 -1
- data/lib/new_relic/agent/payload_metric_mapping.rb +1 -1
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
- data/lib/new_relic/agent/pipe_service.rb +1 -1
- data/lib/new_relic/agent/prepend_supportability.rb +1 -1
- data/lib/new_relic/agent/priority_sampled_buffer.rb +8 -5
- data/lib/new_relic/agent/range_extensions.rb +1 -1
- data/lib/new_relic/agent/rules_engine/replacement_rule.rb +1 -1
- data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -1
- data/lib/new_relic/agent/rules_engine.rb +1 -1
- data/lib/new_relic/agent/sampler.rb +1 -1
- data/lib/new_relic/agent/sampler_collection.rb +1 -1
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/memory_sampler.rb +2 -2
- data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/vm_sampler.rb +1 -1
- data/lib/new_relic/agent/span_event_aggregator.rb +2 -1
- data/lib/new_relic/agent/span_event_primitive.rb +108 -54
- data/lib/new_relic/agent/sql_sampler.rb +6 -6
- data/lib/new_relic/agent/stats.rb +1 -1
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +2 -2
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
- data/lib/new_relic/agent/stats_engine.rb +1 -1
- data/lib/new_relic/agent/supported_versions.rb +3 -3
- data/lib/new_relic/agent/synthetics_event_aggregator.rb +1 -1
- data/lib/new_relic/agent/system_info.rb +13 -4
- data/lib/new_relic/agent/threading/agent_thread.rb +1 -1
- data/lib/new_relic/agent/threading/backtrace_node.rb +1 -1
- data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
- data/lib/new_relic/agent/threading/thread_profile.rb +1 -1
- data/lib/new_relic/agent/timestamp_sampled_buffer.rb +1 -1
- data/lib/new_relic/agent/tracer.rb +34 -19
- data/lib/new_relic/agent/transaction/abstract_segment.rb +32 -5
- data/lib/new_relic/agent/transaction/datastore_segment.rb +1 -1
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +177 -0
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +58 -147
- data/lib/new_relic/agent/transaction/external_request_segment.rb +32 -39
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +5 -12
- data/lib/new_relic/agent/transaction/request_attributes.rb +1 -1
- data/lib/new_relic/agent/transaction/segment.rb +28 -2
- data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction/trace.rb +3 -5
- data/lib/new_relic/agent/transaction/trace_builder.rb +1 -1
- data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
- data/lib/new_relic/agent/transaction/trace_node.rb +11 -9
- data/lib/new_relic/agent/transaction/tracing.rb +1 -1
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +1 -1
- data/lib/new_relic/agent/transaction.rb +104 -82
- data/lib/new_relic/agent/transaction_error_primitive.rb +11 -16
- data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -1
- data/lib/new_relic/agent/transaction_event_primitive.rb +29 -40
- data/lib/new_relic/agent/transaction_event_recorder.rb +1 -1
- data/lib/new_relic/agent/transaction_metrics.rb +1 -1
- data/lib/new_relic/agent/transaction_sampler.rb +1 -1
- data/lib/new_relic/agent/transaction_time_aggregator.rb +1 -1
- data/lib/new_relic/agent/utilization/aws.rb +1 -1
- data/lib/new_relic/agent/utilization/azure.rb +1 -1
- data/lib/new_relic/agent/utilization/gcp.rb +1 -1
- data/lib/new_relic/agent/utilization/pcf.rb +1 -1
- data/lib/new_relic/agent/utilization/vendor.rb +1 -1
- data/lib/new_relic/agent/utilization_data.rb +1 -1
- data/lib/new_relic/agent/vm/jruby_vm.rb +1 -1
- data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +1 -1
- data/lib/new_relic/agent/vm/mri_vm.rb +7 -5
- data/lib/new_relic/agent/vm/snapshot.rb +1 -1
- data/lib/new_relic/agent/vm.rb +1 -1
- data/lib/new_relic/agent/worker_loop.rb +1 -1
- data/lib/new_relic/agent.rb +49 -8
- data/lib/new_relic/cli/command.rb +1 -1
- data/lib/new_relic/cli/commands/deployments.rb +1 -2
- data/lib/new_relic/cli/commands/install.rb +4 -3
- data/lib/new_relic/coerce.rb +32 -7
- data/lib/new_relic/collection_helper.rb +1 -1
- data/lib/new_relic/constants.rb +42 -0
- data/lib/new_relic/control/class_methods.rb +1 -1
- data/lib/new_relic/control/frameworks/external.rb +1 -1
- data/lib/new_relic/control/frameworks/merb.rb +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +1 -1
- data/lib/new_relic/control/frameworks/rails3.rb +1 -1
- data/lib/new_relic/control/frameworks/rails4.rb +1 -1
- data/lib/new_relic/control/frameworks/rails_notifications.rb +1 -1
- data/lib/new_relic/control/frameworks/ruby.rb +1 -1
- data/lib/new_relic/control/frameworks/sinatra.rb +1 -1
- data/lib/new_relic/control/frameworks.rb +1 -1
- data/lib/new_relic/control/instance_methods.rb +11 -2
- data/lib/new_relic/control/instrumentation.rb +1 -1
- data/lib/new_relic/control/server_methods.rb +1 -1
- data/lib/new_relic/control.rb +1 -1
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/dependency_detection.rb +9 -5
- data/lib/new_relic/environment_report.rb +2 -4
- data/lib/new_relic/helper.rb +1 -1
- data/lib/new_relic/language_support.rb +1 -1
- data/lib/new_relic/latest_changes.rb +2 -2
- data/lib/new_relic/local_environment.rb +1 -1
- data/lib/new_relic/metric_data.rb +1 -1
- data/lib/new_relic/metric_spec.rb +1 -1
- data/lib/new_relic/noticed_error.rb +39 -18
- data/lib/new_relic/rack/agent_hooks.rb +1 -1
- data/lib/new_relic/rack/agent_middleware.rb +1 -1
- data/lib/new_relic/rack/browser_monitoring.rb +6 -1
- data/lib/new_relic/rack.rb +1 -1
- data/lib/new_relic/recipes/capistrano3.rb +1 -1
- data/lib/new_relic/recipes/capistrano_legacy.rb +1 -1
- data/lib/new_relic/recipes.rb +1 -1
- data/lib/new_relic/supportability_helper.rb +17 -1
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +1 -1
- data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
- data/lib/tasks/all.rb +1 -1
- data/lib/tasks/multiverse.rb +35 -1
- data/lib/tasks/newrelic.rb +1 -1
- data/lib/tasks/tests.rake +6 -1
- data/newrelic_rpm.gemspec +18 -13
- data/recipes/newrelic.rb +1 -1
- data/test/agent_helper.rb +339 -72
- metadata +104 -41
- data/.travis.yml +0 -175
- data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
- data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
- data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
- data/lib/new_relic/agent/transaction/attributes.rb +0 -154
- data/lib/new_relic/build.rb +0 -2
- data/lib/new_relic/metrics.rb +0 -13
- data/lib/tasks/versions.html.erb +0 -28
- data/lib/tasks/versions.postface.html +0 -8
- data/lib/tasks/versions.preface.html +0 -9
- data/lib/tasks/versions.rake +0 -65
- data/lib/tasks/versions.txt.erb +0 -14
data/test/agent_helper.rb
CHANGED
@@ -1,30 +1,61 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
|
-
# See https://github.com/newrelic/
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
5
|
# These helpers should not have any gem dependencies except on newrelic_rpm
|
6
6
|
# itself, and should be usable from within any multiverse suite.
|
7
7
|
|
8
8
|
require 'json'
|
9
|
+
require 'net/http'
|
10
|
+
begin
|
11
|
+
require 'net/http/status'
|
12
|
+
rescue LoadError
|
13
|
+
# NOP -- Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
|
14
|
+
end
|
15
|
+
|
16
|
+
module MiniTest
|
17
|
+
module Assertions
|
18
|
+
# The failure message is backwards. This patch reverses the message
|
19
|
+
# Note: passing +msg+ caused two failure messages to be shown on failure
|
20
|
+
# and was more confusing than patching here.
|
21
|
+
def assert_match matcher, obj, msg = nil
|
22
|
+
msg = message(msg) { "Expected #{mu_pp obj} to match #{mu_pp matcher}" }
|
23
|
+
assert_respond_to matcher, :"=~"
|
24
|
+
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
25
|
+
assert matcher =~ obj, msg
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
9
29
|
|
10
30
|
class ArrayLogDevice
|
11
|
-
def initialize
|
31
|
+
def initialize array=[]
|
12
32
|
@array = array
|
13
33
|
end
|
14
34
|
attr_reader :array
|
15
35
|
|
16
|
-
def write
|
36
|
+
def write message
|
17
37
|
@array << message
|
18
38
|
end
|
19
39
|
|
20
40
|
def close; end
|
21
41
|
end
|
22
42
|
|
23
|
-
def
|
43
|
+
def fake_guid length=16
|
44
|
+
NewRelic::Agent::GuidGenerator.generate_guid length
|
45
|
+
end
|
46
|
+
|
47
|
+
def assert_match matcher, obj, msg = nil
|
48
|
+
msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
|
49
|
+
assert_respond_to matcher, :"=~"
|
50
|
+
matcher = Regexp.new Regexp.escape matcher if String === matcher
|
51
|
+
assert matcher =~ obj, msg
|
52
|
+
end
|
53
|
+
|
54
|
+
def assert_between floor, ceiling, value, message="expected #{floor} <= #{value} <= #{ceiling}"
|
24
55
|
assert((floor <= value && value <= ceiling), message)
|
25
56
|
end
|
26
57
|
|
27
|
-
def assert_in_delta
|
58
|
+
def assert_in_delta expected, actual, delta
|
28
59
|
assert_between((expected - delta), (expected + delta), actual)
|
29
60
|
end
|
30
61
|
|
@@ -36,7 +67,7 @@ def reset_error_traces!
|
|
36
67
|
NewRelic::Agent.instance.error_collector.error_trace_aggregator.reset!
|
37
68
|
end
|
38
69
|
|
39
|
-
def assert_has_traced_error
|
70
|
+
def assert_has_traced_error error_class
|
40
71
|
errors = harvest_error_traces!
|
41
72
|
assert \
|
42
73
|
errors.find {|e| e.exception_class_name == error_class.name} != nil, \
|
@@ -55,6 +86,14 @@ def last_transaction_event
|
|
55
86
|
harvest_transaction_events!.last.last
|
56
87
|
end
|
57
88
|
|
89
|
+
def harvest_span_events!
|
90
|
+
NewRelic::Agent.instance.span_event_aggregator.harvest!
|
91
|
+
end
|
92
|
+
|
93
|
+
def last_span_event
|
94
|
+
harvest_span_events!.last.last
|
95
|
+
end
|
96
|
+
|
58
97
|
def harvest_error_events!
|
59
98
|
NewRelic::Agent.instance.error_collector.error_event_aggregator.harvest!
|
60
99
|
end
|
@@ -63,38 +102,44 @@ def last_error_event
|
|
63
102
|
harvest_error_events!.last.last
|
64
103
|
end
|
65
104
|
|
66
|
-
unless defined?
|
67
|
-
def assert_block
|
105
|
+
unless defined? assert_block
|
106
|
+
def assert_block *msgs
|
68
107
|
assert yield, *msgs
|
69
108
|
end
|
70
109
|
end
|
71
110
|
|
72
|
-
unless defined?
|
73
|
-
def assert_includes
|
111
|
+
unless defined? assert_includes
|
112
|
+
def assert_includes collection, member, msg=nil
|
74
113
|
msg = "Expected #{collection.inspect} to include #{member.inspect}"
|
75
114
|
assert_block( msg ) { collection.include?(member) }
|
76
115
|
end
|
77
116
|
end
|
78
117
|
|
79
|
-
unless defined?
|
80
|
-
def assert_not_includes
|
118
|
+
unless defined? assert_not_includes
|
119
|
+
def assert_not_includes collection, member, msg=nil
|
81
120
|
msg = "Expected #{collection.inspect} not to include #{member.inspect}"
|
82
121
|
assert !collection.include?(member), msg
|
83
122
|
end
|
84
123
|
end
|
85
124
|
|
86
|
-
unless defined?
|
87
|
-
def assert_empty
|
125
|
+
unless defined? assert_empty
|
126
|
+
def assert_empty collection, msg=nil
|
88
127
|
assert collection.empty?, msg
|
89
128
|
end
|
90
129
|
end
|
91
130
|
|
92
|
-
def assert_equal_unordered
|
131
|
+
def assert_equal_unordered left, right
|
93
132
|
assert_equal(left.length, right.length, "Lengths don't match. #{left.length} != #{right.length}")
|
94
133
|
left.each { |element| assert_includes(right, element) }
|
95
134
|
end
|
96
135
|
|
97
|
-
def
|
136
|
+
def assert_log_contains(log, message)
|
137
|
+
lines = log.array
|
138
|
+
failure_message = "Did not find '#{message}' in log. Log contained:\n#{lines.join('')}"
|
139
|
+
assert (lines.any? { |line| line.match(message) }), failure_message
|
140
|
+
end
|
141
|
+
|
142
|
+
def assert_audit_log_contains audit_log_contents, needle
|
98
143
|
# Original request bodies dumped to the log have symbol keys, but once
|
99
144
|
# they go through a dump/load, they're strings again, so we strip
|
100
145
|
# double-quotes and colons from the log, and the strings we searching for.
|
@@ -112,7 +157,7 @@ end
|
|
112
157
|
# orderings of the key/value pairs in Hashes that were embedded in the request
|
113
158
|
# body). So, this method traverses an object graph and only makes assertions
|
114
159
|
# about the terminal (non-Array-or-Hash) nodes therein.
|
115
|
-
def assert_audit_log_contains_object
|
160
|
+
def assert_audit_log_contains_object audit_log_contents, o, format = :json
|
116
161
|
case o
|
117
162
|
when Hash
|
118
163
|
o.each do |k,v|
|
@@ -130,12 +175,12 @@ def assert_audit_log_contains_object(audit_log_contents, o, format = :json)
|
|
130
175
|
end
|
131
176
|
end
|
132
177
|
|
133
|
-
def compare_metrics
|
178
|
+
def compare_metrics expected, actual
|
134
179
|
actual.delete_if {|a| a.include?('GC/Transaction/') }
|
135
180
|
assert_equal(expected.to_a.sort, actual.to_a.sort, "extra: #{(actual - expected).to_a.inspect}; missing: #{(expected - actual).to_a.inspect}")
|
136
181
|
end
|
137
182
|
|
138
|
-
def metric_spec_from_specish
|
183
|
+
def metric_spec_from_specish specish
|
139
184
|
spec = case specish
|
140
185
|
when String then NewRelic::MetricSpec.new(specish)
|
141
186
|
when Array then NewRelic::MetricSpec.new(*specish)
|
@@ -143,7 +188,7 @@ def metric_spec_from_specish(specish)
|
|
143
188
|
spec
|
144
189
|
end
|
145
190
|
|
146
|
-
def _normalize_metric_expectations
|
191
|
+
def _normalize_metric_expectations expectations
|
147
192
|
case expectations
|
148
193
|
when Array
|
149
194
|
hash = {}
|
@@ -157,7 +202,7 @@ def _normalize_metric_expectations(expectations)
|
|
157
202
|
end
|
158
203
|
end
|
159
204
|
|
160
|
-
def dump_stats
|
205
|
+
def dump_stats stats
|
161
206
|
str = " Call count: #{stats.call_count}\n"
|
162
207
|
str << " Total call time: #{stats.total_call_time}\n"
|
163
208
|
str << " Total exclusive time: #{stats.total_exclusive_time}\n"
|
@@ -170,7 +215,7 @@ def dump_stats(stats)
|
|
170
215
|
str
|
171
216
|
end
|
172
217
|
|
173
|
-
def assert_stats_has_values
|
218
|
+
def assert_stats_has_values stats, expected_spec, expected_attrs
|
174
219
|
expected_attrs.each do |attr, expected_value|
|
175
220
|
actual_value = stats.send(attr)
|
176
221
|
if attr == :call_count
|
@@ -183,7 +228,7 @@ def assert_stats_has_values(stats, expected_spec, expected_attrs)
|
|
183
228
|
end
|
184
229
|
end
|
185
230
|
|
186
|
-
def assert_metrics_recorded
|
231
|
+
def assert_metrics_recorded expected
|
187
232
|
expected = _normalize_metric_expectations(expected)
|
188
233
|
expected.each do |specish, expected_attrs|
|
189
234
|
expected_spec = metric_spec_from_specish(specish)
|
@@ -212,9 +257,9 @@ end
|
|
212
257
|
#
|
213
258
|
# If you want to *allow* unexpected metrics matching certain patterns, use
|
214
259
|
# the :ignore_filter option. This will allow you to specify a Regex that
|
215
|
-
#
|
260
|
+
# allowlists broad swathes of metric territory (e.g. 'Supportability/').
|
216
261
|
#
|
217
|
-
def assert_metrics_recorded_exclusive
|
262
|
+
def assert_metrics_recorded_exclusive expected, options={}
|
218
263
|
expected = _normalize_metric_expectations(expected)
|
219
264
|
assert_metrics_recorded(expected)
|
220
265
|
|
@@ -252,7 +297,7 @@ def clear_metrics!
|
|
252
297
|
NewRelic::Agent.instance.stats_engine.reset_for_test!
|
253
298
|
end
|
254
299
|
|
255
|
-
def assert_metrics_not_recorded
|
300
|
+
def assert_metrics_not_recorded not_expected
|
256
301
|
not_expected = _normalize_metric_expectations(not_expected)
|
257
302
|
found_but_not_expected = []
|
258
303
|
not_expected.each do |specish, _|
|
@@ -266,7 +311,7 @@ end
|
|
266
311
|
|
267
312
|
alias :refute_metrics_recorded :assert_metrics_not_recorded
|
268
313
|
|
269
|
-
def assert_no_metrics_match
|
314
|
+
def assert_no_metrics_match regex
|
270
315
|
matching_metrics = []
|
271
316
|
NewRelic::Agent.instance.stats_engine.to_h.keys.map(&:to_s).each do |metric|
|
272
317
|
matching_metrics << metric if metric.match regex
|
@@ -281,30 +326,30 @@ end
|
|
281
326
|
|
282
327
|
alias :refute_metrics_match :assert_no_metrics_match
|
283
328
|
|
284
|
-
def format_metric_spec_list
|
329
|
+
def format_metric_spec_list specs
|
285
330
|
spec_strings = specs.map do |spec|
|
286
331
|
"#{spec.name} (#{spec.scope.empty? ? '<unscoped>' : spec.scope})"
|
287
332
|
end
|
288
333
|
"[\n #{spec_strings.join(",\n ")}\n]"
|
289
334
|
end
|
290
335
|
|
291
|
-
def assert_truthy
|
336
|
+
def assert_truthy expected, msg=nil
|
292
337
|
msg ||= "Expected #{expected.inspect} to be truthy"
|
293
338
|
assert !!expected, msg
|
294
339
|
end
|
295
340
|
|
296
|
-
def assert_falsy
|
341
|
+
def assert_falsy expected, msg=nil
|
297
342
|
msg ||= "Expected #{expected.inspect} to be falsy"
|
298
343
|
assert !expected, msg
|
299
344
|
end
|
300
345
|
|
301
|
-
unless defined?
|
302
|
-
def assert_false
|
346
|
+
unless defined? assert_false
|
347
|
+
def assert_false expected
|
303
348
|
assert_equal false, expected
|
304
349
|
end
|
305
350
|
end
|
306
351
|
|
307
|
-
unless defined?
|
352
|
+
unless defined? refute
|
308
353
|
alias refute assert_false
|
309
354
|
end
|
310
355
|
|
@@ -326,7 +371,7 @@ end
|
|
326
371
|
# With a transaction name plus category:
|
327
372
|
# in_transaction('foobar', :category => :controller) { ... }
|
328
373
|
#
|
329
|
-
def in_transaction
|
374
|
+
def in_transaction *args, &blk
|
330
375
|
opts = (args.last && args.last.is_a?(Hash)) ? args.pop : {}
|
331
376
|
category = (opts && opts.delete(:category)) || :other
|
332
377
|
|
@@ -345,25 +390,71 @@ def in_transaction(*args, &blk)
|
|
345
390
|
txn
|
346
391
|
end
|
347
392
|
|
348
|
-
|
393
|
+
# Temporarily disables default transformer so tests with invalid inputs can be tried
|
394
|
+
def with_disabled_defaults_transformer key
|
395
|
+
begin
|
396
|
+
transformer = NewRelic::Agent::Configuration::DEFAULTS[key][:transform]
|
397
|
+
NewRelic::Agent::Configuration::DEFAULTS[key][:transform] = nil
|
398
|
+
yield
|
399
|
+
ensure
|
400
|
+
NewRelic::Agent::Configuration::DEFAULTS[key][:transform] = transformer
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
# Convenience wrapper to stand up a transaction and provide a segment within
|
405
|
+
# that transaction to work with. The same arguements as provided to in_transaction
|
406
|
+
# may be supplied.
|
407
|
+
def with_segment *args, &blk
|
408
|
+
segment = nil
|
409
|
+
txn = in_transaction(*args) do |txn|
|
410
|
+
segment = txn.current_segment
|
411
|
+
yield segment, txn
|
412
|
+
end
|
413
|
+
[segment, txn]
|
414
|
+
end
|
415
|
+
|
416
|
+
# building error attributes on segments are deferred until it's time
|
417
|
+
# to publish/harvest them as spans, so for testing, we'll explicitly
|
418
|
+
# build 'em as appropriate so we can test 'em
|
419
|
+
def build_deferred_error_attributes segment
|
420
|
+
return unless segment.noticed_error
|
421
|
+
return if segment.noticed_error_attributes.frozen?
|
422
|
+
segment.noticed_error.build_error_attributes
|
423
|
+
end
|
424
|
+
|
425
|
+
def capture_segment_with_error
|
426
|
+
begin
|
427
|
+
segment_with_error = nil
|
428
|
+
with_segment do |segment|
|
429
|
+
segment_with_error = segment
|
430
|
+
raise "oops!"
|
431
|
+
end
|
432
|
+
rescue Exception => exception
|
433
|
+
assert segment_with_error, "expected to have a segment_with_error"
|
434
|
+
build_deferred_error_attributes segment_with_error
|
435
|
+
return segment_with_error, exception
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
def stub_transaction_guid guid
|
349
440
|
NewRelic::Agent::Transaction.tl_current.instance_variable_set(:@guid, guid)
|
350
441
|
end
|
351
442
|
|
352
443
|
# Convenience wrapper around in_transaction that sets the category so that it
|
353
444
|
# looks like we are in a web transaction
|
354
|
-
def in_web_transaction
|
445
|
+
def in_web_transaction name='dummy'
|
355
446
|
in_transaction(name, :category => :controller, :request => stub(:path => '/')) do |txn|
|
356
447
|
yield txn
|
357
448
|
end
|
358
449
|
end
|
359
450
|
|
360
|
-
def in_background_transaction
|
451
|
+
def in_background_transaction name='silly'
|
361
452
|
in_transaction(name, :category => :task) do |txn|
|
362
453
|
yield txn
|
363
454
|
end
|
364
455
|
end
|
365
456
|
|
366
|
-
def refute_contains_request_params
|
457
|
+
def refute_contains_request_params attributes
|
367
458
|
attributes.keys.each do |key|
|
368
459
|
refute_match(/^request\.parameters\./, key.to_s)
|
369
460
|
end
|
@@ -382,7 +473,7 @@ def last_transaction_trace_request_params
|
|
382
473
|
end
|
383
474
|
end
|
384
475
|
|
385
|
-
def find_sql_trace
|
476
|
+
def find_sql_trace metric_name
|
386
477
|
NewRelic::Agent.agent.sql_sampler.sql_traces.values.detect do |trace|
|
387
478
|
trace.database_metric_name == metric_name
|
388
479
|
end
|
@@ -392,7 +483,7 @@ def last_sql_trace
|
|
392
483
|
NewRelic::Agent.agent.sql_sampler.sql_traces.values.last
|
393
484
|
end
|
394
485
|
|
395
|
-
def find_last_transaction_node
|
486
|
+
def find_last_transaction_node transaction_sample=nil
|
396
487
|
if transaction_sample
|
397
488
|
root_node = transaction_sample.root_node
|
398
489
|
else
|
@@ -405,7 +496,7 @@ def find_last_transaction_node(transaction_sample=nil)
|
|
405
496
|
return last_node
|
406
497
|
end
|
407
498
|
|
408
|
-
def find_node_with_name
|
499
|
+
def find_node_with_name transaction_sample, name
|
409
500
|
transaction_sample.root_node.each_node do |node|
|
410
501
|
if node.metric_name == name
|
411
502
|
return node
|
@@ -415,7 +506,7 @@ def find_node_with_name(transaction_sample, name)
|
|
415
506
|
nil
|
416
507
|
end
|
417
508
|
|
418
|
-
def find_node_with_name_matching
|
509
|
+
def find_node_with_name_matching transaction_sample, regex
|
419
510
|
transaction_sample.root_node.each_node do |node|
|
420
511
|
if node.metric_name.match regex
|
421
512
|
return node
|
@@ -425,7 +516,7 @@ def find_node_with_name_matching(transaction_sample, regex)
|
|
425
516
|
nil
|
426
517
|
end
|
427
518
|
|
428
|
-
def find_all_nodes_with_name_matching
|
519
|
+
def find_all_nodes_with_name_matching transaction_sample, regexes
|
429
520
|
regexes = [regexes].flatten
|
430
521
|
matching_nodes = []
|
431
522
|
|
@@ -440,7 +531,7 @@ def find_all_nodes_with_name_matching(transaction_sample, regexes)
|
|
440
531
|
matching_nodes
|
441
532
|
end
|
442
533
|
|
443
|
-
def with_config
|
534
|
+
def with_config config_hash, at_start=true
|
444
535
|
config = NewRelic::Agent::Configuration::DottedHash.new(config_hash, true)
|
445
536
|
NewRelic::Agent.config.add_config_for_testing(config, at_start)
|
446
537
|
NewRelic::Agent.instance.refresh_attribute_filter
|
@@ -459,13 +550,13 @@ def with_server_source config_hash, at_start=true
|
|
459
550
|
end
|
460
551
|
end
|
461
552
|
|
462
|
-
def with_config_low_priority
|
553
|
+
def with_config_low_priority config_hash
|
463
554
|
with_config(config_hash, false) do
|
464
555
|
yield
|
465
556
|
end
|
466
557
|
end
|
467
558
|
|
468
|
-
def with_transaction_renaming_rules
|
559
|
+
def with_transaction_renaming_rules rule_specs
|
469
560
|
original_engine = NewRelic::Agent.agent.instance_variable_get(:@transaction_rules)
|
470
561
|
begin
|
471
562
|
new_engine = NewRelic::Agent::RulesEngine.create_transaction_rules('transaction_name_rules' => rule_specs)
|
@@ -491,7 +582,7 @@ unless Time.respond_to?(:__original_now)
|
|
491
582
|
end
|
492
583
|
end
|
493
584
|
|
494
|
-
def nr_freeze_time
|
585
|
+
def nr_freeze_time now=Time.now
|
495
586
|
Time.__frozen_now = now
|
496
587
|
end
|
497
588
|
|
@@ -499,11 +590,11 @@ def nr_unfreeze_time
|
|
499
590
|
Time.__frozen_now = nil
|
500
591
|
end
|
501
592
|
|
502
|
-
def advance_time
|
593
|
+
def advance_time seconds
|
503
594
|
Time.__frozen_now = Time.now + seconds
|
504
595
|
end
|
505
596
|
|
506
|
-
def with_constant_defined
|
597
|
+
def with_constant_defined constant_symbol, implementation=Module.new
|
507
598
|
const_path = constant_path(constant_symbol.to_s)
|
508
599
|
|
509
600
|
if const_path
|
@@ -523,7 +614,7 @@ def with_constant_defined(constant_symbol, implementation=Module.new)
|
|
523
614
|
end
|
524
615
|
end
|
525
616
|
|
526
|
-
def constant_path
|
617
|
+
def constant_path name, opts={}
|
527
618
|
allow_partial = opts[:allow_partial]
|
528
619
|
path = [Object]
|
529
620
|
parts = name.gsub(/^::/, '').split('::')
|
@@ -536,13 +627,13 @@ def constant_path(name, opts={})
|
|
536
627
|
path
|
537
628
|
end
|
538
629
|
|
539
|
-
def get_parent
|
630
|
+
def get_parent constant_name
|
540
631
|
parent_name = constant_name.gsub(/::[^:]*$/, '')
|
541
632
|
const_path = constant_path(parent_name)
|
542
633
|
const_path ? const_path[-1] : nil
|
543
634
|
end
|
544
635
|
|
545
|
-
def undefine_constant
|
636
|
+
def undefine_constant constant_symbol
|
546
637
|
const_str = constant_symbol.to_s
|
547
638
|
parent = get_parent(const_str)
|
548
639
|
const_name = const_str.gsub(/.*::/, '')
|
@@ -566,11 +657,11 @@ ensure
|
|
566
657
|
NewRelic::Agent.logger = orig_logger
|
567
658
|
end
|
568
659
|
|
569
|
-
def create_agent_command
|
660
|
+
def create_agent_command args={}
|
570
661
|
NewRelic::Agent::Commands::AgentCommand.new([-1, { "name" => "command_name", "arguments" => args}])
|
571
662
|
end
|
572
663
|
|
573
|
-
def wait_for_backtrace_service_poll
|
664
|
+
def wait_for_backtrace_service_poll opts={}
|
574
665
|
defaults = {
|
575
666
|
:timeout => 10.0,
|
576
667
|
:service => NewRelic::Agent.agent.agent_command_router.backtrace_service,
|
@@ -596,7 +687,7 @@ def wait_for_backtrace_service_poll(opts={})
|
|
596
687
|
end
|
597
688
|
end
|
598
689
|
|
599
|
-
def with_array_logger
|
690
|
+
def with_array_logger level=:info
|
600
691
|
orig_logger = NewRelic::Agent.logger
|
601
692
|
config = { :log_level => level }
|
602
693
|
logdev = ArrayLogDevice.new
|
@@ -612,20 +703,90 @@ ensure
|
|
612
703
|
NewRelic::Agent.logger = orig_logger
|
613
704
|
end
|
614
705
|
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
706
|
+
# The EnvUpdater was introduced due to random fails in JRuby environment
|
707
|
+
# whereby attempting to set ENV[key] = some_value randomly failed.
|
708
|
+
# It is conjectured that this is thread related, but may also be
|
709
|
+
# a core bug in the JVM implementation of Ruby. Root cause was not
|
710
|
+
# discovered, but it was found that a combination of retrying and using
|
711
|
+
# mutex lock around the update operation was the only consistently working
|
712
|
+
# solution as the error continued to surface without the mutex and
|
713
|
+
# retry alone wasn't enough, either.
|
714
|
+
#
|
715
|
+
# JRUBY: oraclejdk8 + jruby-9.2.6.0
|
716
|
+
#
|
717
|
+
# NOTE: Singleton pattern to ensure one mutex lock for all threads
|
718
|
+
class EnvUpdater
|
719
|
+
MAX_RETRIES = 5
|
720
|
+
|
721
|
+
def initialize
|
722
|
+
@mutex = Mutex.new
|
620
723
|
end
|
621
|
-
|
724
|
+
|
725
|
+
# Will attempt the given block up to MAX_RETRIES before
|
726
|
+
# surfacing the exception down the chain.
|
727
|
+
def with_retry retry_limit=MAX_RETRIES
|
728
|
+
retries ||= 0
|
729
|
+
sleep(retries)
|
622
730
|
yield
|
623
|
-
|
624
|
-
|
731
|
+
rescue
|
732
|
+
(retries += 1) < retry_limit ? retry : raise
|
733
|
+
end
|
734
|
+
|
735
|
+
# Locks and updates the ENV
|
736
|
+
def safe_update env
|
737
|
+
with_retry do
|
738
|
+
@mutex.synchronize do
|
739
|
+
env.each{ |key, val| ENV[key] = val.to_s }
|
740
|
+
end
|
741
|
+
end
|
742
|
+
end
|
743
|
+
|
744
|
+
# Locks and restores the ENV
|
745
|
+
def safe_restore old_env
|
746
|
+
with_retry do
|
747
|
+
@mutex.synchronize do
|
748
|
+
old_env.each{ |key, val| val ? ENV[key] = val : ENV.delete(key) }
|
749
|
+
end
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
# Singleton pattern implemented via @@instance
|
754
|
+
def self.instance
|
755
|
+
@@instance ||= EnvUpdater.new
|
625
756
|
end
|
757
|
+
|
758
|
+
def self.safe_update env
|
759
|
+
instance.safe_update env
|
760
|
+
end
|
761
|
+
|
762
|
+
def self.safe_restore old_env
|
763
|
+
instance.safe_restore old_env
|
764
|
+
end
|
765
|
+
|
766
|
+
# Effectively saves current ENV settings for given env's key/values,
|
767
|
+
# runs given block, then restores ENV to original state before returning.
|
768
|
+
def self.inject env, &block
|
769
|
+
old_env = {}
|
770
|
+
env.each{ |key, val| old_env[key] = ENV[key] }
|
771
|
+
begin
|
772
|
+
safe_update(env)
|
773
|
+
yield
|
774
|
+
ensure
|
775
|
+
safe_restore(old_env)
|
776
|
+
end
|
777
|
+
end
|
778
|
+
|
779
|
+
# must call instance here to ensure only one @mutex for all threads.
|
780
|
+
instance
|
781
|
+
end
|
782
|
+
|
783
|
+
# Changes ENV settings to given and runs given block and restores ENV
|
784
|
+
# to original values before returning.
|
785
|
+
def with_environment env, &block
|
786
|
+
EnvUpdater.inject(env) { yield }
|
626
787
|
end
|
627
788
|
|
628
|
-
def with_argv
|
789
|
+
def with_argv argv
|
629
790
|
old_argv = ARGV.dup
|
630
791
|
ARGV.clear
|
631
792
|
ARGV.concat(argv)
|
@@ -638,7 +799,7 @@ def with_argv(argv)
|
|
638
799
|
end
|
639
800
|
end
|
640
801
|
|
641
|
-
def with_ignore_error_filter
|
802
|
+
def with_ignore_error_filter filter, &blk
|
642
803
|
original_filter = NewRelic::Agent.ignore_error_filter
|
643
804
|
NewRelic::Agent.ignore_error_filter(&filter)
|
644
805
|
|
@@ -647,7 +808,7 @@ ensure
|
|
647
808
|
NewRelic::Agent::ErrorCollector.ignore_error_filter = original_filter
|
648
809
|
end
|
649
810
|
|
650
|
-
def json_dump_and_encode
|
811
|
+
def json_dump_and_encode object
|
651
812
|
Base64.encode64(::JSON.dump(object))
|
652
813
|
end
|
653
814
|
|
@@ -655,7 +816,7 @@ def get_last_analytics_event
|
|
655
816
|
NewRelic::Agent.agent.transaction_event_aggregator.harvest![1].last
|
656
817
|
end
|
657
818
|
|
658
|
-
def swap_instance_method
|
819
|
+
def swap_instance_method target, method_name, new_method_implementation, &blk
|
659
820
|
old_method_implementation = target.instance_method(method_name)
|
660
821
|
target.send(:define_method, method_name, new_method_implementation)
|
661
822
|
yield
|
@@ -670,7 +831,7 @@ def cross_agent_tests_dir
|
|
670
831
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'cross_agent_tests'))
|
671
832
|
end
|
672
833
|
|
673
|
-
def load_cross_agent_test
|
834
|
+
def load_cross_agent_test name
|
674
835
|
test_file_path = File.join(cross_agent_tests_dir, "#{name}.json")
|
675
836
|
data = File.read(test_file_path)
|
676
837
|
data.gsub!('callCount', 'call_count')
|
@@ -679,13 +840,13 @@ def load_cross_agent_test(name)
|
|
679
840
|
data
|
680
841
|
end
|
681
842
|
|
682
|
-
def each_cross_agent_test
|
843
|
+
def each_cross_agent_test options
|
683
844
|
options = {:dir => nil, :pattern => "*"}.update(options)
|
684
845
|
path = File.join [cross_agent_tests_dir, options[:dir], options[:pattern]].compact
|
685
846
|
Dir.glob(path).each { |file| yield file}
|
686
847
|
end
|
687
848
|
|
688
|
-
def assert_event_attributes
|
849
|
+
def assert_event_attributes event, test_name, expected_attributes, non_expected_attributes
|
689
850
|
incorrect_attributes = []
|
690
851
|
|
691
852
|
event_attrs = event[0]
|
@@ -709,10 +870,116 @@ def assert_event_attributes(event, test_name, expected_attributes, non_expected_
|
|
709
870
|
assert(incorrect_attributes.empty?, msg)
|
710
871
|
|
711
872
|
non_expected_attributes.each do |name|
|
712
|
-
|
873
|
+
refute event_attrs[name], "Found value '#{event_attrs[name]}' for attribute '#{name}', but expected nothing in #{test_name}"
|
713
874
|
end
|
714
875
|
end
|
715
876
|
|
716
|
-
def attributes_for
|
877
|
+
def attributes_for sample, type
|
717
878
|
sample.attributes.instance_variable_get("@#{type}_attributes")
|
718
879
|
end
|
880
|
+
|
881
|
+
def uncache_trusted_account_key
|
882
|
+
NewRelic::Agent::Transaction::TraceContext::AccountHelpers.instance_variable_set :@trace_state_entry_key, nil
|
883
|
+
end
|
884
|
+
|
885
|
+
def reset_buffers_and_caches
|
886
|
+
NewRelic::Agent.drop_buffered_data
|
887
|
+
uncache_trusted_account_key
|
888
|
+
end
|
889
|
+
|
890
|
+
def message_for_status_code code
|
891
|
+
# Net::HTTP::STATUS_CODES was introduced in Ruby 2.5
|
892
|
+
if defined?(Net::HTTP::STATUS_CODES)
|
893
|
+
return Net::HTTP::STATUS_CODES[code]
|
894
|
+
end
|
895
|
+
|
896
|
+
case code
|
897
|
+
when 200 then "OK"
|
898
|
+
when 404 then "Not Found"
|
899
|
+
when 403 then "Forbidden"
|
900
|
+
else "Unknown"
|
901
|
+
end
|
902
|
+
end
|
903
|
+
|
904
|
+
# wraps the given headers in a Net::HTTPResponse which has accompanying
|
905
|
+
# http status code associated with it.
|
906
|
+
# a "status_code" may be passed in the headers to alter the HTTP Status Code
|
907
|
+
# that is wrapped in the response.
|
908
|
+
def mock_http_response headers, wrap_it=true
|
909
|
+
status_code = (headers.delete("status_code") || 200).to_i
|
910
|
+
net_http_resp = Net::HTTPResponse.new(1.0, status_code, message_for_status_code(status_code))
|
911
|
+
headers.each do |key, value|
|
912
|
+
net_http_resp.add_field key.to_s, value
|
913
|
+
end
|
914
|
+
return net_http_resp unless wrap_it
|
915
|
+
NewRelic::Agent::HTTPClients::NetHTTPResponse.new(net_http_resp)
|
916
|
+
end
|
917
|
+
|
918
|
+
# +expected+ can be a string or regular expression
|
919
|
+
def assert_match_or_equal expected, value
|
920
|
+
if expected.is_a?(Regexp)
|
921
|
+
assert_match expected, value
|
922
|
+
else
|
923
|
+
assert_equal expected, value
|
924
|
+
end
|
925
|
+
end
|
926
|
+
|
927
|
+
# selects the last segment with a noticed_error and checks
|
928
|
+
# the expectations against it.
|
929
|
+
def assert_segment_noticed_error txn, segment_name, error_classes, error_message
|
930
|
+
error_segment = txn.segments.reverse.detect{|s| s.noticed_error}
|
931
|
+
assert error_segment, "Expected at least one segment with a noticed_error"
|
932
|
+
|
933
|
+
assert_match_or_equal segment_name, error_segment.name
|
934
|
+
|
935
|
+
noticed_error = error_segment.noticed_error
|
936
|
+
|
937
|
+
assert_match_or_equal error_classes, noticed_error.exception_class_name
|
938
|
+
assert_match_or_equal error_message, noticed_error.message
|
939
|
+
end
|
940
|
+
|
941
|
+
def assert_transaction_noticed_error txn, error_classes
|
942
|
+
refute_empty txn.exceptions, "Expected transaction to notice the error"
|
943
|
+
assert_match_or_equal error_classes, txn.exceptions.keys.first.class.name
|
944
|
+
end
|
945
|
+
|
946
|
+
def refute_transaction_noticed_error txn, error_class
|
947
|
+
error_segment = txn.segments.reverse.detect{|s| s.noticed_error}
|
948
|
+
assert error_segment, "Expected at least one segment with a noticed_error"
|
949
|
+
assert_empty txn.exceptions, "Expected transaction to NOT notice any segment errors"
|
950
|
+
end
|
951
|
+
|
952
|
+
def refute_raises *exp
|
953
|
+
msg = "#{exp.pop}.\n" if String === exp.last
|
954
|
+
|
955
|
+
begin
|
956
|
+
yield
|
957
|
+
rescue MiniTest::Skip => e
|
958
|
+
puts "SKIP REPORTS: #{e.inspect}"
|
959
|
+
return e if exp.include? MiniTest::Skip
|
960
|
+
raise e
|
961
|
+
rescue Exception => e
|
962
|
+
puts "EXCEPTION RAISED: #{e.inspect}\n#{e.backtrace}"
|
963
|
+
exp = exp.first if exp.size == 1
|
964
|
+
flunk msg || "unexpected exception raised: #{e}"
|
965
|
+
end
|
966
|
+
end
|
967
|
+
|
968
|
+
def assert_implements instance, method, *args
|
969
|
+
fail_message = "expected #{instance.class}##{method} method to be implemented"
|
970
|
+
refute_raises NotImplementedError, fail_message do
|
971
|
+
instance.send(method, *args)
|
972
|
+
end
|
973
|
+
end
|
974
|
+
|
975
|
+
def defer_testing_to_min_supported_rails test_file, min_rails_version, supports_jruby=true
|
976
|
+
if defined?(::Rails) &&
|
977
|
+
defined?(::Rails::VERSION::STRING) &&
|
978
|
+
(::Rails::VERSION::STRING.to_f >= min_rails_version) &&
|
979
|
+
(supports_jruby || !NewRelic::LanguageSupport.jruby?)
|
980
|
+
|
981
|
+
yield
|
982
|
+
else
|
983
|
+
puts "Skipping tests in #{test_file} because Rails >= #{min_rails_version} is unavailable"
|
984
|
+
end
|
985
|
+
end
|