newrelic_rpm 2.8.2 → 2.8.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/README +1 -1
- data/lib/new_relic/agent/collection_helper.rb +1 -1
- data/lib/new_relic/config.rb +1 -0
- data/lib/new_relic/config/rails.rb +20 -14
- data/lib/new_relic/recipes.rb +13 -10
- data/lib/new_relic/version.rb +7 -1
- data/test/config/test_config.rb +26 -0
- data/test/new_relic/agent/agent_test_controller.rb +25 -0
- data/test/new_relic/agent/model_fixture.rb +0 -2
- data/test/new_relic/agent/tc_active_record.rb +16 -17
- data/test/new_relic/agent/tc_agent.rb +2 -2
- data/test/new_relic/agent/tc_collection_helper.rb +6 -5
- data/test/new_relic/agent/tc_controller.rb +11 -32
- data/test/new_relic/agent/tc_transaction_sample_builder.rb +173 -179
- data/test/test_helper.rb +2 -1
- data/ui/helpers/newrelic_helper.rb +5 -5
- metadata +3 -2
data/README
CHANGED
@@ -38,7 +38,7 @@ http://localhost:3000/newrelic
|
|
38
38
|
=== PRODUCTION MODE
|
39
39
|
|
40
40
|
To monitor your applications in production, create an account at
|
41
|
-
http://newrelic.com/get-RPM.
|
41
|
+
http://newrelic.com/get-RPM.html
|
42
42
|
|
43
43
|
When your application runs in the production environment, the New Relic agent
|
44
44
|
runs in production mode. It connects to the New Relic RPM service and sends deep
|
@@ -13,7 +13,7 @@ module NewRelic::Agent::CollectionHelper
|
|
13
13
|
new_params = {}
|
14
14
|
params.each do | key, value |
|
15
15
|
new_params[truncate(normalize_params(key),32)] = normalize_params(value)
|
16
|
-
|
16
|
+
end
|
17
17
|
new_params
|
18
18
|
when Enumerable
|
19
19
|
# We only want the first 20 values of any enumerable. Invoking to_a.first(20) works but
|
data/lib/new_relic/config.rb
CHANGED
@@ -43,20 +43,8 @@ class NewRelic::Config::Rails < NewRelic::Config
|
|
43
43
|
return
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
# has the effect of adding a route indiscriminately which is frowned upon by
|
49
|
-
# some: http://www.ruby-forum.com/topic/126316#563328
|
50
|
-
ActionController::Routing::RouteSet.class_eval do
|
51
|
-
next if defined? draw_with_newrelic_map
|
52
|
-
def draw_with_newrelic_map
|
53
|
-
draw_without_newrelic_map do | map |
|
54
|
-
map.named_route 'newrelic_developer', '/newrelic/:action/:id', :controller => 'newrelic' unless NewRelic::Config.instance['skip_developer_route']
|
55
|
-
yield map
|
56
|
-
end
|
57
|
-
end
|
58
|
-
alias_method_chain :draw, :newrelic_map
|
59
|
-
end
|
46
|
+
install_devmode_route
|
47
|
+
|
60
48
|
|
61
49
|
# If we have the config object then add the controller path to the list.
|
62
50
|
# Otherwise we have to assume the controller paths have already been
|
@@ -85,6 +73,24 @@ class NewRelic::Config::Rails < NewRelic::Config
|
|
85
73
|
|
86
74
|
protected
|
87
75
|
|
76
|
+
def install_devmode_route
|
77
|
+
# This is a monkey patch to inject the developer tool route into the
|
78
|
+
# parent app without requiring users to modify their routes. Of course this
|
79
|
+
# has the effect of adding a route indiscriminately which is frowned upon by
|
80
|
+
# some: http://www.ruby-forum.com/topic/126316#563328
|
81
|
+
ActionController::Routing::RouteSet.class_eval do
|
82
|
+
return false if self.instance_methods.include? 'draw_with_newrelic_map'
|
83
|
+
def draw_with_newrelic_map
|
84
|
+
draw_without_newrelic_map do | map |
|
85
|
+
map.named_route 'newrelic_developer', '/newrelic/:action/:id', :controller => 'newrelic' unless NewRelic::Config.instance['skip_developer_route']
|
86
|
+
yield map
|
87
|
+
end
|
88
|
+
end
|
89
|
+
alias_method_chain :draw, :newrelic_map
|
90
|
+
end
|
91
|
+
return true
|
92
|
+
end
|
93
|
+
|
88
94
|
# Collect the Rails::Info into an associative array as well as the list of plugins
|
89
95
|
def gather_info
|
90
96
|
i = [[:app, app]]
|
data/lib/new_relic/recipes.rb
CHANGED
@@ -40,10 +40,10 @@ make_notify_task = lambda do
|
|
40
40
|
end
|
41
41
|
new_revision = rev || source.query_revision(source.head()) { |cmd| `#{cmd}` }
|
42
42
|
deploy_options = { :environment => rails_env,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
:revision => new_revision,
|
44
|
+
:changelog => changelog,
|
45
|
+
:description => description,
|
46
|
+
:appname => appname }
|
47
47
|
logger.debug "Uploading deployment to New Relic"
|
48
48
|
deployment = NewRelic::Commands::Deployments.new deploy_options
|
49
49
|
deployment.run
|
@@ -62,10 +62,13 @@ make_notify_task = lambda do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
66
|
-
|
67
|
-
if instance
|
68
|
-
instance.load &make_notify_task
|
65
|
+
if Capistrano::Version::MAJOR < 2
|
66
|
+
STDERR.puts "Unable to load #{__FILE__}\nNew Relic Capistrano hooks require at least version 2.0.0"
|
69
67
|
else
|
70
|
-
|
71
|
-
|
68
|
+
instance = Capistrano::Configuration.instance
|
69
|
+
if instance
|
70
|
+
instance.load &make_notify_task
|
71
|
+
else
|
72
|
+
make_notify_task.call
|
73
|
+
end
|
74
|
+
end
|
data/lib/new_relic/version.rb
CHANGED
@@ -3,7 +3,7 @@ module NewRelic
|
|
3
3
|
module VERSION #:nodoc:
|
4
4
|
MAJOR = 2
|
5
5
|
MINOR = 8
|
6
|
-
TINY =
|
6
|
+
TINY = 3
|
7
7
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
8
8
|
def self.changes
|
9
9
|
puts "NewRelic RPM Plugin Version: #{NewRelic::VERSION::STRING}"
|
@@ -12,6 +12,12 @@ module NewRelic
|
|
12
12
|
|
13
13
|
CHANGELOG = <<EOF
|
14
14
|
|
15
|
+
2009-02-10 version 2.8.3
|
16
|
+
* refactor unit tests so they will run in a generic rails environment
|
17
|
+
* require classes in advance to avoid autoloading. this is to address
|
18
|
+
incompatibilities with desert as well as more flexibility in gem
|
19
|
+
initialization
|
20
|
+
* fixed newrelic_helper.rb 1.9 incompatibility
|
15
21
|
2009-02-07 version 2.8.2
|
16
22
|
* fix Ruby 1.9 syntax compatibility errors
|
17
23
|
* update the class loading sanity check, will notify server of errors
|
data/test/config/test_config.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'new_relic/config/rails'
|
2
|
+
require 'new_relic/agent/agent_test_controller'
|
3
|
+
|
2
4
|
class NewRelic::Config::Test < NewRelic::Config::Rails
|
3
5
|
def env
|
4
6
|
'test'
|
@@ -6,4 +8,28 @@ class NewRelic::Config::Test < NewRelic::Config::Rails
|
|
6
8
|
def config_file
|
7
9
|
File.join(File.dirname(__FILE__), "newrelic.yml")
|
8
10
|
end
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
setup_log env
|
14
|
+
end
|
15
|
+
# when running tests, don't write out stderr
|
16
|
+
def log!(msg, level=:info)
|
17
|
+
log.send level, msg if log
|
18
|
+
end
|
19
|
+
|
20
|
+
# Add the default route in case it's missing. Need it for testing.
|
21
|
+
def install_devmode_route
|
22
|
+
if super
|
23
|
+
ActionController::Routing::RouteSet.class_eval do
|
24
|
+
def draw_with_test_route
|
25
|
+
draw_without_test_route do | map |
|
26
|
+
map.connect ':controller/:action/:id'
|
27
|
+
yield map
|
28
|
+
end
|
29
|
+
end
|
30
|
+
alias_method_chain :draw, :test_route
|
31
|
+
end
|
32
|
+
return true
|
33
|
+
end
|
34
|
+
end
|
9
35
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# This is a controller class used in testing controller instrumentation
|
2
|
+
class NewRelic::Agent::AgentTestController < ActionController::Base
|
3
|
+
filter_parameter_logging :social_security_number
|
4
|
+
def index
|
5
|
+
render :text => params.inspect
|
6
|
+
end
|
7
|
+
def _filter_parameters(params)
|
8
|
+
filter_parameters params
|
9
|
+
end
|
10
|
+
def action_to_render
|
11
|
+
render :text => params.inspect
|
12
|
+
end
|
13
|
+
def action_to_ignore
|
14
|
+
render :text => 'unmeasured'
|
15
|
+
end
|
16
|
+
def entry_action
|
17
|
+
perform_action_with_newrelic_trace('internal_action') do
|
18
|
+
internal_action
|
19
|
+
end
|
20
|
+
end
|
21
|
+
private
|
22
|
+
def internal_action
|
23
|
+
render :text => 'internal action'
|
24
|
+
end
|
25
|
+
end
|
@@ -6,11 +6,9 @@ class NewRelic::Agent::ModelFixture < ActiveRecord::Base
|
|
6
6
|
connection.create_table :test_data, :force => true do |t|
|
7
7
|
t.column :name, :string
|
8
8
|
end
|
9
|
-
connection.setup_slow
|
10
9
|
end
|
11
10
|
|
12
11
|
def self.teardown
|
13
|
-
connection.teardown_slow
|
14
12
|
connection.drop_table :test_data
|
15
13
|
end
|
16
14
|
|
@@ -6,12 +6,7 @@ class ActiveRecordInstrumentationTests < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
def setup
|
8
8
|
super
|
9
|
-
|
10
|
-
NewRelic::Agent::ModelFixture.setup
|
11
|
-
rescue => e
|
12
|
-
puts e
|
13
|
-
raise e
|
14
|
-
end
|
9
|
+
NewRelic::Agent::ModelFixture.setup
|
15
10
|
@agent = NewRelic::Agent.instance
|
16
11
|
@agent.start :test, :test
|
17
12
|
@agent.transaction_sampler.harvest_slowest_sample
|
@@ -38,7 +33,7 @@ class ActiveRecordInstrumentationTests < Test::Unit::TestCase
|
|
38
33
|
NewRelic::Agent::ModelFixture.find(:all)
|
39
34
|
sample = @agent.transaction_sampler.harvest_slowest_sample
|
40
35
|
segment = sample.root_segment.called_segments.first.called_segments.first
|
41
|
-
|
36
|
+
assert_match /^SELECT \* FROM ["`]test_data["`]$/i, segment.params[:sql].strip
|
42
37
|
NewRelic::TransactionSample::Segment.any_instance.expects(:explain_sql).returns([])
|
43
38
|
sample = sample.prepare_to_send(:obfuscate_sql => true, :explain_enabled => true, :explain_sql => 0.0)
|
44
39
|
segment = sample.root_segment.called_segments.first.called_segments.first
|
@@ -53,10 +48,11 @@ class ActiveRecordInstrumentationTests < Test::Unit::TestCase
|
|
53
48
|
segment = sample.root_segment.called_segments.first.called_segments.first
|
54
49
|
assert_match /^SELECT /, segment.params[:sql]
|
55
50
|
explanations = segment.params[:explanation]
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
if isMysql? || isPostgres?
|
52
|
+
assert_not_nil explanations, "No explains in segment: #{segment}"
|
53
|
+
assert_equal 1, explanations.size,"No explains in segment: #{segment}"
|
54
|
+
assert_equal 1, explanations.first.size
|
55
|
+
end
|
60
56
|
end
|
61
57
|
def test_transaction
|
62
58
|
|
@@ -66,16 +62,17 @@ class ActiveRecordInstrumentationTests < Test::Unit::TestCase
|
|
66
62
|
segment = sample.root_segment.called_segments.first.called_segments.first
|
67
63
|
assert_nil segment.params[:sql], "SQL should have been removed."
|
68
64
|
explanations = segment.params[:explanation]
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
if isMysql? || isPostgres?
|
66
|
+
assert_not_nil explanations, "No explains in segment: #{segment}"
|
67
|
+
assert_equal 1, explanations.size,"No explains in segment: #{segment}"
|
68
|
+
assert_equal 1, explanations.first.size
|
69
|
+
end
|
73
70
|
if isPostgres?
|
74
71
|
assert_equal Array, explanations.class
|
75
72
|
assert_equal Array, explanations[0].class
|
76
73
|
assert_equal Array, explanations[0][0].class
|
77
74
|
assert_match /Seq Scan on test_data/, explanations[0][0].join(";")
|
78
|
-
|
75
|
+
elsif isMysql?
|
79
76
|
assert_equal "1;SIMPLE;test_data;ALL;;;;;1;", explanations.first.first.join(";")
|
80
77
|
end
|
81
78
|
|
@@ -87,5 +84,7 @@ class ActiveRecordInstrumentationTests < Test::Unit::TestCase
|
|
87
84
|
def isPostgres?
|
88
85
|
NewRelic::Agent::ModelFixture.configurations[RAILS_ENV]['adapter'] =~ /postgres/
|
89
86
|
end
|
90
|
-
|
87
|
+
def isMysql?
|
88
|
+
NewRelic::Agent::ModelFixture.connection.class.name =~ /mysql/i
|
89
|
+
end
|
91
90
|
end
|
@@ -111,8 +111,8 @@ class AgentTests < ActiveSupport::TestCase
|
|
111
111
|
def test_info
|
112
112
|
props = NewRelic::Config.instance.app_config_info
|
113
113
|
list = props.assoc('Plugin List').last.sort
|
114
|
-
|
115
|
-
|
114
|
+
assert_not_nil list # can't really guess what might be in here.
|
115
|
+
assert_match /jdbc|postgres|mysql|sqlite/, props.assoc('Database adapter').last
|
116
116
|
end
|
117
117
|
def test_version
|
118
118
|
assert_match /\d\.\d\.\d+/, NewRelic::VERSION::STRING
|
@@ -26,13 +26,14 @@ class NewRelic::Agent::CollectionHelperTests < Test::Unit::TestCase
|
|
26
26
|
assert_equal '1000', new_array[0]
|
27
27
|
end
|
28
28
|
def test_boolean
|
29
|
-
np = normalize_params(
|
30
|
-
assert_equal false, np['
|
29
|
+
np = normalize_params(NewRelic::Config.instance.settings)
|
30
|
+
assert_equal false, np['enabled']
|
31
31
|
end
|
32
|
-
|
33
|
-
|
32
|
+
class MyString < String; end
|
33
|
+
def test_kind_of_string
|
34
|
+
s = MyString.new "This is a string"
|
34
35
|
assert_equal "This is a string", s.to_s
|
35
|
-
assert_equal
|
36
|
+
assert_equal MyString, s.class
|
36
37
|
assert_equal String, s.to_s.class
|
37
38
|
params = normalize_params(:val => [s])
|
38
39
|
assert_equal String, params[:val][0].class
|
@@ -1,35 +1,10 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
2
|
require 'action_controller/base'
|
3
|
-
|
4
|
-
|
5
|
-
class AgentTestController < ActionController::Base
|
6
|
-
filter_parameter_logging :social_security_number
|
7
|
-
def index
|
8
|
-
render :text => params.inspect
|
9
|
-
end
|
10
|
-
def _filter_parameters(params)
|
11
|
-
filter_parameters params
|
12
|
-
end
|
13
|
-
def action_to_render
|
14
|
-
render :text => params.inspect
|
15
|
-
end
|
16
|
-
def action_to_ignore
|
17
|
-
render :text => 'unmeasured'
|
18
|
-
end
|
19
|
-
def entry_action
|
20
|
-
perform_action_with_newrelic_trace('internal_action') do
|
21
|
-
internal_action
|
22
|
-
end
|
23
|
-
end
|
24
|
-
private
|
25
|
-
def internal_action
|
26
|
-
render :text => 'internal action'
|
27
|
-
end
|
28
|
-
end
|
3
|
+
#require 'new_relic/agent/agent_test_controller'
|
29
4
|
|
30
5
|
class AgentControllerTests < ActionController::TestCase
|
31
6
|
|
32
|
-
self.controller_class = AgentTestController
|
7
|
+
self.controller_class = NewRelic::Agent::AgentTestController
|
33
8
|
|
34
9
|
attr_accessor :agent
|
35
10
|
|
@@ -40,7 +15,7 @@ class AgentControllerTests < ActionController::TestCase
|
|
40
15
|
# @agent.instrument_app
|
41
16
|
agent.start :test, :test
|
42
17
|
agent.transaction_sampler.harvest_slowest_sample
|
43
|
-
AgentTestController.class_eval do
|
18
|
+
NewRelic::Agent::AgentTestController.class_eval do
|
44
19
|
newrelic_ignore :only => [:action_to_ignore, :entry_action]
|
45
20
|
end
|
46
21
|
end
|
@@ -57,7 +32,7 @@ class AgentControllerTests < ActionController::TestCase
|
|
57
32
|
end
|
58
33
|
def test_metric__no_ignore
|
59
34
|
engine = @agent.stats_engine
|
60
|
-
index_stats = engine.get_stats_no_scope('Controller/agent_test/index')
|
35
|
+
index_stats = engine.get_stats_no_scope('Controller/new_relic/agent/agent_test/index')
|
61
36
|
assert_difference 'index_stats.call_count' do
|
62
37
|
get :index
|
63
38
|
end
|
@@ -68,11 +43,15 @@ class AgentControllerTests < ActionController::TestCase
|
|
68
43
|
get :entry_action
|
69
44
|
assert_equal false, Thread.current[:controller_ignored]
|
70
45
|
assert_nil engine.lookup_stat('Controller/agent_test/entry_action')
|
71
|
-
assert_equal 1, engine.lookup_stat('Controller/agent_test/internal_action').call_count
|
46
|
+
assert_equal 1, engine.lookup_stat('Controller/new_relic/agent/agent_test/internal_action').call_count
|
72
47
|
end
|
73
48
|
def test_action_instrumentation
|
74
|
-
|
75
|
-
|
49
|
+
begin
|
50
|
+
get :index, :foo => 'bar'
|
51
|
+
assert_match /bar/, @response.body
|
52
|
+
#rescue ActionController::RoutingError
|
53
|
+
# you might get here if you don't have the default route installed.
|
54
|
+
end
|
76
55
|
end
|
77
56
|
|
78
57
|
def test_controller_params
|
@@ -1,200 +1,194 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
-
##require 'new_relic/agent/transaction_sampler'
|
3
|
-
require 'test/unit'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
class NewRelic::Agent::TransationSampleBuilderTests < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@builder = NewRelic::Agent::TransactionSampleBuilder.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_build_sample
|
10
|
+
build_segment("a") do
|
11
|
+
build_segment("aa") do
|
12
|
+
build_segment("aaa")
|
11
13
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
build_segment("aa") do
|
16
|
-
build_segment("aaa")
|
17
|
-
end
|
18
|
-
build_segment("ab") do
|
19
|
-
build_segment("aba") do
|
20
|
-
build_segment("abaa")
|
21
|
-
end
|
22
|
-
build_segment("aba")
|
23
|
-
build_segment("abc") do
|
24
|
-
build_segment("abca")
|
25
|
-
build_segment("abcd")
|
26
|
-
end
|
27
|
-
end
|
14
|
+
build_segment("ab") do
|
15
|
+
build_segment("aba") do
|
16
|
+
build_segment("abaa")
|
28
17
|
end
|
29
|
-
build_segment
|
30
|
-
build_segment
|
31
|
-
build_segment
|
32
|
-
build_segment
|
33
|
-
build_segment "cba"
|
34
|
-
end
|
18
|
+
build_segment("aba")
|
19
|
+
build_segment("abc") do
|
20
|
+
build_segment("abca")
|
21
|
+
build_segment("abcd")
|
35
22
|
end
|
36
|
-
|
37
|
-
@builder.finish_trace(Time.now.to_f)
|
38
|
-
validate_builder
|
39
23
|
end
|
24
|
+
end
|
25
|
+
build_segment "b"
|
26
|
+
build_segment "c" do
|
27
|
+
build_segment "ca"
|
28
|
+
build_segment "cb" do
|
29
|
+
build_segment "cba"
|
30
|
+
end
|
31
|
+
end
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
33
|
+
@builder.finish_trace(Time.now.to_f)
|
34
|
+
validate_builder
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_freeze
|
38
|
+
build_segment "a" do
|
39
|
+
build_segment "aa"
|
40
|
+
end
|
41
|
+
|
42
|
+
begin
|
43
|
+
builder.sample
|
44
|
+
assert false
|
45
|
+
rescue Exception => e
|
46
|
+
# expected
|
47
|
+
end
|
48
|
+
|
49
|
+
@builder.finish_trace(Time.now.to_f)
|
50
|
+
|
51
|
+
validate_builder
|
52
|
+
|
53
|
+
begin
|
54
|
+
build_segment "b"
|
55
|
+
assert_false
|
56
|
+
rescue TypeError => e
|
57
|
+
# expected
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# this is really a test for transaction sample
|
62
|
+
def test_omit_segments_with
|
63
|
+
build_segment "Controller/my_controller/index" do
|
64
|
+
sleep 0.010
|
56
65
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
66
|
+
build_segment "Rails/Application Code Loading" do
|
67
|
+
sleep 0.020
|
68
|
+
|
69
|
+
build_segment "foo/bar" do
|
70
|
+
sleep 0.010
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
sleep 0.010
|
69
|
-
|
70
|
-
build_segment "Rails/Application Code Loading" do
|
71
|
-
sleep 0.020
|
72
|
-
|
73
|
-
build_segment "foo/bar" do
|
74
|
-
sleep 0.010
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
build_segment "a" do
|
79
|
-
build_segment "ab"
|
80
|
-
sleep 0.010
|
81
|
-
end
|
82
|
-
build_segment "b" do
|
83
|
-
build_segment "ba"
|
84
|
-
sleep 0.05
|
85
|
-
build_segment "bb"
|
86
|
-
build_segment "bc" do
|
87
|
-
build_segment "bca"
|
88
|
-
sleep 0.05
|
89
|
-
end
|
90
|
-
end
|
91
|
-
build_segment "c"
|
92
|
-
end
|
93
|
-
@builder.finish_trace(Time.now.to_f)
|
94
|
-
|
95
|
-
validate_builder false
|
96
|
-
|
97
|
-
sample = @builder.sample
|
98
|
-
|
99
|
-
should_be_a_copy = sample.omit_segments_with('OMIT NOTHING')
|
100
|
-
validate_segment should_be_a_copy.root_segment, false
|
101
|
-
|
102
|
-
assert sample.to_s == should_be_a_copy.to_s
|
103
|
-
|
104
|
-
without_code_loading = sample.omit_segments_with('Rails/Application Code Loading')
|
105
|
-
validate_segment without_code_loading.root_segment, false
|
106
|
-
|
107
|
-
# after we take out code loading, the delta should be approximately
|
108
|
-
# 30 milliseconds
|
109
|
-
delta = (sample.duration - without_code_loading.duration).to_ms
|
110
|
-
|
111
|
-
# allow a few milliseconds for slop just in case this is running on a 386 ;)
|
112
|
-
assert delta >= 30, "delta #{delta} should be between 30 and 50"
|
113
|
-
# disable this test for a couple days:
|
114
|
-
assert delta <= 50, "delta #{delta} should be between 30 and 50"
|
115
|
-
|
116
|
-
# ensure none of the segments have this regex
|
117
|
-
without_code_loading.each_segment do |segment|
|
118
|
-
assert_nil segment.metric_name =~ /Rails\/Application Code Loading/
|
119
|
-
end
|
74
|
+
build_segment "a" do
|
75
|
+
build_segment "ab"
|
76
|
+
sleep 0.010
|
120
77
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
129
|
-
end
|
130
|
-
rescue; end
|
131
|
-
end
|
78
|
+
build_segment "b" do
|
79
|
+
build_segment "ba"
|
80
|
+
sleep 0.05
|
81
|
+
build_segment "bb"
|
82
|
+
build_segment "bc" do
|
83
|
+
build_segment "bca"
|
84
|
+
sleep 0.05
|
132
85
|
end
|
133
86
|
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
87
|
+
build_segment "c"
|
88
|
+
end
|
89
|
+
@builder.finish_trace(Time.now.to_f)
|
90
|
+
|
91
|
+
validate_builder false
|
92
|
+
|
93
|
+
sample = @builder.sample
|
94
|
+
|
95
|
+
should_be_a_copy = sample.omit_segments_with('OMIT NOTHING')
|
96
|
+
validate_segment should_be_a_copy.root_segment, false
|
97
|
+
|
98
|
+
assert sample.to_s == should_be_a_copy.to_s
|
99
|
+
|
100
|
+
without_code_loading = sample.omit_segments_with('Rails/Application Code Loading')
|
101
|
+
validate_segment without_code_loading.root_segment, false
|
102
|
+
|
103
|
+
# after we take out code loading, the delta should be approximately
|
104
|
+
# 30 milliseconds
|
105
|
+
delta = (sample.duration - without_code_loading.duration).to_ms
|
106
|
+
|
107
|
+
# allow a few milliseconds for slop just in case this is running on a 386 ;)
|
108
|
+
assert delta >= 30, "delta #{delta} should be between 30 and 50"
|
109
|
+
# disable this test for a couple days:
|
110
|
+
assert delta <= 50, "delta #{delta} should be between 30 and 50"
|
111
|
+
|
112
|
+
# ensure none of the segments have this regex
|
113
|
+
without_code_loading.each_segment do |segment|
|
114
|
+
assert_nil segment.metric_name =~ /Rails\/Application Code Loading/
|
115
|
+
end
|
116
|
+
end
|
117
|
+
def test_unbalanced_handling
|
118
|
+
assert_raise RuntimeError do
|
119
|
+
build_segment("a") do
|
120
|
+
begin
|
121
|
+
build_segment("aa") do
|
122
|
+
build_segment("aaa") do
|
123
|
+
raise "a problem"
|
124
|
+
end
|
143
125
|
end
|
144
|
-
|
145
|
-
build_segment "c"
|
146
|
-
|
147
|
-
@builder.finish_trace(Time.now.to_f)
|
148
|
-
validate_builder
|
149
|
-
|
150
|
-
dump = Marshal.dump @builder.sample
|
151
|
-
sample = Marshal.restore(dump)
|
152
|
-
validate_segment(sample.root_segment)
|
126
|
+
rescue; end
|
153
127
|
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
def validate_builder(check_names = true)
|
167
|
-
validate_segment @builder.sample.root_segment, check_names
|
128
|
+
end
|
129
|
+
end
|
130
|
+
def test_marshal
|
131
|
+
build_segment "a" do
|
132
|
+
build_segment "ab"
|
133
|
+
end
|
134
|
+
build_segment "b" do
|
135
|
+
build_segment "ba"
|
136
|
+
build_segment "bb"
|
137
|
+
build_segment "bc" do
|
138
|
+
build_segment "bca"
|
168
139
|
end
|
140
|
+
end
|
141
|
+
build_segment "c"
|
169
142
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
143
|
+
@builder.finish_trace(Time.now.to_f)
|
144
|
+
validate_builder
|
145
|
+
|
146
|
+
dump = Marshal.dump @builder.sample
|
147
|
+
sample = Marshal.restore(dump)
|
148
|
+
validate_segment(sample.root_segment)
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_parallel_first_level_segments
|
152
|
+
build_segment "a" do
|
153
|
+
build_segment "ab"
|
154
|
+
end
|
155
|
+
build_segment "b"
|
156
|
+
build_segment "c"
|
157
|
+
|
158
|
+
@builder.finish_trace(Time.now.to_f)
|
159
|
+
validate_builder
|
160
|
+
end
|
161
|
+
|
162
|
+
def validate_builder(check_names = true)
|
163
|
+
validate_segment @builder.sample.root_segment, check_names
|
164
|
+
end
|
165
|
+
|
166
|
+
def validate_segment(s, check_names = true)
|
167
|
+
p = s.parent_segment
|
168
|
+
|
169
|
+
unless p.nil? || p.metric_name == 'ROOT'
|
170
|
+
assert p.called_segments.include?(s)
|
171
|
+
assert_equal p.metric_name.length, s.metric_name.length - 1, "p: #{p.metric_name}, s: #{s.metric_name}" if check_names
|
172
|
+
assert p.metric_name < s.metric_name if check_names
|
173
|
+
assert p.entry_timestamp <= s.entry_timestamp
|
174
|
+
end
|
175
|
+
|
176
|
+
assert s.exit_timestamp >= s.entry_timestamp
|
177
|
+
|
178
|
+
children = s.called_segments
|
179
|
+
last_segment = s
|
180
|
+
children.each do |child|
|
181
|
+
assert child.metric_name > last_segment.metric_name if check_names
|
182
|
+
assert child.entry_timestamp >= last_segment.entry_timestamp
|
183
|
+
last_metric = child
|
192
184
|
|
193
|
-
|
194
|
-
@builder.trace_entry(metric, Time.now.to_f)
|
195
|
-
proc.call if proc
|
196
|
-
@builder.trace_exit(metric, Time.now.to_f)
|
197
|
-
end
|
185
|
+
validate_segment(child, check_names)
|
198
186
|
end
|
199
187
|
end
|
200
|
-
|
188
|
+
|
189
|
+
def build_segment(metric, time = 0, &proc)
|
190
|
+
@builder.trace_entry(metric, Time.now.to_f)
|
191
|
+
proc.call if proc
|
192
|
+
@builder.trace_exit(metric, Time.now.to_f)
|
193
|
+
end
|
194
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -9,7 +9,6 @@ require 'test_help'
|
|
9
9
|
require 'mocha'
|
10
10
|
require 'test/unit'
|
11
11
|
|
12
|
-
|
13
12
|
module NewRelic
|
14
13
|
class Config
|
15
14
|
def setup_log_with_block_logging(*args)
|
@@ -19,6 +18,7 @@ module NewRelic
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
21
|
+
=begin
|
22
22
|
# This is a mixin for hacking the select method
|
23
23
|
if defined? ActiveRecord::ConnectionAdapters
|
24
24
|
class ActiveRecord::ConnectionAdapters::MysqlAdapter
|
@@ -37,3 +37,4 @@ if defined? ActiveRecord::ConnectionAdapters
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
+
=end
|
@@ -275,11 +275,11 @@ private
|
|
275
275
|
def mime_type_from_extension(extension)
|
276
276
|
extension = extension[/[^.]*$/].downcase
|
277
277
|
case extension
|
278
|
-
when 'png'
|
279
|
-
when 'gif'
|
280
|
-
when 'jpg'
|
281
|
-
when 'css'
|
282
|
-
when 'js'
|
278
|
+
when 'png'; 'image/png'
|
279
|
+
when 'gif'; 'image/gif'
|
280
|
+
when 'jpg'; 'image/jpg'
|
281
|
+
when 'css'; 'text/css'
|
282
|
+
when 'js'; 'text/javascript'
|
283
283
|
else 'text/plain'
|
284
284
|
end
|
285
285
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newrelic_rpm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.8.
|
4
|
+
version: 2.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Kayser
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-14 00:00:00 -08:00
|
13
13
|
default_executable: newrelic_cmd
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- test/config/test_config.rb
|
95
95
|
- test/new_relic
|
96
96
|
- test/new_relic/agent
|
97
|
+
- test/new_relic/agent/agent_test_controller.rb
|
97
98
|
- test/new_relic/agent/mock_ar_connection.rb
|
98
99
|
- test/new_relic/agent/mock_scope_listener.rb
|
99
100
|
- test/new_relic/agent/model_fixture.rb
|