newrelic_rpm 3.9.7.266 → 3.9.8.273
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +44 -1
- data/lib/new_relic/agent.rb +31 -0
- data/lib/new_relic/agent/agent.rb +34 -5
- data/lib/new_relic/agent/configuration/default_source.rb +25 -1
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
- data/lib/new_relic/agent/cross_app_monitor.rb +1 -1
- data/lib/new_relic/agent/custom_event_aggregator.rb +2 -4
- data/lib/new_relic/agent/error_collector.rb +17 -12
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +9 -8
- data/lib/new_relic/agent/instrumentation/grape.rb +67 -0
- data/lib/new_relic/agent/new_relic_service.rb +93 -43
- data/lib/new_relic/agent/pipe_service.rb +4 -0
- data/lib/new_relic/agent/synthetics_event_buffer.rb +42 -0
- data/lib/new_relic/agent/system_info.rb +44 -18
- data/lib/new_relic/agent/transaction_event_aggregator.rb +9 -2
- data/lib/new_relic/agent/utilization_data.rb +77 -0
- data/lib/new_relic/agent/vm/mri_vm.rb +3 -3
- data/lib/new_relic/rack/agent_hooks.rb +15 -15
- data/lib/new_relic/recipes/capistrano3.rb +2 -2
- data/lib/new_relic/version.rb +1 -1
- data/newrelic_rpm.gemspec +0 -1
- data/test/agent_helper.rb +13 -3
- data/test/environments/lib/environments/runner.rb +3 -19
- data/test/environments/rails42/Gemfile +5 -1
- data/test/fixtures/cross_agent_tests/README.md +1 -1
- data/test/fixtures/cross_agent_tests/cat_map.json +154 -88
- data/test/fixtures/cross_agent_tests/docker_container_id/cases.json +30 -6
- data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.1.2-lxc-driver.txt +10 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.1.2-native-driver-fs.txt +10 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.1.2-native-driver-systemd.txt +10 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/heroku.txt +1 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/ubuntu-14.04-lxc-container.txt +10 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/{lxc-containers-without-docker.txt → ubuntu-14.04-no-container.txt} +0 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/ubuntu-14.10-no-container.txt +10 -0
- data/test/multiverse/lib/multiverse/runner.rb +1 -0
- data/test/multiverse/lib/multiverse/suite.rb +6 -2
- data/test/multiverse/suites/active_record/.gitignore +1 -0
- data/test/multiverse/suites/active_record/Envfile +25 -7
- data/test/multiverse/suites/active_record/Rakefile +9 -0
- data/test/{new_relic/agent/instrumentation → multiverse/suites/active_record}/active_record_test.rb +82 -88
- data/test/multiverse/suites/active_record/app/models/models.rb +27 -0
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +5 -46
- data/test/multiverse/suites/active_record/before_suite.rb +23 -0
- data/test/multiverse/suites/active_record/config/database.rb +79 -0
- data/test/multiverse/suites/active_record/config/database.yml +19 -0
- data/test/multiverse/suites/active_record/db/migrate/20141105131800_create_users_and_aliases.rb +21 -0
- data/test/multiverse/suites/active_record/db/migrate/20141106082200_create_orders_and_shipments.rb +25 -0
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +4 -1
- data/test/multiverse/suites/agent_only/custom_analytics_events_test.rb +53 -0
- data/test/multiverse/suites/agent_only/keepalive_test.rb +3 -7
- data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +170 -0
- data/test/multiverse/suites/grape/Envfile +15 -0
- data/test/multiverse/suites/grape/config/newrelic.yml +18 -0
- data/test/multiverse/suites/grape/grape_test.rb +60 -0
- data/test/multiverse/suites/grape/grape_test_api.rb +43 -0
- data/test/multiverse/suites/grape/unsupported_version_test.rb +31 -0
- data/test/multiverse/suites/json/Envfile +3 -1
- data/test/multiverse/suites/rack/rack_env_mutation_test.rb +54 -0
- data/test/multiverse/suites/rails/Envfile +1 -1
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +2 -1
- data/test/multiverse/suites/resque/resque_marshalling_test.rb +54 -0
- data/test/multiverse/suites/typhoeus/Envfile +4 -4
- data/test/new_relic/agent/agent_test.rb +37 -0
- data/test/new_relic/agent/configuration/default_source_test.rb +14 -0
- data/test/new_relic/agent/custom_event_aggregator_test.rb +3 -3
- data/test/new_relic/agent/error_collector/notice_error_test.rb +4 -4
- data/test/new_relic/agent/error_collector_test.rb +27 -4
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +23 -0
- data/test/new_relic/agent/new_relic_service_test.rb +208 -103
- data/test/new_relic/agent/pipe_service_test.rb +7 -0
- data/test/new_relic/agent/synthetics_event_buffer_test.rb +54 -0
- data/test/new_relic/agent/synthetics_monitor_test.rb +0 -3
- data/test/new_relic/agent/system_info_test.rb +6 -6
- data/test/new_relic/agent/transaction_event_aggregator_test.rb +43 -2
- data/test/new_relic/agent/utilization_data_test.rb +18 -0
- data/test/new_relic/collection_helper_test.rb +0 -1
- data/test/new_relic/data_container_tests.rb +11 -7
- data/test/new_relic/fake_collector.rb +23 -0
- data/test/new_relic/fake_instance_metadata_service.rb +45 -0
- data/test/new_relic/license_test.rb +2 -0
- data/test/new_relic/marshalling_test_cases.rb +89 -4
- data/test/new_relic/transaction_sample_test.rb +1 -0
- data/test/test_helper.rb +1 -0
- metadata +33 -6
- metadata.gz.sig +1 -2
- data/test/active_record_fixtures.rb +0 -79
- data/test/new_relic/rack/all_test.rb +0 -14
@@ -1,22 +1,46 @@
|
|
1
1
|
[
|
2
2
|
{
|
3
3
|
"filename": "docker-0.9.1.txt",
|
4
|
-
"
|
4
|
+
"containerId": "f37a7e4d17017e7bf774656b19ca4360c6cdc4951c86700a464101d0d9ce97ee"
|
5
5
|
},
|
6
6
|
{
|
7
7
|
"filename": "docker-1.0.0.txt",
|
8
|
-
"
|
8
|
+
"containerId": "3ccfa00432798ff38f85839de1e396f771b4acbe9f4ddea0a761c39b9790a782"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"filename": "docker-1.1.2-lxc-driver.txt",
|
12
|
+
"containerId": "cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159"
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"filename": "docker-1.1.2-native-driver-fs.txt",
|
16
|
+
"containerId": "2a4f870e24a3b52eb9fe7f3e02858c31855e213e568cfa6c76cb046ffa5b8a28"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"filename": "docker-1.1.2-native-driver-systemd.txt",
|
20
|
+
"containerId": "67f98c9e6188f9c1818672a15dbe46237b6ee7e77f834d40d41c5fb3c2f84a2f"
|
9
21
|
},
|
10
22
|
{
|
11
23
|
"filename": "docker-1.3.txt",
|
12
|
-
"
|
24
|
+
"containerId": "47cbd16b77c50cbf71401c069cd2189f0e659af17d5a2daca3bddf59d8a870b2"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"filename": "heroku.txt",
|
28
|
+
"containerId": null
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"filename": "ubuntu-14.04-no-container.txt",
|
32
|
+
"containerId": null
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"filename": "ubuntu-14.04-lxc-container.txt",
|
36
|
+
"containerId": null
|
13
37
|
},
|
14
38
|
{
|
15
|
-
"filename": "
|
16
|
-
"
|
39
|
+
"filename": "ubuntu-14.10-no-container.txt",
|
40
|
+
"containerId": null
|
17
41
|
},
|
18
42
|
{
|
19
43
|
"filename": "empty.txt",
|
20
|
-
"
|
44
|
+
"containerId": null
|
21
45
|
}
|
22
46
|
]
|
@@ -0,0 +1,10 @@
|
|
1
|
+
11:hugetlb:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
2
|
+
10:perf_event:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
3
|
+
9:blkio:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
4
|
+
8:freezer:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
5
|
+
7:name=systemd:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
6
|
+
6:devices:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
7
|
+
5:memory:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
8
|
+
4:cpuacct:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
9
|
+
3:cpu:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
10
|
+
2:cpuset:/lxc/cb8c113e5f3cf8332f5231f8154adc429ea910f7c29995372de4f571c55d3159
|
@@ -0,0 +1,10 @@
|
|
1
|
+
11:hugetlb:/
|
2
|
+
10:perf_event:/docker/2a4f870e24a3b52eb9fe7f3e02858c31855e213e568cfa6c76cb046ffa5b8a28
|
3
|
+
9:blkio:/docker/2a4f870e24a3b52eb9fe7f3e02858c31855e213e568cfa6c76cb046ffa5b8a28
|
4
|
+
8:freezer:/docker/2a4f870e24a3b52eb9fe7f3e02858c31855e213e568cfa6c76cb046ffa5b8a28
|
5
|
+
7:name=systemd:/
|
6
|
+
6:devices:/docker/2a4f870e24a3b52eb9fe7f3e02858c31855e213e568cfa6c76cb046ffa5b8a28
|
7
|
+
5:memory:/docker/2a4f870e24a3b52eb9fe7f3e02858c31855e213e568cfa6c76cb046ffa5b8a28
|
8
|
+
4:cpuacct:/docker/2a4f870e24a3b52eb9fe7f3e02858c31855e213e568cfa6c76cb046ffa5b8a28
|
9
|
+
3:cpu:/docker/2a4f870e24a3b52eb9fe7f3e02858c31855e213e568cfa6c76cb046ffa5b8a28
|
10
|
+
2:cpuset:/
|
data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.1.2-native-driver-systemd.txt
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
10:hugetlb:/
|
2
|
+
9:perf_event:/
|
3
|
+
8:blkio:/system.slice/docker-67f98c9e6188f9c1818672a15dbe46237b6ee7e77f834d40d41c5fb3c2f84a2f.scope
|
4
|
+
7:net_cls:/
|
5
|
+
6:freezer:/system.slice/docker-67f98c9e6188f9c1818672a15dbe46237b6ee7e77f834d40d41c5fb3c2f84a2f.scope
|
6
|
+
5:devices:/system.slice/docker-67f98c9e6188f9c1818672a15dbe46237b6ee7e77f834d40d41c5fb3c2f84a2f.scope
|
7
|
+
4:memory:/system.slice/docker-67f98c9e6188f9c1818672a15dbe46237b6ee7e77f834d40d41c5fb3c2f84a2f.scope
|
8
|
+
3:cpuacct,cpu:/system.slice/docker-67f98c9e6188f9c1818672a15dbe46237b6ee7e77f834d40d41c5fb3c2f84a2f.scope
|
9
|
+
2:cpuset:/
|
10
|
+
1:name=systemd:/system.slice/docker-67f98c9e6188f9c1818672a15dbe46237b6ee7e77f834d40d41c5fb3c2f84a2f.scope
|
@@ -0,0 +1 @@
|
|
1
|
+
1:hugetlb,perf_event,blkio,freezer,devices,memory,cpuacct,cpu,cpuset:/lxc/b6d196c1-50f2-4949-abdb-5d4909864487
|
File without changes
|
@@ -84,6 +84,7 @@ module Multiverse
|
|
84
84
|
GROUPS = {
|
85
85
|
"agent" => ["agent_only", "bare", "config_file_loading",
|
86
86
|
"deferred_instrumentation", "high_security"],
|
87
|
+
"api" => ["grape"],
|
87
88
|
"background" => ["delayed_job", "resque", "sidekiq"],
|
88
89
|
"database" => ["datamapper", "mongo", "sequel"],
|
89
90
|
"httpclients" => ["curb", "excon", "httpclient", "typhoeus", "net_http"],
|
@@ -199,6 +199,10 @@ module Multiverse
|
|
199
199
|
return unless is_rbx?
|
200
200
|
|
201
201
|
f.puts "gem 'rubysl', :platforms => [:rbx]" unless gemfile_text =~ /^\s*gem .rubysl./
|
202
|
+
# Compilation issues with rubysl-openssl 2.2.1, lock at 2.1.0 for now.
|
203
|
+
# https://github.com/rubysl/rubysl-openssl/issues/11
|
204
|
+
f.puts "gem 'rubysl-openssl', '2.1.0', :platforms => [:rbx]" unless gemfile_text =~ /^\s*gem .rubysl-openssl./
|
205
|
+
|
202
206
|
f.puts "gem 'json', :platforms => [:rbx]" unless gemfile_text =~ /^\s*gem .json./
|
203
207
|
f.puts "gem 'racc', :platforms => [:rbx]" unless gemfile_text =~ /^\s*gem .racc./
|
204
208
|
end
|
@@ -242,7 +246,7 @@ module Multiverse
|
|
242
246
|
end
|
243
247
|
|
244
248
|
def log_test_running_process
|
245
|
-
puts yellow("Starting tests in child PID #{Process.pid}\n")
|
249
|
+
puts yellow("Starting tests in child PID #{Process.pid} at #{Time.now}\n")
|
246
250
|
end
|
247
251
|
|
248
252
|
def should_serialize?
|
@@ -493,7 +497,7 @@ module Multiverse
|
|
493
497
|
end
|
494
498
|
|
495
499
|
def verbose?
|
496
|
-
ENV['VERBOSE']
|
500
|
+
ENV['VERBOSE'] == "1" || ENV['VERBOSE'] == "true"
|
497
501
|
end
|
498
502
|
end
|
499
503
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
db/schema.rb
|
@@ -1,17 +1,18 @@
|
|
1
|
-
boilerplate_gems = <<-
|
1
|
+
boilerplate_gems = <<-BOILERPLATE
|
2
2
|
gem 'rack'
|
3
|
+
gem 'rake'
|
3
4
|
if RUBY_PLATFORM == 'java'
|
4
|
-
gem
|
5
|
+
gem "activerecord-jdbcmysql-adapter"
|
5
6
|
else
|
6
|
-
gem '
|
7
|
+
gem 'mysql'
|
7
8
|
end
|
8
|
-
|
9
|
+
BOILERPLATE
|
9
10
|
|
10
11
|
if RUBY_VERSION >= '1.9.3'
|
11
12
|
# JRuby currently having problem with Rails 4.2 beta. Remove condition on GA.
|
12
13
|
if !defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby'
|
13
14
|
gemfile <<-RB
|
14
|
-
gem 'activerecord', '~> 4.2.0.
|
15
|
+
gem 'activerecord', '~> 4.2.0.rc1'
|
15
16
|
gem 'minitest', '~> 5.2.3'
|
16
17
|
#{boilerplate_gems}
|
17
18
|
RB
|
@@ -39,9 +40,26 @@ gemfile <<-RB
|
|
39
40
|
#{boilerplate_gems}
|
40
41
|
RB
|
41
42
|
|
42
|
-
|
43
|
+
# We pull in Rails on the older verions because ActiveRecord didn't have all
|
44
|
+
# the tasks we need for setup, and there are some TestUnit vs Minitest oddities
|
45
|
+
#
|
46
|
+
# JRuby testing with 1.7 on Rails 2.x has issues and was already excluded in
|
47
|
+
# test:env
|
48
|
+
if RUBY_VERSION <= '1.9.3' && (!defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby')
|
43
49
|
gemfile <<-RB
|
44
|
-
gem '
|
50
|
+
gem 'rails', '~> 2.3.18'
|
51
|
+
#{boilerplate_gems}
|
52
|
+
RB
|
53
|
+
|
54
|
+
gemfile <<-RB
|
55
|
+
gem "rails", "~> 2.2.3"
|
56
|
+
#{boilerplate_gems}
|
57
|
+
RB
|
58
|
+
end
|
59
|
+
|
60
|
+
if RUBY_VERSION < '1.9.2'
|
61
|
+
gemfile <<-RB
|
62
|
+
gem "rails", "~> 2.1.2"
|
45
63
|
#{boilerplate_gems}
|
46
64
|
RB
|
47
65
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.expand_path('config/database')
|
2
|
+
|
3
|
+
desc "Setup for ActiveRecord"
|
4
|
+
task :environment do
|
5
|
+
if defined?(DatabaseTasks)
|
6
|
+
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
|
7
|
+
ActiveRecord::Base.establish_connection DatabaseTasks.env.to_sym
|
8
|
+
end
|
9
|
+
end
|
data/test/{new_relic/agent/instrumentation → multiverse/suites/active_record}/active_record_test.rb
RENAMED
@@ -2,42 +2,35 @@
|
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
4
|
|
5
|
-
|
5
|
+
require 'multiverse_helpers'
|
6
|
+
require File.expand_path(File.join(__FILE__, "..", "app", "models", "models"))
|
6
7
|
|
7
|
-
|
8
|
-
require 'active_record_fixtures'
|
8
|
+
class ActiveRecordInstrumentationTest < Minitest::Test
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
super
|
13
|
-
NewRelic::Agent.manual_start
|
14
|
-
ActiveRecord::Base.establish_connection unless ActiveRecord::Base.connection.active?
|
15
|
-
ActiveRecordFixtures.setup
|
16
|
-
NewRelic::Agent.drop_buffered_data
|
17
|
-
end
|
10
|
+
include MultiverseHelpers
|
11
|
+
setup_and_teardown_agent
|
18
12
|
|
19
|
-
def
|
13
|
+
def after_setup
|
20
14
|
super
|
21
|
-
NewRelic::Agent
|
22
|
-
NewRelic::Agent.shutdown
|
15
|
+
NewRelic::Agent.drop_buffered_data
|
23
16
|
end
|
24
17
|
|
25
18
|
def test_metrics_for_create
|
26
19
|
in_web_transaction do
|
27
|
-
|
20
|
+
Order.create(:name => 'bob')
|
28
21
|
end
|
29
22
|
|
30
23
|
if active_record_major_version >= 3
|
31
24
|
assert_generic_rollup_metrics('insert')
|
32
25
|
else
|
33
|
-
assert_activerecord_metrics(
|
26
|
+
assert_activerecord_metrics(Order, 'create')
|
34
27
|
end
|
35
28
|
assert_remote_service_metrics
|
36
29
|
end
|
37
30
|
|
38
31
|
def test_metrics_for_create_via_association
|
39
32
|
in_web_transaction do
|
40
|
-
order =
|
33
|
+
order = Order.create(:name => 'bob')
|
41
34
|
order.shipments.create
|
42
35
|
order.shipments.to_a
|
43
36
|
end
|
@@ -49,34 +42,34 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
49
42
|
def test_metrics_for_find
|
50
43
|
in_web_transaction do
|
51
44
|
if active_record_major_version >= 4
|
52
|
-
|
45
|
+
Order.where(:name => 'foo').load
|
53
46
|
else
|
54
|
-
|
47
|
+
Order.find_all_by_name('foo')
|
55
48
|
end
|
56
49
|
end
|
57
50
|
|
58
|
-
assert_activerecord_metrics(
|
51
|
+
assert_activerecord_metrics(Order, 'find')
|
59
52
|
assert_remote_service_metrics
|
60
53
|
end
|
61
54
|
|
62
55
|
def test_metrics_for_find_by_id
|
63
56
|
in_web_transaction do
|
64
|
-
order =
|
65
|
-
|
57
|
+
order = Order.create(:name => 'kathy')
|
58
|
+
Order.find(order.id)
|
66
59
|
end
|
67
60
|
|
68
|
-
assert_activerecord_metrics(
|
61
|
+
assert_activerecord_metrics(Order, 'find')
|
69
62
|
assert_remote_service_metrics
|
70
63
|
end
|
71
64
|
|
72
65
|
def test_metrics_for_find_via_association
|
73
66
|
in_web_transaction do
|
74
|
-
order =
|
67
|
+
order = Order.create(:name => 'bob')
|
75
68
|
order.shipments.create
|
76
69
|
order.shipments.to_a
|
77
70
|
end
|
78
71
|
|
79
|
-
assert_activerecord_metrics(
|
72
|
+
assert_activerecord_metrics(Shipment, 'find')
|
80
73
|
assert_remote_service_metrics
|
81
74
|
end
|
82
75
|
|
@@ -84,23 +77,25 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
84
77
|
in_web_transaction do
|
85
78
|
case
|
86
79
|
when active_record_major_version >= 4
|
87
|
-
|
80
|
+
Order.all.load
|
88
81
|
when active_record_major_version >= 3
|
89
|
-
|
82
|
+
Order.all
|
90
83
|
else
|
91
|
-
|
84
|
+
Order.find(:all)
|
92
85
|
end
|
93
86
|
end
|
94
87
|
|
95
|
-
assert_activerecord_metrics(
|
88
|
+
assert_activerecord_metrics(Order, 'find')
|
96
89
|
assert_remote_service_metrics
|
97
90
|
end
|
98
91
|
|
99
92
|
def test_metrics_for_find_via_named_scope
|
100
|
-
|
101
|
-
|
93
|
+
major_version = active_record_major_version
|
94
|
+
minor_version = active_record_minor_version
|
95
|
+
Order.class_eval do
|
96
|
+
if major_version >= 4
|
102
97
|
scope :jeffs, lambda { where(:name => 'Jeff') }
|
103
|
-
elsif
|
98
|
+
elsif major_version == 3 && minor_version >= 1
|
104
99
|
scope :jeffs, :conditions => { :name => 'Jeff' }
|
105
100
|
else
|
106
101
|
named_scope :jeffs, :conditions => { :name => 'Jeff' }
|
@@ -109,33 +104,33 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
109
104
|
|
110
105
|
in_web_transaction do
|
111
106
|
if active_record_major_version >= 4
|
112
|
-
|
107
|
+
Order.jeffs.load
|
113
108
|
else
|
114
|
-
|
109
|
+
Order.jeffs.find(:all)
|
115
110
|
end
|
116
111
|
end
|
117
112
|
|
118
|
-
assert_activerecord_metrics(
|
113
|
+
assert_activerecord_metrics(Order, 'find')
|
119
114
|
assert_remote_service_metrics
|
120
115
|
end
|
121
116
|
|
122
117
|
def test_metrics_for_exists
|
123
118
|
in_web_transaction do
|
124
|
-
|
119
|
+
Order.exists?(["name=?", "jeff"])
|
125
120
|
end
|
126
121
|
|
127
122
|
if active_record_major_version == 3 && [0,1].include?(active_record_minor_version)
|
128
123
|
# Bugginess in Rails 3.0 and 3.1 doesn't let us get ActiveRecord/find
|
129
124
|
assert_generic_rollup_metrics('select')
|
130
125
|
else
|
131
|
-
assert_activerecord_metrics(
|
126
|
+
assert_activerecord_metrics(Order, 'find')
|
132
127
|
end
|
133
128
|
assert_remote_service_metrics
|
134
129
|
end
|
135
130
|
|
136
131
|
def test_metrics_for_update
|
137
132
|
in_web_transaction do
|
138
|
-
order =
|
133
|
+
order = Order.create(:name => "wendy")
|
139
134
|
order.name = 'walter'
|
140
135
|
order.save
|
141
136
|
end
|
@@ -143,29 +138,29 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
143
138
|
if active_record_major_version >= 3
|
144
139
|
assert_generic_rollup_metrics('update')
|
145
140
|
else
|
146
|
-
assert_activerecord_metrics(
|
141
|
+
assert_activerecord_metrics(Order, 'save')
|
147
142
|
end
|
148
143
|
assert_remote_service_metrics
|
149
144
|
end
|
150
145
|
|
151
146
|
def test_metrics_for_destroy
|
152
147
|
in_web_transaction do
|
153
|
-
order =
|
148
|
+
order = Order.create("name" => "burt")
|
154
149
|
order.destroy
|
155
150
|
end
|
156
151
|
|
157
152
|
if active_record_major_version >= 3
|
158
153
|
assert_generic_rollup_metrics('delete')
|
159
154
|
else
|
160
|
-
assert_activerecord_metrics(
|
155
|
+
assert_activerecord_metrics(Order, 'destroy')
|
161
156
|
end
|
162
157
|
assert_remote_service_metrics
|
163
158
|
end
|
164
159
|
|
165
160
|
def test_metrics_for_direct_sql_select
|
166
161
|
in_web_transaction do
|
167
|
-
conn =
|
168
|
-
conn.select_rows("SELECT * FROM #{
|
162
|
+
conn = Order.connection
|
163
|
+
conn.select_rows("SELECT * FROM #{Order.table_name}")
|
169
164
|
end
|
170
165
|
|
171
166
|
assert_generic_rollup_metrics('select')
|
@@ -174,7 +169,7 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
174
169
|
|
175
170
|
def test_metrics_for_direct_sql_other
|
176
171
|
in_web_transaction do
|
177
|
-
conn =
|
172
|
+
conn = Order.connection
|
178
173
|
conn.execute("begin")
|
179
174
|
conn.execute("commit")
|
180
175
|
end
|
@@ -186,7 +181,7 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
186
181
|
def test_metrics_for_direct_sql_show
|
187
182
|
if supports_show_tables?
|
188
183
|
in_web_transaction do
|
189
|
-
conn =
|
184
|
+
conn = Order.connection
|
190
185
|
conn.execute("show tables")
|
191
186
|
end
|
192
187
|
|
@@ -197,14 +192,14 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
197
192
|
|
198
193
|
def test_still_records_metrics_in_error_cases
|
199
194
|
# have the AR select throw an error
|
200
|
-
|
195
|
+
Order.connection.stubs(:log_info).with do |sql, *|
|
201
196
|
raise "Error" if sql =~ /select/
|
202
197
|
true
|
203
198
|
end
|
204
199
|
|
205
200
|
in_web_transaction do
|
206
201
|
begin
|
207
|
-
|
202
|
+
Order.connection.select_rows "select * from #{Order.table_name}"
|
208
203
|
rescue RuntimeError => e
|
209
204
|
# catch only the error we raise above
|
210
205
|
raise unless e.message == 'Error'
|
@@ -217,7 +212,7 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
217
212
|
|
218
213
|
def test_passes_through_errors
|
219
214
|
begin
|
220
|
-
|
215
|
+
Order.transaction do
|
221
216
|
raise ActiveRecord::ActiveRecordError.new('preserve-me!')
|
222
217
|
end
|
223
218
|
rescue ActiveRecord::ActiveRecordError => e
|
@@ -228,7 +223,7 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
228
223
|
def test_no_metrics_recorded_with_disable_all_tracing
|
229
224
|
NewRelic::Agent.disable_all_tracing do
|
230
225
|
in_web_transaction('bogosity') do
|
231
|
-
|
226
|
+
Order.first
|
232
227
|
end
|
233
228
|
end
|
234
229
|
assert_nil NewRelic::Agent.instance.transaction_sampler.last_sample
|
@@ -237,12 +232,12 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
237
232
|
|
238
233
|
def test_records_transaction_trace_nodes
|
239
234
|
in_web_transaction do
|
240
|
-
|
235
|
+
Order.first
|
241
236
|
end
|
242
237
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
243
|
-
segment = find_segment_with_name(sample, 'ActiveRecord/
|
238
|
+
segment = find_segment_with_name(sample, 'ActiveRecord/Order/find')
|
244
239
|
|
245
|
-
assert_equal('ActiveRecord/
|
240
|
+
assert_equal('ActiveRecord/Order/find', segment.metric_name)
|
246
241
|
|
247
242
|
sql = segment.params[:sql]
|
248
243
|
assert_match(/^SELECT /, sql)
|
@@ -255,11 +250,11 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
255
250
|
def test_gathers_explain_plans
|
256
251
|
with_config(:'transaction_tracer.explain_threshold' => -0.1) do
|
257
252
|
in_web_transaction do
|
258
|
-
|
253
|
+
Order.first
|
259
254
|
end
|
260
255
|
|
261
256
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
262
|
-
sql_segment = find_segment_with_name(sample, 'ActiveRecord/
|
257
|
+
sql_segment = find_segment_with_name(sample, 'ActiveRecord/Order/find')
|
263
258
|
|
264
259
|
assert_match(/^SELECT /, sql_segment.params[:sql])
|
265
260
|
|
@@ -275,7 +270,7 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
275
270
|
|
276
271
|
def test_records_metrics_on_background_transaction
|
277
272
|
in_transaction('back it up') do
|
278
|
-
|
273
|
+
Order.create(:name => 'bob')
|
279
274
|
end
|
280
275
|
|
281
276
|
assert_metrics_recorded(['Datastore/allOther'])
|
@@ -284,33 +279,33 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
284
279
|
|
285
280
|
def test_remote_service_metric_respects_dynamic_connection_config
|
286
281
|
if supports_remote_service_metrics?
|
287
|
-
q = "SELECT * FROM #{
|
288
|
-
|
282
|
+
q = "SELECT * FROM #{Shipment.table_name} LIMIT 1"
|
283
|
+
Shipment.connection.execute(q)
|
289
284
|
assert_remote_service_metrics
|
290
285
|
|
291
|
-
config =
|
286
|
+
config = Shipment.connection.instance_eval { @config }
|
292
287
|
config[:host] = '127.0.0.1'
|
293
|
-
|
288
|
+
Shipment.establish_connection(config)
|
294
289
|
|
295
|
-
|
290
|
+
Shipment.connection.execute(q)
|
296
291
|
assert_remote_service_metrics('127.0.0.1')
|
297
292
|
|
298
293
|
config[:host] = 'localhost'
|
299
|
-
|
294
|
+
Shipment.establish_connection(config)
|
300
295
|
end
|
301
296
|
end
|
302
297
|
|
303
298
|
def test_cached_calls_are_not_recorded_with_find
|
304
299
|
in_web_transaction do
|
305
|
-
order =
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
300
|
+
order = Order.create(:name => 'Oberon')
|
301
|
+
Order.connection.cache do
|
302
|
+
Order.find(order.id)
|
303
|
+
Order.find(order.id)
|
304
|
+
Order.find(order.id)
|
310
305
|
end
|
311
306
|
end
|
312
307
|
|
313
|
-
assert_activerecord_metrics(
|
308
|
+
assert_activerecord_metrics(Order, 'find', :call_count => 1)
|
314
309
|
assert_remote_service_metrics
|
315
310
|
end
|
316
311
|
|
@@ -318,17 +313,17 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
318
313
|
# If this is the first create, ActiveRecord needs to warm up,
|
319
314
|
# send some SQL SELECTS, etc.
|
320
315
|
in_web_transaction do
|
321
|
-
|
316
|
+
Order.create(:name => 'Oberon')
|
322
317
|
end
|
323
318
|
NewRelic::Agent.drop_buffered_data
|
324
319
|
|
325
320
|
# the actual test is here
|
326
|
-
query = "SELECT * FROM #{
|
321
|
+
query = "SELECT * FROM #{Order.table_name} WHERE name = 'Oberon'"
|
327
322
|
in_web_transaction do
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
323
|
+
Order.connection.cache do
|
324
|
+
Order.connection.select_all(query)
|
325
|
+
Order.connection.select_all(query)
|
326
|
+
Order.connection.select_all(query)
|
332
327
|
end
|
333
328
|
end
|
334
329
|
|
@@ -337,21 +332,24 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
337
332
|
)
|
338
333
|
end
|
339
334
|
|
340
|
-
|
335
|
+
def test_with_database_metric_name
|
336
|
+
in_web_transaction do
|
337
|
+
Order.create(:name => "eely")
|
338
|
+
NewRelic::Agent.with_database_metric_name('Eel', 'squirm') do
|
339
|
+
Order.connection.select_rows("SELECT id FROM #{Order.table_name}")
|
340
|
+
end
|
341
|
+
end
|
341
342
|
|
342
|
-
|
343
|
-
|
343
|
+
assert_metrics_recorded(
|
344
|
+
{ 'ActiveRecord/Eel/squirm' => {:call_count => 1}}
|
345
|
+
)
|
344
346
|
end
|
345
347
|
|
348
|
+
## helpers
|
349
|
+
|
346
350
|
def adapter
|
347
|
-
adapter_string =
|
348
|
-
|
349
|
-
when /postgres/i then :postgres
|
350
|
-
when /mysql/i then :mysql
|
351
|
-
when /sqlite/i then :sqlite3
|
352
|
-
else
|
353
|
-
adapter_string.downcase.to_sym
|
354
|
-
end
|
351
|
+
adapter_string = Order.configurations[RAILS_ENV]['adapter']
|
352
|
+
adapter_string.downcase.to_sym
|
355
353
|
end
|
356
354
|
|
357
355
|
def supports_show_tables?
|
@@ -415,7 +413,3 @@ class NewRelic::Agent::Instrumentation::NewActiveRecordInstrumentationTest < Min
|
|
415
413
|
end
|
416
414
|
end
|
417
415
|
end
|
418
|
-
|
419
|
-
else
|
420
|
-
puts "Skipping tests in #{__FILE__} because Rails is unavailable"
|
421
|
-
end
|