newrelic_rpm 3.6.8.168 → 3.6.9.171
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +1 -0
- data/.yardopts +17 -0
- data/CHANGELOG +48 -0
- data/README.md +8 -6
- data/lib/new_relic/agent.rb +65 -17
- data/lib/new_relic/agent/agent.rb +42 -113
- data/lib/new_relic/agent/browser_monitoring.rb +9 -1
- data/lib/new_relic/agent/configuration/default_source.rb +12 -0
- data/lib/new_relic/agent/error_collector.rb +13 -6
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +5 -5
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +15 -0
- data/lib/new_relic/agent/instrumentation/curb.rb +2 -2
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rack.rb +2 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +9 -3
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +5 -0
- data/lib/new_relic/agent/method_tracer.rb +45 -27
- data/lib/new_relic/agent/new_relic_service.rb +14 -6
- data/lib/new_relic/agent/pipe_service.rb +1 -1
- data/lib/new_relic/agent/request_sampler.rb +10 -7
- data/lib/new_relic/agent/rules_engine.rb +5 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
- data/lib/new_relic/agent/sql_sampler.rb +4 -2
- data/lib/new_relic/agent/stats_engine.rb +3 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +17 -7
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +5 -7
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +2 -0
- data/lib/new_relic/agent/supported_versions.rb +247 -0
- data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
- data/lib/new_relic/agent/threading/thread_profile.rb +2 -1
- data/lib/new_relic/agent/transaction.rb +7 -6
- data/lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb +11 -5
- data/lib/new_relic/agent/transaction/force_persist_sample_buffer.rb +3 -3
- data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +3 -3
- data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +23 -4
- data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +4 -4
- data/lib/new_relic/agent/transaction_sampler.rb +14 -18
- data/lib/new_relic/agent/worker_loop.rb +1 -0
- data/lib/new_relic/control.rb +1 -0
- data/lib/new_relic/control/instance_methods.rb +0 -1
- data/lib/new_relic/helper.rb +1 -2
- data/lib/new_relic/language_support.rb +12 -2
- data/lib/new_relic/local_environment.rb +12 -11
- data/lib/new_relic/rack.rb +9 -0
- data/lib/new_relic/rack/agent_hooks.rb +6 -0
- data/lib/new_relic/rack/browser_monitoring.rb +9 -2
- data/lib/new_relic/rack/developer_mode.rb +15 -1
- data/lib/new_relic/rack/error_collector.rb +7 -0
- data/lib/new_relic/recipes.rb +2 -0
- data/lib/new_relic/transaction_sample.rb +39 -48
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/install.rake +44 -2
- data/lib/tasks/versions.html.erb +31 -0
- data/lib/tasks/versions.rake +52 -0
- data/lib/tasks/versions.txt.erb +14 -0
- data/newrelic_rpm.gemspec +4 -2
- data/test/agent_helper.rb +21 -1
- data/test/environments/lib/environments/runner.rb +19 -5
- data/test/environments/norails/Gemfile +4 -1
- data/test/environments/rails21/Gemfile +4 -6
- data/test/environments/rails21/Rakefile +4 -0
- data/test/environments/rails21/config/database.yml +2 -7
- data/test/environments/rails22/Gemfile +6 -13
- data/test/environments/rails22/Rakefile +4 -0
- data/test/environments/rails22/config/database.yml +2 -7
- data/test/environments/rails22/config/environment.rb +1 -1
- data/test/environments/rails23/Gemfile +3 -4
- data/test/environments/rails23/Rakefile +4 -0
- data/test/environments/rails23/config/database.yml +2 -7
- data/test/environments/rails30/Gemfile +2 -4
- data/test/environments/rails30/Rakefile +2 -0
- data/test/environments/rails30/config/database.yml +2 -7
- data/test/environments/rails31/Gemfile +2 -4
- data/test/environments/rails31/Rakefile +2 -0
- data/test/environments/rails31/config/database.yml +2 -7
- data/test/environments/rails32/Gemfile +2 -5
- data/test/environments/rails32/Rakefile +2 -0
- data/test/environments/rails32/config/database.yml +1 -1
- data/test/environments/rails40/Gemfile +7 -4
- data/test/environments/rails40/Rakefile +2 -0
- data/test/environments/rails40/config/database.yml +2 -7
- data/test/helpers/runtime_detection.rb +17 -0
- data/test/multiverse/lib/multiverse/suite.rb +20 -4
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +1 -1
- data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +32 -7
- data/test/multiverse/suites/agent_only/xray_sessions_test.rb +1 -0
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +4 -3
- data/test/multiverse/suites/curb/curb_test.rb +8 -0
- data/test/multiverse/suites/excon/excon_test.rb +8 -0
- data/test/multiverse/suites/httpclient/httpclient_test.rb +8 -0
- data/test/multiverse/suites/net_http/net_http_test.rb +8 -0
- data/test/multiverse/suites/padrino/Envfile +3 -2
- data/test/multiverse/suites/rails/gc_instrumentation_test.rb +17 -8
- data/test/multiverse/suites/resque/Envfile +3 -3
- data/test/multiverse/suites/resque/instrumentation_test.rb +47 -5
- data/test/multiverse/suites/sequel/Envfile +0 -3
- data/test/multiverse/suites/sequel/database.rb +53 -0
- data/test/{new_relic/agent/instrumentation/sequel_test.rb → multiverse/suites/sequel/sequel_instrumentation_test.rb} +12 -53
- data/test/multiverse/suites/sequel/{sequel_test.rb → sequel_safety_test.rb} +2 -17
- data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +50 -5
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +15 -2
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +8 -0
- data/test/new_relic/agent/agent/connect_test.rb +3 -2
- data/test/new_relic/agent/agent_test.rb +89 -82
- data/test/new_relic/agent/browser_monitoring_test.rb +44 -1
- data/test/new_relic/agent/error_collector_test.rb +17 -20
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +13 -10
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +16 -1
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
- data/test/new_relic/agent/new_relic_service_test.rb +78 -9
- data/test/new_relic/agent/pipe_channel_manager_test.rb +7 -9
- data/test/new_relic/agent/pipe_service_test.rb +4 -4
- data/test/new_relic/agent/request_sampler_test.rb +2 -2
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +15 -35
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +15 -7
- data/test/new_relic/agent/stats_engine_test.rb +4 -3
- data/test/new_relic/agent/threading/backtrace_service_test.rb +2 -0
- data/test/new_relic/agent/threading/thread_profile_test.rb +19 -0
- data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +4 -4
- data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +1 -1
- data/test/new_relic/agent/transaction_sampler_test.rb +60 -45
- data/test/new_relic/fake_collector.rb +37 -2
- data/test/new_relic/http_client_test_cases.rb +26 -1
- data/test/new_relic/language_support_test.rb +12 -31
- data/test/new_relic/local_environment_test.rb +6 -2
- data/test/new_relic/multiverse_helpers.rb +2 -5
- data/test/new_relic/transaction_sample_test.rb +57 -36
- data/test/performance/suites/config.rb +76 -0
- data/test/rum/no_html_and_no_header.result.html +3 -0
- data/test/rum/no_html_and_no_header.source.html +3 -0
- data/test/script/ci.sh +0 -2
- data/test/test_helper.rb +5 -0
- metadata +43 -26
- metadata.gz.sig +0 -0
@@ -188,6 +188,14 @@ class CurbTest < MiniTest::Unit::TestCase
|
|
188
188
|
Curl::Easy.http_post( default_url, '' )
|
189
189
|
end
|
190
190
|
|
191
|
+
def put_response
|
192
|
+
Curl::Easy.http_put( default_url, '' )
|
193
|
+
end
|
194
|
+
|
195
|
+
def delete_response
|
196
|
+
Curl::Easy.http_delete( default_url )
|
197
|
+
end
|
198
|
+
|
191
199
|
def body(res)
|
192
200
|
res.body_str
|
193
201
|
end
|
@@ -36,6 +36,14 @@ class ExconTest < MiniTest::Unit::TestCase
|
|
36
36
|
Excon.post(default_url, :body => "")
|
37
37
|
end
|
38
38
|
|
39
|
+
def put_response
|
40
|
+
Excon.put(default_url, :body => "")
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_response
|
44
|
+
Excon.delete(default_url)
|
45
|
+
end
|
46
|
+
|
39
47
|
def request_instance
|
40
48
|
NewRelic::Agent::HTTPClients::ExconHTTPRequest.new({:headers => ""})
|
41
49
|
end
|
@@ -28,6 +28,14 @@ class HTTPClientTest < MiniTest::Unit::TestCase
|
|
28
28
|
HTTPClient.post(default_url, :body => "")
|
29
29
|
end
|
30
30
|
|
31
|
+
def put_response
|
32
|
+
HTTPClient.put(default_url, :body => "")
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_response
|
36
|
+
HTTPClient.delete(default_url, :body => "")
|
37
|
+
end
|
38
|
+
|
31
39
|
def request_instance
|
32
40
|
httpclient_req = HTTP::Message.new_request(:get, 'http://newrelic.com')
|
33
41
|
NewRelic::Agent::HTTPClients::HTTPClientRequest.new(httpclient_req)
|
@@ -50,6 +50,14 @@ class NetHttpTest < MiniTest::Unit::TestCase
|
|
50
50
|
start(default_uri) { |http| http.post(default_uri.path, "") }
|
51
51
|
end
|
52
52
|
|
53
|
+
def put_response
|
54
|
+
start(default_uri) { |http| http.put(default_uri.path, "") }
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete_response
|
58
|
+
start(default_uri) { |http| http.delete(default_uri.path) }
|
59
|
+
end
|
60
|
+
|
53
61
|
def create_http(uri)
|
54
62
|
http = Net::HTTP.new(uri.host, uri.port)
|
55
63
|
if use_ssl?
|
@@ -1,5 +1,6 @@
|
|
1
|
-
suite_condition("Sinatra not compatible with 1.8.6") do
|
2
|
-
|
1
|
+
suite_condition("Sinatra not compatible with 1.8.6 or Rubinius") do
|
2
|
+
is_rbx = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
3
|
+
RUBY_VERSION != '1.8.6' && !is_rbx # https://github.com/rubinius/rubinius/issues/2671
|
3
4
|
end
|
4
5
|
|
5
6
|
gemfile <<-RB
|
@@ -5,18 +5,27 @@
|
|
5
5
|
require './app'
|
6
6
|
require 'multiverse_helpers'
|
7
7
|
|
8
|
-
# GC instrumentation only works with REE or 1.9.
|
8
|
+
# GC instrumentation only works with REE or MRI >= 1.9.2
|
9
9
|
if (defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise/) ||
|
10
|
-
RUBY_VERSION >= '1.9.2'
|
10
|
+
(RUBY_VERSION >= '1.9.2' && !NewRelic::LanguageSupport.using_engine?('jruby'))
|
11
11
|
|
12
12
|
class GcController < ApplicationController
|
13
13
|
include Rails.application.routes.url_helpers
|
14
14
|
def gc_action
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
begin
|
16
|
+
profiler = NewRelic::Agent::StatsEngine::GCProfiler.init
|
17
|
+
gc_count = profiler.call_count
|
18
|
+
|
19
|
+
Timeout.timeout(5) do
|
20
|
+
until profiler.call_count > gc_count
|
21
|
+
long_string = "01234567" * 100_000
|
22
|
+
long_string = nil
|
23
|
+
another_long_string = "01234567" * 100_000
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue Timeout::Error
|
27
|
+
puts "Timed out waiting for GC..."
|
28
|
+
end
|
20
29
|
|
21
30
|
render :text => 'ha'
|
22
31
|
end
|
@@ -52,7 +61,7 @@ class GCRailsInstrumentationTest < ActionController::TestCase
|
|
52
61
|
|
53
62
|
def assert_in_range(duration, gc_time)
|
54
63
|
assert gc_time > 0.0, "GC Time wasn't recorded!"
|
55
|
-
assert gc_time < duration, "GC Time can't be more than elapsed!"
|
64
|
+
assert gc_time < duration, "GC Time #{gc_time} can't be more than elapsed #{duration}!"
|
56
65
|
end
|
57
66
|
|
58
67
|
def get_call_time(name, scope=nil)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
suite_condition("Resque tests not compatible with 1.8.6
|
2
|
-
RUBY_VERSION != '1.8.6'
|
1
|
+
suite_condition("Resque tests not compatible with 1.8.6") do
|
2
|
+
RUBY_VERSION != '1.8.6'
|
3
3
|
end
|
4
4
|
|
5
5
|
gemfile <<-RB
|
@@ -9,7 +9,7 @@ gemfile <<-RB
|
|
9
9
|
RB
|
10
10
|
|
11
11
|
gemfile <<-RB
|
12
|
-
gem 'resque', '~>1.
|
12
|
+
gem 'resque', '~>1.25.1'
|
13
13
|
gem 'json'
|
14
14
|
gem 'rake'
|
15
15
|
RB
|
@@ -9,6 +9,7 @@ require 'logger'
|
|
9
9
|
require 'newrelic_rpm'
|
10
10
|
require 'fake_collector'
|
11
11
|
require 'multiverse_helpers'
|
12
|
+
require File.join(File.dirname(__FILE__), "..", "..", "..", "agent_helper")
|
12
13
|
|
13
14
|
class ResqueTest < MiniTest::Unit::TestCase
|
14
15
|
include MultiverseHelpers
|
@@ -27,13 +28,14 @@ class ResqueTest < MiniTest::Unit::TestCase
|
|
27
28
|
@count
|
28
29
|
end
|
29
30
|
|
30
|
-
def self.perform(sleep_duration=0)
|
31
|
+
def self.perform(name, sleep_duration=0)
|
31
32
|
sleep sleep_duration
|
32
33
|
@count += 1
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
37
|
JOB_COUNT = 5
|
38
|
+
TRANSACTION_NAME = 'OtherTransaction/ResqueJob/ResqueTest::JobForTesting/perform'
|
37
39
|
|
38
40
|
def run_jobs
|
39
41
|
JobForTesting.reset_counter
|
@@ -43,8 +45,10 @@ class ResqueTest < MiniTest::Unit::TestCase
|
|
43
45
|
# will be done in our upcoming end-to-end testing suites
|
44
46
|
Resque.inline = true
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
49
|
+
JOB_COUNT.times do |i|
|
50
|
+
Resque.enqueue(JobForTesting, "testing")
|
51
|
+
end
|
48
52
|
end
|
49
53
|
|
50
54
|
NewRelic::Agent.instance.send(:transmit_data)
|
@@ -66,16 +70,54 @@ class ResqueTest < MiniTest::Unit::TestCase
|
|
66
70
|
assert NewRelic::Agent.instance.started?
|
67
71
|
end
|
68
72
|
|
69
|
-
|
73
|
+
def test_doesnt_capture_args_by_default
|
74
|
+
run_jobs
|
75
|
+
assert_no_params_on_jobs
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_isnt_influenced_by_global_capture_params
|
79
|
+
with_config(:capture_params => true) do
|
80
|
+
run_jobs
|
81
|
+
end
|
82
|
+
assert_no_params_on_jobs
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_agent_posts_captured_args_to_job
|
86
|
+
with_config(:'resque.capture_params' => true) do
|
87
|
+
run_jobs
|
88
|
+
end
|
89
|
+
|
90
|
+
transaction_samples = $collector.calls_for('transaction_sample_data')
|
91
|
+
assert_false transaction_samples.empty?
|
92
|
+
|
93
|
+
transaction_samples.each do |post|
|
94
|
+
post.samples.each do |sample|
|
95
|
+
assert_equal sample.metric_name, TRANSACTION_NAME, "Huh, that transaction shouldn't be in there!"
|
96
|
+
assert_equal sample.tree.custom_params["job_arguments"], ["testing"]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
70
100
|
|
71
101
|
def assert_metric_and_call_count(name, expected_call_count)
|
72
102
|
metric_data = $collector.calls_for('metric_data')
|
73
103
|
assert_equal(1, metric_data.size, "expected exactly one metric_data post from agent")
|
74
104
|
|
75
|
-
metric = metric_data.first
|
105
|
+
metric = metric_data.first.metrics.find { |m| m[0]['name'] == name }
|
76
106
|
assert(metric, "could not find metric named #{name}")
|
77
107
|
|
78
108
|
call_count = metric[1][0]
|
79
109
|
assert_equal(expected_call_count, call_count)
|
80
110
|
end
|
111
|
+
|
112
|
+
def assert_no_params_on_jobs
|
113
|
+
transaction_samples = $collector.calls_for('transaction_sample_data')
|
114
|
+
assert_false transaction_samples.empty?
|
115
|
+
|
116
|
+
transaction_samples.each do |post|
|
117
|
+
post.samples.each do |sample|
|
118
|
+
assert_equal sample.metric_name, TRANSACTION_NAME, "Huh, that transaction shouldn't be in there!"
|
119
|
+
assert_nil sample.tree.custom_params["job_arguments"]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
81
123
|
end
|
@@ -31,12 +31,9 @@ gemfile <<-RB
|
|
31
31
|
gem 'sequel', '3.47.0'
|
32
32
|
RB
|
33
33
|
|
34
|
-
|
35
34
|
gemfile <<-RB
|
36
35
|
gem 'newrelic_rpm', :require => false, :path => File.expand_path('../../../../')
|
37
36
|
gem 'jdbc-sqlite3', '3.7.2', :platform => :jruby
|
38
37
|
gem 'sqlite3', '1.3.7', :platform => :ruby
|
39
38
|
gem 'sequel', '4.0.0'
|
40
39
|
RB
|
41
|
-
|
42
|
-
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require 'sequel'
|
6
|
+
|
7
|
+
# This file is intended to define the database connection and schema for all of
|
8
|
+
# the Sequel multiverse tests.
|
9
|
+
#
|
10
|
+
# DO NOT require newrelic_rpm here. Some of the tests rely on the timing of
|
11
|
+
# when New Relic gets pulled in.
|
12
|
+
if !defined?(DB)
|
13
|
+
def jruby?
|
14
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Use an in-memory SQLite database
|
18
|
+
if (jruby?)
|
19
|
+
DB = Sequel.connect('jdbc:sqlite::memory:')
|
20
|
+
else
|
21
|
+
DB = Sequel.sqlite
|
22
|
+
end
|
23
|
+
|
24
|
+
# Create tables and model classes for testing
|
25
|
+
DB.create_table( :authors ) do
|
26
|
+
primary_key :id
|
27
|
+
string :name
|
28
|
+
string :login
|
29
|
+
end
|
30
|
+
class Author < Sequel::Model; end
|
31
|
+
|
32
|
+
DB.create_table( :posts ) do
|
33
|
+
primary_key :id
|
34
|
+
string :title
|
35
|
+
string :content
|
36
|
+
time :created_at
|
37
|
+
end
|
38
|
+
class Post < Sequel::Model; end
|
39
|
+
|
40
|
+
DB.create_table( :users ) do
|
41
|
+
primary_key :uid
|
42
|
+
string :login
|
43
|
+
string :firstname
|
44
|
+
string :lastname
|
45
|
+
end
|
46
|
+
class User < Sequel::Model; end
|
47
|
+
|
48
|
+
# Version 4.0 of Sequel moved update_except off to a plugin
|
49
|
+
# So we can test that we still instrument it, it's got to be included
|
50
|
+
if defined?(Sequel::MAJOR) && Sequel::MAJOR >= 4
|
51
|
+
Sequel::Model.plugin :blacklist_security
|
52
|
+
end
|
53
|
+
end
|
@@ -2,58 +2,22 @@
|
|
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 File.join(File.dirname(__FILE__), 'database.rb')
|
6
6
|
|
7
|
-
|
7
|
+
if Sequel.const_defined?( :MAJOR ) &&
|
8
|
+
( Sequel::MAJOR > 3 ||
|
9
|
+
Sequel::MAJOR == 3 && Sequel::MINOR >= 37 )
|
8
10
|
|
9
|
-
require
|
11
|
+
require 'newrelic_rpm'
|
12
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
|
10
13
|
|
11
|
-
class NewRelic::Agent::Instrumentation::SequelInstrumentationTest <
|
12
|
-
require 'active_record_fixtures'
|
13
|
-
include NewRelic::Agent::Instrumentation::ControllerInstrumentation,
|
14
|
-
TransactionSampleTestHelper
|
15
|
-
|
16
|
-
def self.jruby?
|
17
|
-
NewRelic::LanguageSupport.using_engine?('jruby')
|
18
|
-
end
|
19
|
-
|
20
|
-
def jruby?
|
21
|
-
self.class.jruby?
|
22
|
-
end
|
23
|
-
|
24
|
-
# Use an in-memory SQLite database
|
25
|
-
if (jruby?)
|
26
|
-
DB = Sequel.connect('jdbc:sqlite::memory:')
|
27
|
-
else
|
28
|
-
DB = Sequel.sqlite
|
29
|
-
end
|
30
|
-
DB.extension :newrelic_instrumentation
|
31
|
-
|
32
|
-
# Create tables and model classes for testing
|
33
|
-
DB.create_table( :authors ) do
|
34
|
-
primary_key :id
|
35
|
-
string :name
|
36
|
-
string :login
|
37
|
-
end
|
38
|
-
class Author < Sequel::Model; end
|
39
|
-
|
40
|
-
DB.create_table( :posts ) do
|
41
|
-
primary_key :id
|
42
|
-
string :title
|
43
|
-
string :content
|
44
|
-
time :created_at
|
45
|
-
end
|
46
|
-
class Post < Sequel::Model; end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
#
|
51
|
-
# Setup/teardown
|
52
|
-
#
|
14
|
+
class NewRelic::Agent::Instrumentation::SequelInstrumentationTest < MiniTest::Unit::TestCase
|
53
15
|
|
54
16
|
def setup
|
55
17
|
super
|
56
18
|
|
19
|
+
DB.extension :newrelic_instrumentation
|
20
|
+
|
57
21
|
NewRelic::Agent.manual_start
|
58
22
|
NewRelic::Agent.instance.transaction_sampler.reset!
|
59
23
|
NewRelic::Agent.instance.stats_engine.clear_stats
|
@@ -65,11 +29,6 @@ class NewRelic::Agent::Instrumentation::SequelInstrumentationTest < Test::Unit::
|
|
65
29
|
NewRelic::Agent.shutdown
|
66
30
|
end
|
67
31
|
|
68
|
-
|
69
|
-
#
|
70
|
-
# Tests
|
71
|
-
#
|
72
|
-
|
73
32
|
def test_sequel_database_instrumentation_is_loaded
|
74
33
|
assert DB.respond_to?( :primary_metric_for )
|
75
34
|
end
|
@@ -144,7 +103,7 @@ class NewRelic::Agent::Instrumentation::SequelInstrumentationTest < Test::Unit::
|
|
144
103
|
def test_model_update_except_method_generates_metrics
|
145
104
|
in_web_transaction do
|
146
105
|
post = Post.create( :title => 'All The Things', :content => 'A story.' )
|
147
|
-
post.update_except( {:title => 'A Bit More of the Things'}
|
106
|
+
post.update_except( {:title => 'A Bit More of the Things'} )
|
148
107
|
end
|
149
108
|
|
150
109
|
assert_remote_service_metrics
|
@@ -303,7 +262,7 @@ class NewRelic::Agent::Instrumentation::SequelInstrumentationTest < Test::Unit::
|
|
303
262
|
yield
|
304
263
|
end
|
305
264
|
|
306
|
-
sample = transaction_samples.first.prepare_to_send(
|
265
|
+
sample = transaction_samples.first.prepare_to_send!(
|
307
266
|
:explain_sql=>options[:explain_sql] || -0.01, # Force to take explain, even if duration's reported as 0.0
|
308
267
|
:record_sql=>options[:record_sql])
|
309
268
|
segment = last_segment( sample )
|
@@ -320,5 +279,5 @@ class NewRelic::Agent::Instrumentation::SequelInstrumentationTest < Test::Unit::
|
|
320
279
|
end
|
321
280
|
|
322
281
|
else
|
323
|
-
puts "Skipping tests in #{__FILE__} because
|
282
|
+
puts "Skipping tests in #{__FILE__} because unsupported Sequel version"
|
324
283
|
end
|
@@ -5,24 +5,9 @@
|
|
5
5
|
# https://newrelic.atlassian.net/browse/RUBY-1123
|
6
6
|
# https://support.newrelic.com/tickets/42515
|
7
7
|
|
8
|
-
require '
|
9
|
-
require 'test/unit'
|
8
|
+
require File.join(File.dirname(__FILE__), 'database.rb')
|
10
9
|
|
11
|
-
|
12
|
-
DB = Sequel.connect('jdbc:sqlite::memory:')
|
13
|
-
else
|
14
|
-
DB = Sequel.sqlite
|
15
|
-
end
|
16
|
-
|
17
|
-
DB.create_table( :users ) do
|
18
|
-
primary_key :uid
|
19
|
-
string :login
|
20
|
-
string :firstname
|
21
|
-
string :lastname
|
22
|
-
end
|
23
|
-
class User < Sequel::Model; end
|
24
|
-
|
25
|
-
class SequelTest < MiniTest::Unit::TestCase
|
10
|
+
class SequelSafetyTest < MiniTest::Unit::TestCase
|
26
11
|
|
27
12
|
def test_it_doesnt_blow_up
|
28
13
|
require 'newrelic_rpm'
|
@@ -10,9 +10,11 @@ require 'test/unit'
|
|
10
10
|
require 'newrelic_rpm'
|
11
11
|
require 'fake_collector'
|
12
12
|
require 'multiverse_helpers'
|
13
|
+
require File.join(File.dirname(__FILE__), "..", "..", "..", "agent_helper")
|
13
14
|
|
14
15
|
class SidekiqTest < MiniTest::Unit::TestCase
|
15
16
|
JOB_COUNT = 5
|
17
|
+
TRANSACTION_NAME = 'OtherTransaction/SidekiqJob/SidekiqTest::TestWorker/perform'
|
16
18
|
|
17
19
|
include MultiverseHelpers
|
18
20
|
|
@@ -50,9 +52,11 @@ class SidekiqTest < MiniTest::Unit::TestCase
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def run_jobs
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
56
|
+
TestWorker.reset
|
57
|
+
JOB_COUNT.times do |i|
|
58
|
+
TestWorker.perform_async('jobs_completed', i + 1)
|
59
|
+
end
|
56
60
|
end
|
57
61
|
|
58
62
|
NewRelic::Agent.instance.send(:transmit_data)
|
@@ -70,16 +74,57 @@ class SidekiqTest < MiniTest::Unit::TestCase
|
|
70
74
|
assert_metric_and_call_count('OtherTransaction/SidekiqJob/all', JOB_COUNT)
|
71
75
|
end
|
72
76
|
|
73
|
-
|
77
|
+
def test_doesnt_capture_args_by_default
|
78
|
+
run_jobs
|
79
|
+
assert_no_params_on_jobs
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_isnt_influenced_by_global_capture_params
|
83
|
+
with_config(:capture_params => true) do
|
84
|
+
run_jobs
|
85
|
+
end
|
86
|
+
assert_no_params_on_jobs
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_agent_posts_captured_args_to_job
|
90
|
+
with_config(:'sidekiq.capture_params' => true) do
|
91
|
+
run_jobs
|
92
|
+
end
|
93
|
+
|
94
|
+
transaction_samples = $collector.calls_for('transaction_sample_data')
|
95
|
+
assert_false transaction_samples.empty?
|
96
|
+
|
97
|
+
transaction_samples.each do |post|
|
98
|
+
post.samples.each do |sample|
|
99
|
+
assert_equal sample.metric_name, TRANSACTION_NAME, "Huh, that transaction shouldn't be in there!"
|
100
|
+
|
101
|
+
args = sample.tree.custom_params["job_arguments"]
|
102
|
+
assert_equal args.length, 2
|
103
|
+
assert_equal args[0], "jobs_completed"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
74
107
|
|
75
108
|
def assert_metric_and_call_count(name, expected_call_count)
|
76
109
|
metric_data = $collector.calls_for('metric_data')
|
77
110
|
assert_equal(1, metric_data.size, "expected exactly one metric_data post from agent")
|
78
111
|
|
79
|
-
metric = metric_data.first
|
112
|
+
metric = metric_data.first.metrics.find { |m| m[0]['name'] == name }
|
80
113
|
assert(metric, "could not find metric named #{name}")
|
81
114
|
|
82
115
|
call_count = metric[1][0]
|
83
116
|
assert_equal(expected_call_count, call_count)
|
84
117
|
end
|
118
|
+
|
119
|
+
def assert_no_params_on_jobs
|
120
|
+
transaction_samples = $collector.calls_for('transaction_sample_data')
|
121
|
+
assert_false transaction_samples.empty?
|
122
|
+
|
123
|
+
transaction_samples.each do |post|
|
124
|
+
post.samples.each do |sample|
|
125
|
+
assert_equal sample.metric_name, TRANSACTION_NAME, "Huh, that transaction shouldn't be in there!"
|
126
|
+
assert_nil sample.tree.custom_params["job_arguments"]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
85
130
|
end
|