ghazel-newrelic_rpm 3.1.0.1 → 3.4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +120 -35
- data/LICENSE +29 -2
- data/README.rdoc +2 -2
- data/bin/mongrel_rpm +0 -0
- data/bin/newrelic +0 -0
- data/bin/newrelic_cmd +0 -0
- data/lib/new_relic/agent.rb +50 -38
- data/lib/new_relic/agent/agent.rb +459 -337
- data/lib/new_relic/agent/beacon_configuration.rb +71 -11
- data/lib/new_relic/agent/browser_monitoring.rb +73 -14
- data/lib/new_relic/agent/busy_calculator.rb +11 -3
- data/lib/new_relic/agent/chained_call.rb +2 -2
- data/lib/new_relic/agent/database.rb +223 -0
- data/lib/new_relic/agent/error_collector.rb +231 -183
- data/lib/new_relic/agent/instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +10 -2
- data/lib/new_relic/agent/instrumentation/active_record.rb +138 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +7 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +6 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +46 -14
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +11 -3
- data/lib/new_relic/agent/instrumentation/memcache.rb +49 -25
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +7 -2
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +31 -4
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -5
- data/lib/new_relic/agent/instrumentation/net.rb +8 -2
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -2
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +66 -35
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +121 -1
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +21 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -20
- data/lib/new_relic/agent/instrumentation/sunspot.rb +6 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +7 -2
- data/lib/new_relic/agent/method_tracer.rb +205 -99
- data/lib/new_relic/agent/new_relic_service.rb +221 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +161 -0
- data/lib/new_relic/agent/pipe_service.rb +54 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +89 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -7
- data/lib/new_relic/agent/shim_agent.rb +5 -5
- data/lib/new_relic/agent/sql_sampler.rb +282 -0
- data/lib/new_relic/agent/stats_engine.rb +2 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +35 -30
- data/lib/new_relic/agent/stats_engine/samplers.rb +10 -4
- data/lib/new_relic/agent/stats_engine/transactions.rb +28 -87
- data/lib/new_relic/agent/transaction_info.rb +74 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +18 -3
- data/lib/new_relic/agent/transaction_sampler.rb +108 -20
- data/lib/new_relic/agent/worker_loop.rb +14 -6
- data/lib/new_relic/collection_helper.rb +19 -11
- data/lib/new_relic/command.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +2 -2
- data/lib/new_relic/commands/install.rb +2 -13
- data/lib/new_relic/control.rb +2 -3
- data/lib/new_relic/control/class_methods.rb +12 -6
- data/lib/new_relic/control/configuration.rb +57 -8
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +4 -4
- data/lib/new_relic/control/frameworks/merb.rb +2 -1
- data/lib/new_relic/control/frameworks/rails.rb +35 -22
- data/lib/new_relic/control/frameworks/rails3.rb +12 -7
- data/lib/new_relic/control/frameworks/ruby.rb +5 -5
- data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
- data/lib/new_relic/control/instance_methods.rb +38 -12
- data/lib/new_relic/control/instrumentation.rb +23 -4
- data/lib/new_relic/control/logging_methods.rb +70 -15
- data/lib/new_relic/control/server_methods.rb +22 -9
- data/lib/new_relic/delayed_job_injection.rb +16 -3
- data/lib/new_relic/helper.rb +21 -0
- data/lib/new_relic/language_support.rb +95 -0
- data/lib/new_relic/local_environment.rb +92 -48
- data/lib/new_relic/metric_data.rb +7 -2
- data/lib/new_relic/metric_spec.rb +12 -9
- data/lib/new_relic/noticed_error.rb +6 -1
- data/lib/new_relic/rack/browser_monitoring.rb +18 -19
- data/lib/new_relic/rack/developer_mode.rb +3 -2
- data/lib/new_relic/recipes.rb +8 -4
- data/lib/new_relic/stats.rb +17 -60
- data/lib/new_relic/transaction_analysis.rb +2 -1
- data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
- data/lib/new_relic/transaction_sample.rb +60 -75
- data/lib/new_relic/transaction_sample/segment.rb +31 -79
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +1 -1
- data/newrelic.yml +2 -2
- data/newrelic_rpm.gemspec +46 -54
- data/test/active_record_fixtures.rb +3 -3
- data/test/config/newrelic.yml +1 -1
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/new_relic/agent/agent/connect_test.rb +128 -25
- data/test/new_relic/agent/agent/start_test.rb +9 -94
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -4
- data/test/new_relic/agent/agent_test.rb +51 -78
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +49 -33
- data/test/new_relic/agent/beacon_configuration_test.rb +12 -5
- data/test/new_relic/agent/browser_monitoring_test.rb +99 -50
- data/test/new_relic/agent/database_test.rb +161 -0
- data/test/new_relic/agent/error_collector_test.rb +47 -23
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +96 -42
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -11
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +9 -9
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +6 -11
- data/test/new_relic/agent/memcache_instrumentation_test.rb +54 -18
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
- data/test/new_relic/agent/method_tracer_test.rb +3 -2
- data/test/new_relic/agent/new_relic_service_test.rb +151 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +114 -0
- data/test/new_relic/agent/pipe_service_test.rb +113 -0
- data/test/new_relic/agent/rpm_agent_test.rb +4 -31
- data/test/new_relic/agent/sql_sampler_test.rb +192 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +19 -18
- data/test/new_relic/agent/stats_engine_test.rb +41 -6
- data/test/new_relic/agent/transaction_info_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +27 -4
- data/test/new_relic/agent/transaction_sampler_test.rb +68 -46
- data/test/new_relic/agent/worker_loop_test.rb +3 -3
- data/test/new_relic/agent_test.rb +242 -0
- data/test/new_relic/collection_helper_test.rb +50 -28
- data/test/new_relic/control/configuration_test.rb +77 -0
- data/test/new_relic/control/logging_methods_test.rb +49 -21
- data/test/new_relic/control_test.rb +115 -54
- data/test/new_relic/delayed_job_injection_test.rb +21 -0
- data/test/new_relic/fake_collector.rb +210 -0
- data/test/new_relic/fake_service.rb +44 -0
- data/test/new_relic/local_environment_test.rb +14 -1
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +84 -23
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +31 -0
- data/test/new_relic/stats_test.rb +3 -18
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
- data/test/new_relic/transaction_analysis_test.rb +3 -3
- data/test/new_relic/transaction_sample/segment_test.rb +15 -80
- data/test/new_relic/transaction_sample_test.rb +25 -18
- data/test/script/build_test_gem.sh +51 -0
- data/test/script/ci.sh +140 -0
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +1 -0
- data/test/test_helper.rb +18 -5
- data/ui/helpers/developer_mode_helper.rb +14 -8
- data/ui/helpers/google_pie_chart.rb +0 -1
- data/ui/views/newrelic/index.rhtml +2 -2
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +10 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +17 -4
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
- metadata +50 -36
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +0 -108
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +0 -112
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
- data/lib/new_relic/data_serialization.rb +0 -84
- data/lib/new_relic/histogram.rb +0 -91
- data/lib/new_relic/rack/metric_app.rb +0 -65
- data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
- data/lib/new_relic/rack/newrelic.yml +0 -27
- data/lib/new_relic/rack_app.rb +0 -6
- data/test/new_relic/data_serialization_test.rb +0 -70
- data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
@@ -12,7 +12,6 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Test::Un
|
|
12
12
|
object.expects(:newrelic_request_headers).returns({:request => 'headers'}).twice
|
13
13
|
object.expects(:parse_frontend_headers).with({:request => 'headers'}).returns(start_time)
|
14
14
|
assert_equal(start_time, object.send(:_detect_upstream_wait, start_time))
|
15
|
-
assert_equal(0.0, Thread.current[:newrelic_queue_time])
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_detect_upstream_wait_with_upstream
|
@@ -22,7 +21,6 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Test::Un
|
|
22
21
|
object.expects(:newrelic_request_headers).returns(true).twice
|
23
22
|
object.expects(:parse_frontend_headers).returns(start_time)
|
24
23
|
assert_equal(start_time, object.send(:_detect_upstream_wait, runs_at))
|
25
|
-
assert_equal(1.0, Thread.current[:newrelic_queue_time])
|
26
24
|
end
|
27
25
|
|
28
26
|
def test_detect_upstream_wait_swallows_errors
|
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'te
|
|
2
2
|
class NewRelic::Agent::Instrumentation::InstrumentationTest < Test::Unit::TestCase
|
3
3
|
def test_load_all_instrumentation_files
|
4
4
|
# just checking for syntax errors and unguarded code
|
5
|
-
Dir.glob(
|
5
|
+
Dir.glob('new_relic/agent/instrumentation/**/*.rb') do |f|
|
6
6
|
require f
|
7
7
|
end
|
8
8
|
require 'new_relic/delayed_job_injection'
|
@@ -5,14 +5,15 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
|
|
5
5
|
|
6
6
|
attr_reader :agent
|
7
7
|
attr_reader :transaction_sampler
|
8
|
+
attr_reader :sql_sampler
|
8
9
|
|
9
10
|
def setup
|
10
11
|
@agent = mock('agent')
|
11
12
|
@transaction_sampler = mock('transaction sampler')
|
13
|
+
@sql_sampler = mock('sql sampler')
|
12
14
|
end
|
13
15
|
|
14
16
|
def teardown
|
15
|
-
Thread.current[:newrelic_start_time] = nil
|
16
17
|
Thread.current[:newrelic_metric_frame] = nil
|
17
18
|
end
|
18
19
|
|
@@ -37,16 +38,9 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
|
|
37
38
|
log_underflow
|
38
39
|
end
|
39
40
|
|
40
|
-
def test_process_histogram_for_transaction
|
41
|
-
fakehistogram = mock('histogram')
|
42
|
-
agent.expects(:histogram).returns(fakehistogram)
|
43
|
-
self.expects(:start).returns(2)
|
44
|
-
fakehistogram.expects(:process).with(1.0)
|
45
|
-
process_histogram_for_transaction(3)
|
46
|
-
end
|
47
|
-
|
48
41
|
def test_notice_scope_empty
|
49
42
|
transaction_sampler.expects(:notice_scope_empty)
|
43
|
+
sql_sampler.expects(:notice_scope_empty)
|
50
44
|
notice_scope_empty
|
51
45
|
end
|
52
46
|
|
@@ -115,14 +109,12 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
|
|
115
109
|
|
116
110
|
def test_notify_transaction_sampler_true
|
117
111
|
self.expects(:record_transaction_cpu)
|
118
|
-
self.expects(:process_histogram_for_transaction)
|
119
112
|
self.expects(:notice_scope_empty)
|
120
113
|
notify_transaction_sampler(true)
|
121
114
|
end
|
122
115
|
|
123
116
|
def test_notify_transaction_sampler_false
|
124
117
|
self.expects(:record_transaction_cpu)
|
125
|
-
self.expects(:process_histogram_for_transaction).never
|
126
118
|
self.expects(:notice_scope_empty)
|
127
119
|
notify_transaction_sampler(false)
|
128
120
|
end
|
@@ -20,8 +20,8 @@ unless ENV['FAST_TESTS']
|
|
20
20
|
res = Net::HTTP.start(url.host, url.port) {|http|
|
21
21
|
http.get('/index.html')
|
22
22
|
}
|
23
|
-
assert_match /<head
|
24
|
-
assert_equal %w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort,
|
23
|
+
assert_match /<head>/i, res.body
|
24
|
+
assert_equal %w[External/all External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort,
|
25
25
|
metrics_without_gc.sort
|
26
26
|
end
|
27
27
|
|
@@ -31,9 +31,9 @@ unless ENV['FAST_TESTS']
|
|
31
31
|
res = Net::HTTP.start(url.host, url.port) {|http|
|
32
32
|
http.get('/index.html')
|
33
33
|
}
|
34
|
-
assert_match /<head
|
34
|
+
assert_match /<head>/i, res.body
|
35
35
|
end
|
36
|
-
assert_equal %w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all
|
36
|
+
assert_equal %w[External/all External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all
|
37
37
|
External/www.google.com/Net::HTTP/GET:OtherTransaction/Background/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task].sort, metrics_without_gc.select{|m| m =~ /^External/}.sort
|
38
38
|
end
|
39
39
|
|
@@ -43,15 +43,15 @@ unless ENV['FAST_TESTS']
|
|
43
43
|
res = Net::HTTP.start(url.host, url.port) {|http|
|
44
44
|
http.get('/index.html')
|
45
45
|
}
|
46
|
-
assert_match /<head
|
46
|
+
assert_match /<head>/i, res.body
|
47
47
|
end
|
48
|
-
assert_equal %w[External/www.google.com/Net::HTTP/GET External/allWeb External/www.google.com/all
|
48
|
+
assert_equal %w[External/all External/www.google.com/Net::HTTP/GET External/allWeb External/www.google.com/all
|
49
49
|
External/www.google.com/Net::HTTP/GET:Controller/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task].sort, metrics_without_gc.select{|m| m =~ /^External/}.sort
|
50
50
|
end
|
51
51
|
def test_get__simple
|
52
52
|
Net::HTTP.get URI.parse('http://www.google.com/index.html')
|
53
53
|
assert_equal metrics_without_gc.sort,
|
54
|
-
%w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort
|
54
|
+
%w[External/all External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort
|
55
55
|
end
|
56
56
|
def test_ignore
|
57
57
|
NewRelic::Agent.disable_all_tracing do
|
@@ -67,7 +67,7 @@ unless ENV['FAST_TESTS']
|
|
67
67
|
res = Net::HTTP.start(url.host, url.port) {|http|
|
68
68
|
http.head('/index.html')
|
69
69
|
}
|
70
|
-
assert_equal %w[External/www.google.com/Net::HTTP/HEAD External/allOther External/www.google.com/all].sort,
|
70
|
+
assert_equal %w[External/all External/www.google.com/Net::HTTP/HEAD External/allOther External/www.google.com/all].sort,
|
71
71
|
metrics_without_gc.sort
|
72
72
|
end
|
73
73
|
|
@@ -76,7 +76,7 @@ unless ENV['FAST_TESTS']
|
|
76
76
|
res = Net::HTTP.start(url.host, url.port) {|http|
|
77
77
|
http.post('/index.html','data')
|
78
78
|
}
|
79
|
-
assert_equal %w[External/www.google.com/Net::HTTP/POST External/allOther External/www.google.com/all].sort,
|
79
|
+
assert_equal %w[External/all External/www.google.com/Net::HTTP/POST External/allOther External/www.google.com/all].sort,
|
80
80
|
metrics_without_gc.sort
|
81
81
|
end
|
82
82
|
|
@@ -270,20 +270,15 @@ class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
|
|
270
270
|
check_metric_time('WebFrontend/QueueTime', 0.0, 0.001)
|
271
271
|
end
|
272
272
|
|
273
|
-
|
274
|
-
# check all the combinations to make sure that ordering doesn't
|
275
|
-
# affect the return value
|
276
273
|
def test_find_oldest_time
|
277
|
-
|
274
|
+
test_array = [
|
275
|
+
['c', Time.at(1002)],
|
278
276
|
['a', Time.at(1000)],
|
279
277
|
['b', Time.at(1001)],
|
280
|
-
['c', Time.at(1002)],
|
281
278
|
['d', Time.at(1000)],
|
282
279
|
]
|
283
|
-
|
284
|
-
|
285
|
-
assert_equal find_oldest_time(test_array), Time.at(1000), "Should be the oldest time in the array"
|
286
|
-
end
|
280
|
+
assert_equal(find_oldest_time(test_array), Time.at(1000),
|
281
|
+
"Should be the oldest time in the array")
|
287
282
|
end
|
288
283
|
|
289
284
|
# trivial test but the method doesn't do much
|
@@ -306,9 +301,9 @@ class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
|
|
306
301
|
end
|
307
302
|
|
308
303
|
def test_record_time_stat_with_end_after_start
|
309
|
-
record_time_stat('WebFrontend/WebServer/foo',
|
304
|
+
record_time_stat('WebFrontend/WebServer/foo', Time.at(1.0001), Time.at(1))
|
310
305
|
rescue RuntimeError => e
|
311
|
-
|
306
|
+
assert_match(/should not provide an end time less than start time/, e.message)
|
312
307
|
end
|
313
308
|
|
314
309
|
def test_convert_to_microseconds
|
@@ -2,8 +2,10 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
|
|
2
2
|
|
3
3
|
memcached_ready = false
|
4
4
|
classes = {
|
5
|
-
|
6
|
-
|
5
|
+
# 'memcache' => 'MemCache',
|
6
|
+
# 'dalli' => 'Dalli::Client',
|
7
|
+
'memcached' => 'Memcached'
|
8
|
+
# 'spymemcached' => 'Spymemcached'
|
7
9
|
}
|
8
10
|
begin
|
9
11
|
TCPSocket.new('localhost', 11211)
|
@@ -23,16 +25,34 @@ end
|
|
23
25
|
|
24
26
|
class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
|
25
27
|
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
26
|
-
|
28
|
+
|
27
29
|
def setup
|
28
30
|
NewRelic::Agent.manual_start
|
29
31
|
@engine = NewRelic::Agent.instance.stats_engine
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
|
33
|
+
case MEMCACHED_CLASS.name
|
34
|
+
when 'Memcached'
|
35
|
+
@cache = MEMCACHED_CLASS.new('localhost', :support_cas => true)
|
36
|
+
when 'Spymemcached'
|
37
|
+
@cache = MEMCACHED_CLASS.new('localhost:11211')
|
38
|
+
else
|
39
|
+
@cache = MEMCACHED_CLASS.new('localhost')
|
40
|
+
end
|
33
41
|
@key = 'schluessel'
|
42
|
+
@cache.set('schluessel', 1)
|
34
43
|
end
|
35
|
-
|
44
|
+
|
45
|
+
def teardown
|
46
|
+
if MEMCACHED_CLASS.name == 'Memcached'
|
47
|
+
@cache.flush
|
48
|
+
elsif MEMCACHED_CLASS.name == 'Spymemcached'
|
49
|
+
@cache.flush
|
50
|
+
@cache.instance_eval{ @client.shutdown }
|
51
|
+
else
|
52
|
+
@cache.flush_all
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
36
56
|
def _call_test_method_in_web_transaction(method, *args)
|
37
57
|
@engine.clear_stats
|
38
58
|
perform_action_with_newrelic_trace(:name=>'action', :category => :controller) do
|
@@ -48,27 +68,30 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
|
|
48
68
|
end
|
49
69
|
|
50
70
|
def test_reads__web
|
51
|
-
|
71
|
+
commands = ['get']
|
72
|
+
commands << 'get_multi' unless MEMCACHED_CLASS.name == 'Spymemcached'
|
73
|
+
commands.each do |method|
|
52
74
|
if @cache.class.method_defined?(method)
|
53
75
|
_call_test_method_in_web_transaction(method)
|
54
|
-
compare_metrics ["
|
76
|
+
compare_metrics ["Memcache/#{method}", "Memcache/allWeb", "Memcache/#{method}:Controller/NewRelic::Agent::MemcacheInstrumentationTest/action"],
|
55
77
|
@engine.metrics.select{|m| m =~ /^memcache.*/i}
|
56
78
|
end
|
57
79
|
end
|
58
80
|
end
|
59
81
|
|
60
82
|
def test_writes__web
|
61
|
-
%w[
|
83
|
+
%w[delete].each do |method|
|
62
84
|
if @cache.class.method_defined?(method)
|
63
85
|
_call_test_method_in_web_transaction(method)
|
64
|
-
expected_metrics = ["
|
86
|
+
expected_metrics = ["Memcache/#{method}", "Memcache/allWeb", "Memcache/#{method}:Controller/NewRelic::Agent::MemcacheInstrumentationTest/action"]
|
65
87
|
compare_metrics expected_metrics, @engine.metrics.select{|m| m =~ /^memcache.*/i}
|
66
88
|
end
|
67
89
|
end
|
68
90
|
|
69
91
|
%w[set add].each do |method|
|
92
|
+
@cache.delete(@key) rescue nil
|
70
93
|
if @cache.class.method_defined?(method)
|
71
|
-
expected_metrics = ["
|
94
|
+
expected_metrics = ["Memcache/#{method}", "Memcache/allWeb", "Memcache/#{method}:Controller/NewRelic::Agent::MemcacheInstrumentationTest/action"]
|
72
95
|
_call_test_method_in_web_transaction(method, 'value')
|
73
96
|
compare_metrics expected_metrics, @engine.metrics.select{|m| m =~ /^memcache.*/i}
|
74
97
|
end
|
@@ -76,19 +99,20 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
|
|
76
99
|
end
|
77
100
|
|
78
101
|
def test_reads__background
|
79
|
-
|
102
|
+
commands = ['get']
|
103
|
+
commands << 'get_multi' unless MEMCACHED_CLASS.name == 'Spymemcached'
|
104
|
+
commands.each do |method|
|
80
105
|
if @cache.class.method_defined?(method)
|
81
106
|
_call_test_method_in_background_task(method)
|
82
|
-
compare_metrics ["
|
107
|
+
compare_metrics ["Memcache/#{method}", "Memcache/allOther", "Memcache/#{method}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"],
|
83
108
|
@engine.metrics.select{|m| m =~ /^memcache.*/i}
|
84
109
|
end
|
85
110
|
end
|
86
111
|
end
|
87
112
|
|
88
113
|
def test_writes__background
|
89
|
-
|
90
|
-
|
91
|
-
expected_metrics = ["MemCache/#{method}", "MemCache/allOther", "MemCache/#{method}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"]
|
114
|
+
%w[delete].each do |method|
|
115
|
+
expected_metrics = ["Memcache/#{method}", "Memcache/allOther", "Memcache/#{method}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"]
|
92
116
|
if @cache.class.method_defined?(method)
|
93
117
|
_call_test_method_in_background_task(method)
|
94
118
|
compare_metrics expected_metrics, @engine.metrics.select{|m| m =~ /^memcache.*/i}
|
@@ -96,7 +120,8 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
|
|
96
120
|
end
|
97
121
|
|
98
122
|
%w[set add].each do |method|
|
99
|
-
|
123
|
+
@cache.delete(@key) rescue nil
|
124
|
+
expected_metrics = ["Memcache/#{method}", "Memcache/allOther", "Memcache/#{method}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"]
|
100
125
|
if @cache.class.method_defined?(method)
|
101
126
|
_call_test_method_in_background_task(method, 'value')
|
102
127
|
compare_metrics expected_metrics, @engine.metrics.select{|m| m =~ /^memcache.*/i}
|
@@ -104,4 +129,15 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
|
|
104
129
|
end
|
105
130
|
end
|
106
131
|
|
132
|
+
def test_handles_cas
|
133
|
+
expected_metrics = ["Memcache/cas", "Memcache/allOther", "Memcache/cas:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"]
|
134
|
+
if @cache.class.method_defined?(:cas)
|
135
|
+
@engine.clear_stats
|
136
|
+
perform_action_with_newrelic_trace(:name => 'bg_task', :category => :task) do
|
137
|
+
@cache.cas(@key) {|val| val += 2 }
|
138
|
+
end
|
139
|
+
compare_metrics expected_metrics, @engine.metrics.select{|m| m =~ /^memcache.*/i}
|
140
|
+
assert_equal 3, @cache.get(@key)
|
141
|
+
end
|
142
|
+
end
|
107
143
|
end if memcached_ready
|
@@ -206,7 +206,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
|
|
206
206
|
assert_raises(RuntimeError) do
|
207
207
|
trace_execution_scoped(['metric', 'array'], passed_in_opts) do
|
208
208
|
ran = true
|
209
|
-
raise '
|
209
|
+
raise 'raising a test error'
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
@@ -244,6 +244,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
244
244
|
t1 = Time.now
|
245
245
|
method_with_block(1,2,3,true,METRIC) do |scope|
|
246
246
|
assert scope == METRIC
|
247
|
+
sleep 0.1 # pad the test a bit to increase the margin of error
|
247
248
|
end
|
248
249
|
elapsed = Time.now - t1
|
249
250
|
|
@@ -309,11 +310,11 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
309
310
|
metric = "hey"
|
310
311
|
self.class.trace_execution_scoped metric do
|
311
312
|
assert @stats_engine.peek_scope.name == metric
|
312
|
-
throw
|
313
|
+
throw StandardError.new
|
313
314
|
end
|
314
315
|
|
315
316
|
assert false # should never get here
|
316
|
-
rescue
|
317
|
+
rescue StandardError
|
317
318
|
# make sure the scope gets popped
|
318
319
|
assert @stats_engine.peek_scope == nil
|
319
320
|
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
|
2
|
+
|
3
|
+
class NewRelicServiceTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@server = NewRelic::Control::Server.new('127.0.0.1', 30303)
|
6
|
+
@service = NewRelic::Agent::NewRelicService.new('license-key', @server)
|
7
|
+
@http_handle = HTTPHandle.new
|
8
|
+
NewRelic::Control.instance.stubs(:http_connection).returns(@http_handle)
|
9
|
+
@http_handle.respond_to(:get_redirect_host, 'localhost')
|
10
|
+
connect_response = {
|
11
|
+
'config' => 'some config directives',
|
12
|
+
'agent_run_id' => 1
|
13
|
+
}
|
14
|
+
@http_handle.respond_to(:connect, connect_response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_connect_sets_agent_id_and_config_data
|
18
|
+
response = @service.connect
|
19
|
+
assert_equal 1, response['agent_run_id']
|
20
|
+
assert_equal 'some config directives', response['config']
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_connect_sets_redirect_host
|
24
|
+
assert_equal '127.0.0.1', @service.collector.name
|
25
|
+
@service.connect
|
26
|
+
assert_equal 'localhost', @service.collector.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_connect_uses_proxy_collector_if_no_redirect_host
|
30
|
+
@http_handle.reset
|
31
|
+
@http_handle.respond_to(:get_redirect_host, nil)
|
32
|
+
@http_handle.respond_to(:connect, {'agent_run_id' => 1})
|
33
|
+
|
34
|
+
@service.connect
|
35
|
+
assert_equal '127.0.0.1', @service.collector.name
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_connect_sets_agent_id
|
39
|
+
@http_handle.reset
|
40
|
+
@http_handle.respond_to(:get_redirect_host, 'localhost')
|
41
|
+
@http_handle.respond_to(:connect, {'agent_run_id' => 666})
|
42
|
+
|
43
|
+
@service.connect
|
44
|
+
assert_equal 666, @service.agent_id
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_get_redirect_host
|
48
|
+
host = @service.get_redirect_host
|
49
|
+
assert_equal 'localhost', host
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_shutdown
|
53
|
+
@service.agent_id = 666
|
54
|
+
@http_handle.respond_to(:shutdown, 'shut this bird down')
|
55
|
+
response = @service.shutdown(Time.now)
|
56
|
+
assert_equal 'shut this bird down', response
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_should_not_shutdown_if_never_connected
|
60
|
+
@http_handle.respond_to(:shutdown, 'shut this bird down')
|
61
|
+
response = @service.shutdown(Time.now)
|
62
|
+
assert_nil response
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_metric_data
|
66
|
+
@http_handle.respond_to(:metric_data, 'met rick date uhhh')
|
67
|
+
response = @service.metric_data(Time.now - 60, Time.now, {})
|
68
|
+
assert_equal 'met rick date uhhh', response
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_error_data
|
72
|
+
@http_handle.respond_to(:error_data, 'too human')
|
73
|
+
response = @service.error_data([])
|
74
|
+
assert_equal 'too human', response
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_transaction_sample_data
|
78
|
+
@http_handle.respond_to(:transaction_sample_data, 'MPC1000')
|
79
|
+
response = @service.transaction_sample_data([])
|
80
|
+
assert_equal 'MPC1000', response
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_sql_trace_data
|
84
|
+
@http_handle.respond_to(:sql_trace_data, 'explain this')
|
85
|
+
response = @service.sql_trace_data([])
|
86
|
+
assert_equal 'explain this', response
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_request_timeout
|
90
|
+
NewRelic::Control.instance['timeout'] = 600
|
91
|
+
service = NewRelic::Agent::NewRelicService.new('abcdef', @server)
|
92
|
+
assert_equal 600, service.request_timeout
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_should_throw_received_errors
|
96
|
+
assert_raise NewRelic::Agent::ServerConnectionException do
|
97
|
+
@service.send(:invoke_remote, :bogus_method)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class HTTPHandle
|
102
|
+
attr_accessor :read_timeout, :route_table
|
103
|
+
|
104
|
+
def initialize
|
105
|
+
reset
|
106
|
+
end
|
107
|
+
|
108
|
+
def respond_to(method, payload)
|
109
|
+
register(HTTPResponse.new(Marshal.dump(payload))) do |request|
|
110
|
+
request.path.include?(method.to_s)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def register(response, &block)
|
115
|
+
@route_table[block] = response
|
116
|
+
end
|
117
|
+
|
118
|
+
def request(*args)
|
119
|
+
@route_table.each_pair do |condition, response|
|
120
|
+
if condition.call(args[0])
|
121
|
+
return response
|
122
|
+
end
|
123
|
+
end
|
124
|
+
HTTPFailure.new('not found', 404)
|
125
|
+
end
|
126
|
+
|
127
|
+
def reset
|
128
|
+
@route_table = {}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
module HTTPResponseMock
|
133
|
+
attr_accessor :code, :body, :message, :headers
|
134
|
+
|
135
|
+
def initialize(body, code=200, message='OK')
|
136
|
+
@code = code
|
137
|
+
@body = body
|
138
|
+
@message = message
|
139
|
+
@headers = {}
|
140
|
+
end
|
141
|
+
|
142
|
+
def [](key)
|
143
|
+
@headers[key]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
HTTPResponse = Class.new(Net::HTTPOK)
|
148
|
+
HTTPResponse.class_eval { include HTTPResponseMock }
|
149
|
+
HTTPFailure = Class.new(Net::HTTPError)
|
150
|
+
HTTPFailure.class_eval { include HTTPResponseMock }
|
151
|
+
end
|