onyx_newrelic_rpm 2.12.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +436 -0
- data/LICENSE +37 -0
- data/README.md +138 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic_cmd +4 -0
- data/cert/cacert.pem +34 -0
- data/install.rb +46 -0
- data/lib/new_relic/agent/agent.rb +668 -0
- data/lib/new_relic/agent/busy_calculator.rb +91 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/error_collector.rb +128 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +92 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +45 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +404 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +40 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +9 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +307 -0
- data/lib/new_relic/agent/instrumentation/net.rb +17 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +22 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +112 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +24 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +45 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +21 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +17 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +10 -0
- data/lib/new_relic/agent/method_tracer.rb +350 -0
- data/lib/new_relic/agent/sampler.rb +46 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +54 -0
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +142 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
- data/lib/new_relic/agent/shim_agent.rb +21 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +80 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
- data/lib/new_relic/agent/stats_engine.rb +24 -0
- data/lib/new_relic/agent/transaction_sampler.rb +315 -0
- data/lib/new_relic/agent/worker_loop.rb +80 -0
- data/lib/new_relic/agent.rb +369 -0
- data/lib/new_relic/collection_helper.rb +69 -0
- data/lib/new_relic/commands/deployments.rb +145 -0
- data/lib/new_relic/commands/new_relic_commands.rb +30 -0
- data/lib/new_relic/control/external.rb +13 -0
- data/lib/new_relic/control/merb.rb +24 -0
- data/lib/new_relic/control/rails.rb +151 -0
- data/lib/new_relic/control/rails3.rb +75 -0
- data/lib/new_relic/control/ruby.rb +36 -0
- data/lib/new_relic/control/sinatra.rb +18 -0
- data/lib/new_relic/control.rb +528 -0
- data/lib/new_relic/delayed_job_injection.rb +27 -0
- data/lib/new_relic/histogram.rb +89 -0
- data/lib/new_relic/local_environment.rb +333 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +42 -0
- data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
- data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
- data/lib/new_relic/metric_parser/active_record.rb +25 -0
- data/lib/new_relic/metric_parser/controller.rb +54 -0
- data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
- data/lib/new_relic/metric_parser/errors.rb +6 -0
- data/lib/new_relic/metric_parser/external.rb +50 -0
- data/lib/new_relic/metric_parser/mem_cache.rb +50 -0
- data/lib/new_relic/metric_parser/other_transaction.rb +15 -0
- data/lib/new_relic/metric_parser/view.rb +61 -0
- data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
- data/lib/new_relic/metric_parser/web_service.rb +9 -0
- data/lib/new_relic/metric_parser.rb +125 -0
- data/lib/new_relic/metric_spec.rb +67 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +24 -0
- data/lib/new_relic/rack/metric_app.rb +58 -0
- data/lib/new_relic/rack/mongrel_rpm.ru +25 -0
- data/lib/new_relic/rack/newrelic.yml +26 -0
- data/lib/new_relic/rack_app.rb +5 -0
- data/lib/new_relic/recipes.rb +82 -0
- data/lib/new_relic/stats.rb +376 -0
- data/lib/new_relic/transaction_analysis.rb +124 -0
- data/lib/new_relic/transaction_sample.rb +654 -0
- data/lib/new_relic/version.rb +55 -0
- data/lib/new_relic_api.rb +276 -0
- data/lib/newrelic_rpm.rb +40 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +15 -0
- data/newrelic.yml +235 -0
- data/onyx_newrelic_rpm.gemspec +221 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +43 -0
- data/test/config/test_control.rb +38 -0
- data/test/new_relic/agent/active_record_instrumentation_test.rb +287 -0
- data/test/new_relic/agent/agent_controller_test.rb +280 -0
- data/test/new_relic/agent/agent_test_controller.rb +82 -0
- data/test/new_relic/agent/busy_calculator_test.rb +79 -0
- data/test/new_relic/agent/collection_helper_test.rb +125 -0
- data/test/new_relic/agent/error_collector_test.rb +171 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +103 -0
- data/test/new_relic/agent/method_tracer_test.rb +340 -0
- data/test/new_relic/agent/metric_data_test.rb +56 -0
- data/test/new_relic/agent/metric_frame_test.rb +51 -0
- data/test/new_relic/agent/mock_ar_connection.rb +40 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
- data/test/new_relic/agent/rpm_agent_test.rb +138 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +72 -0
- data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
- data/test/new_relic/agent/task_instrumentation_test.rb +193 -0
- data/test/new_relic/agent/testable_agent.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
- data/test/new_relic/agent/transaction_sample_test.rb +186 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +385 -0
- data/test/new_relic/agent/worker_loop_test.rb +60 -0
- data/test/new_relic/control_test.rb +117 -0
- data/test/new_relic/deployments_api_test.rb +69 -0
- data/test/new_relic/environment_test.rb +75 -0
- data/test/new_relic/metric_parser_test.rb +172 -0
- data/test/new_relic/metric_spec_test.rb +177 -0
- data/test/new_relic/shim_agent_test.rb +9 -0
- data/test/new_relic/stats_test.rb +311 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/test_helper.rb +53 -0
- data/test/ui/newrelic_controller_test.rb +14 -0
- data/test/ui/newrelic_helper_test.rb +53 -0
- data/ui/controllers/newrelic_controller.rb +220 -0
- data/ui/helpers/google_pie_chart.rb +49 -0
- data/ui/helpers/newrelic_helper.rb +319 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +19 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +14 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +11 -0
- data/ui/views/newrelic/_stack_trace.rhtml +30 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +42 -0
- data/ui/views/newrelic/images/arrow-close.png +0 -0
- data/ui/views/newrelic/images/arrow-open.png +0 -0
- data/ui/views/newrelic/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/images/file_icon.png +0 -0
- data/ui/views/newrelic/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/images/textmate.png +0 -0
- data/ui/views/newrelic/index.rhtml +57 -0
- data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
- data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/stylesheets/style.css +484 -0
- data/ui/views/newrelic/threads.rhtml +52 -0
- metadata +248 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
|
5
|
+
class NewRelic::Agent::MetricDataTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
|
8
|
+
# test to make sure the MetricData class can serialize to json
|
9
|
+
def test_json
|
10
|
+
spec = NewRelic::MetricSpec.new("controller", "metric#find")
|
11
|
+
|
12
|
+
import = ActiveSupport::JSON.decode(spec.to_json)
|
13
|
+
|
14
|
+
compare_spec(spec, import)
|
15
|
+
|
16
|
+
stats = NewRelic::MethodTraceStats.new
|
17
|
+
|
18
|
+
import = ActiveSupport::JSON.decode(stats.to_json)
|
19
|
+
|
20
|
+
compare_stat(stats, import)
|
21
|
+
|
22
|
+
metric_data = NewRelic::MetricData.new(spec, stats, 10)
|
23
|
+
|
24
|
+
import = ActiveSupport::JSON.decode(metric_data.to_json)
|
25
|
+
|
26
|
+
compare_metric_data(metric_data, import)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def compare_spec(spec, import)
|
33
|
+
assert_equal 2, import.length
|
34
|
+
assert_equal spec.name, import['name']
|
35
|
+
assert_equal spec.scope, import['scope']
|
36
|
+
end
|
37
|
+
|
38
|
+
def compare_stat(stats, import)
|
39
|
+
assert_equal 6, import.length
|
40
|
+
assert_equal stats.total_call_time, import['total_call_time']
|
41
|
+
assert_equal stats.max_call_time, import['max_call_time']
|
42
|
+
assert_equal stats.min_call_time, import['min_call_time']
|
43
|
+
assert_equal stats.sum_of_squares, import['sum_of_squares']
|
44
|
+
assert_equal stats.call_count, import['call_count']
|
45
|
+
assert_equal stats.total_exclusive_time, import['total_exclusive_time']
|
46
|
+
end
|
47
|
+
|
48
|
+
def compare_metric_data(metric_data, import)
|
49
|
+
assert_equal 3, import.length
|
50
|
+
assert_equal metric_data.metric_id, import['metric_id']
|
51
|
+
compare_spec(metric_data.metric_spec, import['metric_spec']) unless metric_data.metric_id
|
52
|
+
compare_stat(metric_data.stats, import['stats'])
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
3
|
+
|
4
|
+
class NewRelic::Agent::MetricFrameTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
attr_reader :f
|
7
|
+
def setup
|
8
|
+
@f = NewRelic::Agent::Instrumentation::MetricFrame.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_request_parsing__none
|
12
|
+
assert_nil f.uri
|
13
|
+
assert_nil f.referer
|
14
|
+
end
|
15
|
+
def test_request_parsing__path
|
16
|
+
request = stub(:path => '/path?hello=bob#none')
|
17
|
+
f.request = request
|
18
|
+
assert_equal "/path", f.uri
|
19
|
+
end
|
20
|
+
def test_request_parsing__fullpath
|
21
|
+
request = stub(:fullpath => '/path?hello=bob#none')
|
22
|
+
f.request = request
|
23
|
+
assert_equal "/path", f.uri
|
24
|
+
end
|
25
|
+
def test_request_parsing__referer
|
26
|
+
request = stub(:referer => 'https://www.yahoo.com:8080/path/hello?bob=none&foo=bar')
|
27
|
+
f.request = request
|
28
|
+
assert_nil f.uri
|
29
|
+
assert_equal "https://www.yahoo.com:8080/path/hello", f.referer
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_request_parsing__uri
|
33
|
+
request = stub(:uri => 'http://creature.com/path?hello=bob#none', :referer => '/path/hello?bob=none&foo=bar')
|
34
|
+
f.request = request
|
35
|
+
assert_equal "/path", f.uri
|
36
|
+
assert_equal "/path/hello", f.referer
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_request_parsing__hostname_only
|
40
|
+
request = stub(:uri => 'http://creature.com')
|
41
|
+
f.request = request
|
42
|
+
assert_equal "/", f.uri
|
43
|
+
assert_nil f.referer
|
44
|
+
end
|
45
|
+
def test_request_parsing__slash
|
46
|
+
request = stub(:uri => 'http://creature.com/')
|
47
|
+
f.request = request
|
48
|
+
assert_equal "/", f.uri
|
49
|
+
assert_nil f.referer
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
class << self
|
4
|
+
def test_connection(config)
|
5
|
+
@connect ||= Connection.new
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Connection
|
11
|
+
attr_accessor :throw
|
12
|
+
attr_reader :disconnected
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@disconnected = false
|
16
|
+
@throw = false
|
17
|
+
end
|
18
|
+
|
19
|
+
def disconnect!()
|
20
|
+
@disconnected = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def find()
|
24
|
+
# used to test that we've instrumented this...
|
25
|
+
end
|
26
|
+
|
27
|
+
def select_rows(s)
|
28
|
+
execute(s)
|
29
|
+
end
|
30
|
+
def execute(s)
|
31
|
+
fail "" if @throw
|
32
|
+
if s != "EXPLAIN #{::SQL_STATEMENT}"
|
33
|
+
fail "Unexpected sql statement #{s}"
|
34
|
+
end
|
35
|
+
s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
class NewRelic::Agent::MockScopeListener
|
3
|
+
|
4
|
+
attr_reader :scope
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@scope = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def notice_first_scope_push(time)
|
11
|
+
end
|
12
|
+
|
13
|
+
def notice_push_scope(scope, time)
|
14
|
+
@scope[scope] = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def notice_pop_scope(scope, time)
|
18
|
+
end
|
19
|
+
|
20
|
+
def notice_scope_empty(time)
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::Agent::NetInstrumentationTest < Test::Unit::TestCase
|
4
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
5
|
+
def setup
|
6
|
+
NewRelic::Agent.manual_start
|
7
|
+
@engine = NewRelic::Agent.instance.stats_engine
|
8
|
+
@engine.clear_stats
|
9
|
+
end
|
10
|
+
def test_get
|
11
|
+
url = URI.parse('http://www.google.com/index.html')
|
12
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
13
|
+
http.get('/index.html')
|
14
|
+
}
|
15
|
+
assert_match /<head>/, res.body
|
16
|
+
assert_equal %w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort,
|
17
|
+
@engine.metrics.sort
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_background
|
21
|
+
perform_action_with_newrelic_trace("task", :category => :task) do
|
22
|
+
url = URI.parse('http://www.google.com/index.html')
|
23
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
24
|
+
http.get('/index.html')
|
25
|
+
}
|
26
|
+
assert_match /<head>/, res.body
|
27
|
+
end
|
28
|
+
assert_equal @engine.metrics.select{|m| m =~ /^External/}.sort,
|
29
|
+
%w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all
|
30
|
+
External/www.google.com/Net::HTTP/GET:OtherTransaction/Background/NewRelic::Agent::NetInstrumentationTest/task].sort
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_transactional
|
34
|
+
perform_action_with_newrelic_trace("task") do
|
35
|
+
url = URI.parse('http://www.google.com/index.html')
|
36
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
37
|
+
http.get('/index.html')
|
38
|
+
}
|
39
|
+
assert_match /<head>/, res.body
|
40
|
+
end
|
41
|
+
assert_equal @engine.metrics.select{|m| m =~ /^External/}.sort,
|
42
|
+
%w[External/www.google.com/Net::HTTP/GET External/allWeb External/www.google.com/all
|
43
|
+
External/www.google.com/Net::HTTP/GET:Controller/NewRelic::Agent::NetInstrumentationTest/task].sort
|
44
|
+
end
|
45
|
+
def test_get__simple
|
46
|
+
Net::HTTP.get URI.parse('http://www.google.com/index.html')
|
47
|
+
assert_equal @engine.metrics.sort,
|
48
|
+
%w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort
|
49
|
+
end
|
50
|
+
def test_ignore
|
51
|
+
NewRelic::Agent.disable_all_tracing do
|
52
|
+
url = URI.parse('http://www.google.com/index.html')
|
53
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
54
|
+
http.post('/index.html','data')
|
55
|
+
}
|
56
|
+
end
|
57
|
+
assert_equal 0, @engine.metrics.size
|
58
|
+
end
|
59
|
+
def test_head
|
60
|
+
url = URI.parse('http://www.google.com/index.html')
|
61
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
62
|
+
http.head('/index.html')
|
63
|
+
}
|
64
|
+
assert_equal %w[External/www.google.com/Net::HTTP/HEAD External/allOther External/www.google.com/all].sort,
|
65
|
+
@engine.metrics.sort
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_post
|
69
|
+
url = URI.parse('http://www.google.com/index.html')
|
70
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
71
|
+
http.post('/index.html','data')
|
72
|
+
}
|
73
|
+
assert_equal %w[External/www.google.com/Net::HTTP/POST External/allOther External/www.google.com/all].sort,
|
74
|
+
@engine.metrics.sort
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
##require 'new_relic/agent/agent'
|
3
|
+
##require 'new_relic/local_environment'
|
4
|
+
|
5
|
+
class RpmAgentTest < ActiveSupport::TestCase
|
6
|
+
|
7
|
+
attr_reader :agent
|
8
|
+
|
9
|
+
# Fake out the agent to think mongrel is running
|
10
|
+
def setup
|
11
|
+
NewRelic::Agent.manual_start
|
12
|
+
@agent = NewRelic::Agent.instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
NewRelic::Agent.shutdown
|
17
|
+
NewRelic::Control.instance['app_name']=nil
|
18
|
+
NewRelic::Control.instance['dispatcher']=nil
|
19
|
+
NewRelic::Control.instance['dispatcher_instance_id']=nil
|
20
|
+
end
|
21
|
+
def test_agent_setup
|
22
|
+
assert NewRelic::Agent.instance.class == NewRelic::Agent::Agent
|
23
|
+
assert_raise RuntimeError do
|
24
|
+
NewRelic::Control.instance.init_plugin :agent_enabled => false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_public_apis
|
29
|
+
assert_raise RuntimeError do
|
30
|
+
NewRelic::Agent.set_sql_obfuscator(:unknown) do |sql|
|
31
|
+
puts sql
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
ignore_called = false
|
36
|
+
NewRelic::Agent.ignore_error_filter do |e|
|
37
|
+
ignore_called = true
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
NewRelic::Agent.notice_error(ActionController::RoutingError.new("message"), :request_params => {:x => "y"})
|
41
|
+
assert ignore_called
|
42
|
+
NewRelic::Agent.instance.error_collector.instance_variable_set '@ignore_filter', nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_startup_shutdown
|
46
|
+
@agent = NewRelic::Agent::ShimAgent.instance
|
47
|
+
@agent.shutdown
|
48
|
+
assert (not @agent.started?)
|
49
|
+
@agent.start
|
50
|
+
assert !@agent.started?
|
51
|
+
# this installs the real agent:
|
52
|
+
NewRelic::Agent.manual_start
|
53
|
+
@agent = NewRelic::Agent.instance
|
54
|
+
assert @agent != NewRelic::Agent::ShimAgent.instance
|
55
|
+
assert @agent.started?
|
56
|
+
@agent.shutdown
|
57
|
+
assert !@agent.started?
|
58
|
+
@agent.start
|
59
|
+
assert @agent.started?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_manual_start
|
63
|
+
NewRelic::Agent.instance.expects(:connect).once
|
64
|
+
NewRelic::Agent.instance.expects(:start_worker_thread).once
|
65
|
+
NewRelic::Agent.instance.instance_variable_set '@started', nil
|
66
|
+
NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_post_fork_handler
|
70
|
+
NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
|
71
|
+
NewRelic::Agent.after_fork
|
72
|
+
NewRelic::Agent.after_fork
|
73
|
+
end
|
74
|
+
def test_manual_overrides
|
75
|
+
NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
|
76
|
+
assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
|
77
|
+
assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
|
78
|
+
end
|
79
|
+
def test_restart
|
80
|
+
NewRelic::Agent.manual_start :app_name => "noapp", :dispatcher_instance_id => ""
|
81
|
+
NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
|
82
|
+
assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
|
83
|
+
assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_send_timeslice_data
|
87
|
+
@agent.expects(:invoke_remote).returns({NewRelic::MetricSpec.new("/A/b/c") => 1, NewRelic::MetricSpec.new("/A/b/c", "/X") => 2, NewRelic::MetricSpec.new("/A/b/d") => 3 }.to_a)
|
88
|
+
@agent.send :harvest_and_send_timeslice_data
|
89
|
+
assert_equal 3, @agent.metric_ids.size
|
90
|
+
assert_equal 3, @agent.metric_ids[NewRelic::MetricSpec.new("/A/b/d") ], @agent.metric_ids.inspect
|
91
|
+
end
|
92
|
+
def test_set_record_sql
|
93
|
+
@agent.set_record_sql(false)
|
94
|
+
assert !Thread::current[:record_sql]
|
95
|
+
NewRelic::Agent.disable_sql_recording do
|
96
|
+
assert_equal false, Thread::current[:record_sql]
|
97
|
+
NewRelic::Agent.disable_sql_recording do
|
98
|
+
assert_equal false, Thread::current[:record_sql]
|
99
|
+
end
|
100
|
+
assert_equal false, Thread::current[:record_sql]
|
101
|
+
end
|
102
|
+
assert !Thread::current[:record_sql], Thread::current[:record_sql]
|
103
|
+
ensure
|
104
|
+
@agent.set_record_sql(nil)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_version
|
108
|
+
assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_invoke_remote__ignore_non_200_results
|
112
|
+
NewRelic::Agent::Agent.class_eval do
|
113
|
+
public :invoke_remote
|
114
|
+
end
|
115
|
+
response_mock = mock()
|
116
|
+
Net::HTTP.any_instance.stubs(:request).returns(response_mock)
|
117
|
+
response_mock.stubs(:message).returns("bogus error")
|
118
|
+
|
119
|
+
for code in %w[500 504 400 302 503] do
|
120
|
+
assert_raise NewRelic::Agent::ServerConnectionException, "Ignore #{code}" do
|
121
|
+
response_mock.stubs(:code).returns(code)
|
122
|
+
NewRelic::Agent.agent.invoke_remote :get_data_report_period, 0
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
def test_invoke_remote__throw_other_errors
|
127
|
+
NewRelic::Agent::Agent.class_eval do
|
128
|
+
public :invoke_remote
|
129
|
+
end
|
130
|
+
response_mock = Net::HTTPSuccess.new nil, nil, nil
|
131
|
+
response_mock.stubs(:body).returns("")
|
132
|
+
Marshal.stubs(:load).raises(RuntimeError, "marshal issue")
|
133
|
+
Net::HTTP.any_instance.stubs(:request).returns(response_mock)
|
134
|
+
assert_raise RuntimeError do
|
135
|
+
NewRelic::Agent.agent.invoke_remote :get_data_report_period, 0xFEFE
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
|
3
|
+
|
4
|
+
class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
NewRelic::Agent.manual_start
|
7
|
+
@engine = NewRelic::Agent.instance.stats_engine
|
8
|
+
rescue => e
|
9
|
+
puts e
|
10
|
+
puts e.backtrace.join("\n")
|
11
|
+
end
|
12
|
+
def teardown
|
13
|
+
@engine.harvest_timeslice_data({},{})
|
14
|
+
end
|
15
|
+
def test_get_no_scope
|
16
|
+
s1 = @engine.get_stats "a"
|
17
|
+
s2 = @engine.get_stats "a"
|
18
|
+
s3 = @engine.get_stats "b"
|
19
|
+
|
20
|
+
assert_not_nil s1
|
21
|
+
assert_not_nil s2
|
22
|
+
assert_not_nil s3
|
23
|
+
|
24
|
+
assert s1 == s2
|
25
|
+
assert s1 != s3
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_harvest
|
29
|
+
s1 = @engine.get_stats "a"
|
30
|
+
s2 = @engine.get_stats "c"
|
31
|
+
|
32
|
+
s1.trace_call 10
|
33
|
+
s2.trace_call 1
|
34
|
+
s2.trace_call 3
|
35
|
+
|
36
|
+
assert @engine.get_stats("a").call_count == 1
|
37
|
+
assert @engine.get_stats("a").total_call_time == 10
|
38
|
+
|
39
|
+
assert @engine.get_stats("c").call_count == 2
|
40
|
+
assert @engine.get_stats("c").total_call_time == 4
|
41
|
+
|
42
|
+
metric_data = @engine.harvest_timeslice_data({}, {}).values
|
43
|
+
|
44
|
+
# after harvest, all the metrics should be reset
|
45
|
+
assert @engine.get_stats("a").call_count == 0
|
46
|
+
assert @engine.get_stats("a").total_call_time == 0
|
47
|
+
|
48
|
+
assert @engine.get_stats("c").call_count == 0
|
49
|
+
assert @engine.get_stats("c").total_call_time == 0
|
50
|
+
|
51
|
+
metric_data = metric_data.reverse if metric_data[0].metric_spec.name != "a"
|
52
|
+
|
53
|
+
assert metric_data[0].metric_spec.name == "a"
|
54
|
+
|
55
|
+
assert metric_data[0].stats.call_count == 1
|
56
|
+
assert metric_data[0].stats.total_call_time == 10
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_harvest_with_merge
|
60
|
+
s = @engine.get_stats "a"
|
61
|
+
s.trace_call 1
|
62
|
+
|
63
|
+
assert @engine.get_stats("a").call_count == 1
|
64
|
+
|
65
|
+
harvest = @engine.harvest_timeslice_data({}, {})
|
66
|
+
assert s.call_count == 0
|
67
|
+
s.trace_call 2
|
68
|
+
assert s.call_count == 1
|
69
|
+
|
70
|
+
# this calk should merge the contents of the previous harvest,
|
71
|
+
# so the stats for metric "a" should have 2 data points
|
72
|
+
harvest = @engine.harvest_timeslice_data(harvest, {})
|
73
|
+
stats = harvest.fetch(NewRelic::MetricSpec.new("a")).stats
|
74
|
+
assert stats.call_count == 2
|
75
|
+
assert stats.total_call_time == 3
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|