newrelic_rpm 3.6.0.83 → 3.6.1.85.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +27 -0
- data/Gemfile +2 -7
- data/README.md +1 -1
- data/lib/new_relic/agent/agent.rb +3 -2
- data/lib/new_relic/agent/autostart.rb +56 -0
- data/lib/new_relic/agent/browser_monitoring.rb +19 -14
- data/lib/new_relic/agent/configuration/defaults.rb +12 -2
- data/lib/new_relic/agent/configuration/environment_source.rb +4 -1
- data/lib/new_relic/agent/cross_app_monitor.rb +2 -1
- data/lib/new_relic/agent/cross_app_tracing.rb +19 -10
- data/lib/new_relic/agent/error_collector.rb +5 -4
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +204 -0
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +88 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +84 -0
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +3 -2
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +104 -87
- data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +91 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +20 -20
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -5
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +3 -3
- data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +3 -25
- data/lib/new_relic/agent/instrumentation/rails4/action_view.rb +2 -115
- data/lib/new_relic/agent/instrumentation/rails4/active_record.rb +2 -82
- data/lib/new_relic/agent/instrumentation/rails4/errors.rb +3 -4
- data/lib/new_relic/agent/method_tracer.rb +93 -56
- data/lib/new_relic/agent/null_logger.rb +6 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +9 -4
- data/lib/new_relic/agent/sql_sampler.rb +10 -6
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +19 -3
- data/lib/new_relic/agent/stats_engine/transactions.rb +53 -34
- data/lib/new_relic/agent/system_info.rb +54 -0
- data/lib/new_relic/agent/thread.rb +2 -2
- data/lib/new_relic/agent/transaction/pop.rb +52 -0
- data/lib/new_relic/agent/transaction.rb +388 -0
- data/lib/new_relic/agent/transaction_info.rb +5 -13
- data/lib/new_relic/agent/transaction_sample_builder.rb +13 -20
- data/lib/new_relic/agent/transaction_sampler.rb +13 -15
- data/lib/new_relic/agent/uri_util.rb +35 -0
- data/lib/new_relic/agent.rb +54 -11
- data/lib/new_relic/build.rb +2 -2
- data/lib/new_relic/control/frameworks/rails.rb +0 -1
- data/lib/new_relic/control/frameworks/rails3.rb +2 -0
- data/lib/new_relic/control/frameworks/rails4.rb +0 -4
- data/lib/new_relic/control/instance_methods.rb +5 -19
- data/lib/new_relic/control/server_methods.rb +2 -0
- data/lib/new_relic/environment_report.rb +4 -34
- data/lib/new_relic/latest_changes.rb +1 -1
- data/lib/new_relic/local_environment.rb +0 -6
- data/lib/new_relic/metric_spec.rb +2 -2
- data/lib/new_relic/rack/error_collector.rb +6 -4
- data/lib/new_relic/transaction_sample.rb +7 -1
- data/lib/new_relic/version.rb +1 -1
- data/lib/newrelic_rpm.rb +2 -2
- data/newrelic.yml +20 -20
- data/test/config/test_control.rb +2 -2
- data/test/multiverse/suites/agent_only/audit_log_test.rb +1 -1
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +0 -2
- data/test/multiverse/suites/agent_only/logging_test.rb +1 -1
- data/test/multiverse/suites/agent_only/marshaling_test.rb +5 -3
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +2 -0
- data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +96 -0
- data/test/multiverse/suites/agent_only/testing_app.rb +1 -0
- data/test/multiverse/suites/rails/error_tracing_test.rb +17 -29
- data/test/multiverse/suites/rails/queue_time_test.rb +8 -2
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -3
- data/test/multiverse/suites/resque/instrumentation_test.rb +1 -1
- data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +8 -0
- data/test/new_relic/agent/agent/connect_test.rb +2 -1
- data/test/new_relic/agent/agent/start_test.rb +0 -10
- data/test/new_relic/agent/agent_logger_test.rb +15 -0
- data/test/new_relic/agent/agent_test_controller.rb +6 -2
- data/test/new_relic/agent/agent_test_controller_test.rb +20 -69
- data/test/new_relic/agent/autostart_test.rb +67 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +60 -38
- data/test/new_relic/agent/configuration/environment_source_test.rb +19 -17
- data/test/new_relic/agent/cross_app_monitor_test.rb +8 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +0 -5
- data/test/new_relic/agent/error_collector_test.rb +8 -9
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +228 -0
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +18 -34
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +5 -5
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +8 -9
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +24 -38
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +126 -178
- data/test/new_relic/agent/instrumentation/rack_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +135 -151
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +153 -81
- data/test/new_relic/agent/method_tracer_test.rb +42 -33
- data/test/new_relic/agent/mock_scope_listener.rb +4 -4
- data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -2
- data/test/new_relic/agent/rpm_agent_test.rb +86 -89
- data/test/new_relic/agent/sql_sampler_test.rb +18 -19
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +5 -8
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +20 -8
- data/test/new_relic/agent/stats_engine/samplers_test.rb +31 -14
- data/test/new_relic/agent/stats_engine_test.rb +53 -60
- data/test/new_relic/agent/thread_test.rb +7 -7
- data/test/new_relic/agent/transaction/pop_test.rb +96 -0
- data/test/new_relic/agent/transaction_info_test.rb +6 -17
- data/test/new_relic/agent/transaction_sample_builder_test.rb +10 -18
- data/test/new_relic/agent/transaction_sampler_test.rb +80 -75
- data/test/new_relic/agent/{instrumentation/metric_frame_test.rb → transaction_test.rb} +76 -42
- data/test/new_relic/agent/uri_util_test.rb +75 -0
- data/test/new_relic/agent_test.rb +115 -9
- data/test/test_helper.rb +138 -9
- data.tar.gz.sig +0 -0
- metadata +37 -74
- metadata.gz.sig +0 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +0 -84
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +0 -353
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +0 -175
- data/test/test_contexts.rb +0 -34
@@ -37,23 +37,35 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
def test_cpu_sampler_records_user_and_system_time
|
41
|
+
timeinfo0 = mock
|
42
|
+
timeinfo0.stubs(:utime).returns(10.0)
|
43
|
+
timeinfo0.stubs(:stime).returns(5.0)
|
44
|
+
|
45
|
+
timeinfo1 = mock
|
46
|
+
timeinfo1.stubs(:utime).returns(14.0) # +5s
|
47
|
+
timeinfo1.stubs(:stime).returns(7.0) # +2s
|
48
|
+
|
49
|
+
elapsed = 10
|
50
|
+
|
51
|
+
freeze_time
|
52
|
+
Process.stubs(:times).returns(timeinfo0, timeinfo1)
|
53
|
+
NewRelic::Agent::SystemInfo.stubs(:processor_count).returns(4)
|
54
|
+
|
55
|
+
s = NewRelic::Agent::Samplers::CpuSampler.new # this calls poll
|
56
|
+
advance_time(elapsed)
|
48
57
|
s.poll
|
49
58
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
59
|
+
assert_metrics_recorded({
|
60
|
+
'CPU/User Time' => { :call_count => 1, :total_call_time => 4.0 },
|
61
|
+
'CPU/System Time' => { :call_count => 1, :total_call_time => 2.0 },
|
62
|
+
# (4s user time) / ((10s elapsed time) * 4 cpus) = 0.1
|
63
|
+
'CPU/User/Utilization' => { :call_count => 1, :total_call_time => 0.1 },
|
64
|
+
# (2s system time) / ((10s elapsed time) * 4 cpus) = 0.05
|
65
|
+
'CPU/System/Utilization' => { :call_count => 1, :total_call_time => 0.05 }
|
66
|
+
})
|
56
67
|
end
|
68
|
+
|
57
69
|
def test_memory__default
|
58
70
|
s = NewRelic::Agent::Samplers::MemorySampler.new
|
59
71
|
s.stats_engine = @stats_engine
|
@@ -64,6 +76,7 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
|
64
76
|
assert_equal(3, stats.call_count)
|
65
77
|
assert stats.total_call_time > 0.5, "cpu greater than 0.5 ms: #{stats.total_call_time}"
|
66
78
|
end
|
79
|
+
|
67
80
|
def test_memory__linux
|
68
81
|
return if RUBY_PLATFORM =~ /darwin/
|
69
82
|
NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'linux'
|
@@ -76,6 +89,7 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
|
76
89
|
assert_equal 3, stats.call_count
|
77
90
|
assert stats.total_call_time > 0.5, "cpu greater than 0.5 ms: #{stats.total_call_time}"
|
78
91
|
end
|
92
|
+
|
79
93
|
def test_memory__solaris
|
80
94
|
return if defined? JRuby
|
81
95
|
NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'solaris'
|
@@ -87,6 +101,7 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
|
87
101
|
assert_equal 1, stats.call_count
|
88
102
|
assert_equal 999, stats.total_call_time
|
89
103
|
end
|
104
|
+
|
90
105
|
def test_memory__windows
|
91
106
|
return if defined? JRuby
|
92
107
|
NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'win32'
|
@@ -94,6 +109,7 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
|
94
109
|
NewRelic::Agent::Samplers::MemorySampler.new
|
95
110
|
end
|
96
111
|
end
|
112
|
+
|
97
113
|
def test_load_samplers
|
98
114
|
@stats_engine.expects(:add_harvest_sampler).at_least_once unless defined? JRuby
|
99
115
|
@stats_engine.expects(:add_sampler).never
|
@@ -101,6 +117,7 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
|
101
117
|
sampler_count = 4
|
102
118
|
assert_equal sampler_count, NewRelic::Agent::Sampler.sampler_classes.size, NewRelic::Agent::Sampler.sampler_classes.inspect
|
103
119
|
end
|
120
|
+
|
104
121
|
def test_memory__is_supported
|
105
122
|
NewRelic::Agent::Samplers::MemorySampler.stubs(:platform).returns 'windows'
|
106
123
|
assert !NewRelic::Agent::Samplers::MemorySampler.supported_on_this_platform? || defined? JRuby
|
@@ -21,11 +21,11 @@ class NewRelic::Agent::StatsEngineTest < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_scope
|
24
|
-
@engine.push_scope
|
25
|
-
|
24
|
+
@engine.push_scope(:scope1)
|
25
|
+
assert_equal 1, @engine.scope_stack.size
|
26
26
|
|
27
|
-
expected = @engine.push_scope
|
28
|
-
@engine.pop_scope
|
27
|
+
expected = @engine.push_scope(:scope2)
|
28
|
+
@engine.pop_scope(expected, "name 2")
|
29
29
|
|
30
30
|
scoped = @engine.get_stats "a"
|
31
31
|
scoped.trace_call 3
|
@@ -40,32 +40,30 @@ class NewRelic::Agent::StatsEngineTest < Test::Unit::TestCase
|
|
40
40
|
def test_scope__overlap
|
41
41
|
NewRelic::Agent.instance.stubs(:stats_engine).returns(@engine)
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
in_transaction('orlando') do
|
44
|
+
self.class.trace_execution_scoped('disney', :deduct_call_time_from_parent => false) { sleep 0.1 }
|
45
|
+
end
|
46
|
+
orlando_disney = @engine.lookup_stats('disney', 'orlando')
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
in_transaction('anaheim') do
|
49
|
+
self.class.trace_execution_scoped('disney', :deduct_call_time_from_parent => false) { sleep 0.11 }
|
50
|
+
end
|
51
|
+
anaheim_disney = @engine.lookup_stats('disney', 'anaheim')
|
50
52
|
|
51
|
-
disney = @engine.
|
53
|
+
disney = @engine.lookup_stats("disney")
|
52
54
|
|
53
55
|
assert_not_same orlando_disney, anaheim_disney
|
54
56
|
assert_not_equal orlando_disney, anaheim_disney
|
55
57
|
assert_equal 1, orlando_disney.call_count
|
56
58
|
assert_equal 1, anaheim_disney.call_count
|
57
|
-
assert_same disney, orlando_disney.unscoped_stats
|
58
|
-
assert_same disney, anaheim_disney.unscoped_stats
|
59
59
|
assert_equal 2, disney.call_count
|
60
60
|
assert_equal disney.total_call_time, orlando_disney.total_call_time + anaheim_disney.total_call_time
|
61
|
-
|
62
61
|
end
|
63
62
|
|
64
63
|
def test_simplethrowcase(depth=0)
|
65
|
-
|
66
64
|
fail "doh" if depth == 10
|
67
65
|
|
68
|
-
scope = @engine.push_scope
|
66
|
+
scope = @engine.push_scope(:"scope#{depth}")
|
69
67
|
|
70
68
|
begin
|
71
69
|
test_simplethrowcase(depth+1)
|
@@ -74,90 +72,85 @@ class NewRelic::Agent::StatsEngineTest < Test::Unit::TestCase
|
|
74
72
|
raise e
|
75
73
|
end
|
76
74
|
ensure
|
77
|
-
@engine.pop_scope
|
75
|
+
@engine.pop_scope(scope, "name #{depth}")
|
78
76
|
end
|
79
77
|
|
80
78
|
if depth == 0
|
81
|
-
assert @engine.
|
79
|
+
assert @engine.scope_stack.empty?
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
85
83
|
|
86
84
|
def test_scope_failure
|
87
|
-
scope1 = @engine.push_scope
|
88
|
-
@engine.push_scope
|
89
|
-
|
90
|
-
|
91
|
-
@engine.pop_scope scope1
|
92
|
-
fail "Didn't throw when scope push/pop mismatched"
|
93
|
-
rescue
|
94
|
-
# success
|
85
|
+
scope1 = @engine.push_scope(:scope1)
|
86
|
+
scope2 = @engine.push_scope(:scope2)
|
87
|
+
assert_raises(RuntimeError) do
|
88
|
+
@engine.pop_scope(scope1, "name 1")
|
95
89
|
end
|
96
90
|
end
|
97
91
|
|
98
92
|
def test_children_time
|
99
93
|
t1 = Time.now
|
100
94
|
|
101
|
-
expected1 = @engine.push_scope
|
95
|
+
expected1 = @engine.push_scope(:a)
|
102
96
|
sleep 0.001
|
103
97
|
t2 = Time.now
|
104
98
|
|
105
|
-
expected2 = @engine.push_scope
|
99
|
+
expected2 = @engine.push_scope(:b)
|
106
100
|
sleep 0.002
|
107
101
|
t3 = Time.now
|
108
102
|
|
109
|
-
expected = @engine.push_scope
|
103
|
+
expected = @engine.push_scope(:c)
|
110
104
|
sleep 0.003
|
111
|
-
scope = @engine.pop_scope
|
105
|
+
scope = @engine.pop_scope(expected, "metric c")
|
112
106
|
|
113
107
|
t4 = Time.now
|
114
108
|
|
115
109
|
check_time_approximate 0, scope.children_time
|
116
|
-
check_time_approximate 0.003, @engine.peek_scope.children_time
|
117
110
|
|
118
111
|
sleep 0.001
|
119
112
|
t5 = Time.now
|
120
113
|
|
121
|
-
expected = @engine.push_scope
|
114
|
+
expected = @engine.push_scope(:d)
|
122
115
|
sleep 0.002
|
123
|
-
scope = @engine.pop_scope
|
116
|
+
scope = @engine.pop_scope(expected, "metric d")
|
124
117
|
|
125
118
|
t6 = Time.now
|
126
119
|
|
127
120
|
check_time_approximate 0, scope.children_time
|
128
121
|
|
129
|
-
scope = @engine.pop_scope
|
130
|
-
assert_equal scope.name
|
122
|
+
scope = @engine.pop_scope(expected2, "metric b")
|
123
|
+
assert_equal 'metric b', scope.name
|
131
124
|
|
132
|
-
check_time_approximate
|
125
|
+
check_time_approximate((t4 - t3) + (t6 - t5), scope.children_time)
|
133
126
|
|
134
|
-
scope = @engine.pop_scope
|
135
|
-
assert_equal scope.name, 'a'
|
127
|
+
scope = @engine.pop_scope(expected1, "metric a")
|
128
|
+
assert_equal scope.name, 'metric a'
|
136
129
|
|
137
|
-
check_time_approximate
|
130
|
+
check_time_approximate((t6 - t2), scope.children_time)
|
138
131
|
end
|
139
132
|
|
140
133
|
def test_simple_start_transaction
|
141
|
-
assert @engine.
|
142
|
-
scope = @engine.push_scope
|
134
|
+
assert @engine.scope_stack.empty?
|
135
|
+
scope = @engine.push_scope :tag
|
143
136
|
@engine.start_transaction
|
144
|
-
assert !@engine.
|
145
|
-
@engine.pop_scope
|
146
|
-
assert @engine.
|
137
|
+
assert !@engine.scope_stack.empty?
|
138
|
+
@engine.pop_scope(scope, "name")
|
139
|
+
assert @engine.scope_stack.empty?
|
147
140
|
@engine.end_transaction
|
148
|
-
assert @engine.
|
141
|
+
assert @engine.scope_stack.empty?
|
149
142
|
end
|
150
143
|
|
151
144
|
|
152
145
|
# test for when the scope stack contains an element only used for tts and not metrics
|
153
146
|
def test_simple_tt_only_scope
|
154
|
-
scope1 = @engine.push_scope
|
155
|
-
scope2 = @engine.push_scope
|
156
|
-
scope3 = @engine.push_scope
|
147
|
+
scope1 = @engine.push_scope(:a, 0, true)
|
148
|
+
scope2 = @engine.push_scope(:b, 10, false)
|
149
|
+
scope3 = @engine.push_scope(:c, 20, true)
|
157
150
|
|
158
|
-
@engine.pop_scope
|
159
|
-
@engine.pop_scope
|
160
|
-
@engine.pop_scope
|
151
|
+
@engine.pop_scope(scope3, "name a", 30)
|
152
|
+
@engine.pop_scope(scope2, "name b", 20)
|
153
|
+
@engine.pop_scope(scope1, "name c", 10)
|
161
154
|
|
162
155
|
assert_equal 0, scope3.children_time
|
163
156
|
assert_equal 10, scope2.children_time
|
@@ -165,15 +158,15 @@ class NewRelic::Agent::StatsEngineTest < Test::Unit::TestCase
|
|
165
158
|
end
|
166
159
|
|
167
160
|
def test_double_tt_only_scope
|
168
|
-
scope1 = @engine.push_scope
|
169
|
-
scope2 = @engine.push_scope
|
170
|
-
scope3 = @engine.push_scope
|
171
|
-
scope4 = @engine.push_scope
|
172
|
-
|
173
|
-
@engine.pop_scope
|
174
|
-
@engine.pop_scope
|
175
|
-
@engine.pop_scope
|
176
|
-
@engine.pop_scope
|
161
|
+
scope1 = @engine.push_scope(:a, 0, true)
|
162
|
+
scope2 = @engine.push_scope(:b, 10, false)
|
163
|
+
scope3 = @engine.push_scope(:c, 20, false)
|
164
|
+
scope4 = @engine.push_scope(:d, 30, true)
|
165
|
+
|
166
|
+
@engine.pop_scope(scope4, "name d", 40)
|
167
|
+
@engine.pop_scope(scope3, "name c", 30)
|
168
|
+
@engine.pop_scope(scope2, "name b", 20)
|
169
|
+
@engine.pop_scope(scope1, "name a", 10)
|
177
170
|
|
178
171
|
assert_equal 0, scope4.children_time.round
|
179
172
|
assert_equal 10, scope3.children_time.round
|
@@ -24,24 +24,24 @@ class ThreadTest < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
def test_bucket_thread_as_request
|
26
26
|
t = ::Thread.new {}
|
27
|
-
|
28
|
-
|
29
|
-
t[:
|
27
|
+
txn = NewRelic::Agent::Transaction.new
|
28
|
+
txn.request = "has a request"
|
29
|
+
t[:newrelic_transaction] = txn
|
30
30
|
|
31
31
|
assert_equal :request, NewRelic::Agent::AgentThread.bucket_thread(t, DONT_CARE)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_bucket_thread_as_background
|
35
35
|
t = ::Thread.new {}
|
36
|
-
|
37
|
-
t[:
|
36
|
+
txn = NewRelic::Agent::Transaction.new
|
37
|
+
t[:newrelic_transaction] = txn
|
38
38
|
|
39
39
|
assert_equal :background, NewRelic::Agent::AgentThread.bucket_thread(t, DONT_CARE)
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def test_bucket_thread_as_other_if_nil_txn
|
43
43
|
t = ::Thread.new {}
|
44
|
-
t[:
|
44
|
+
t[:newrelic_transaction] = nil
|
45
45
|
|
46
46
|
assert_equal :other, NewRelic::Agent::AgentThread.bucket_thread(t, DONT_CARE)
|
47
47
|
end
|
@@ -0,0 +1,96 @@
|
|
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 File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper'))
|
6
|
+
require 'new_relic/agent/transaction/pop'
|
7
|
+
class NewRelic::Agent::Transaction::PopTest < Test::Unit::TestCase
|
8
|
+
include NewRelic::Agent::Transaction::Pop
|
9
|
+
|
10
|
+
attr_reader :agent
|
11
|
+
attr_reader :transaction_sampler
|
12
|
+
attr_reader :sql_sampler
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@transaction_type_stack = []
|
16
|
+
@agent = mock('agent')
|
17
|
+
@transaction_sampler = mock('transaction sampler')
|
18
|
+
@sql_sampler = mock('sql sampler')
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
Thread.current[:newrelic_transaction] = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_log_underflow
|
26
|
+
expects_logging(:error, regexp_matches(/Underflow in transaction: /))
|
27
|
+
log_underflow
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_record_transaction_cpu_positive
|
31
|
+
self.expects(:cpu_burn).once.returns(1.0)
|
32
|
+
transaction_sampler.expects(:notice_transaction_cpu_time).with(1.0)
|
33
|
+
record_transaction_cpu
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_record_transaction_cpu_negative
|
37
|
+
self.expects(:cpu_burn).once.returns(nil)
|
38
|
+
# should not be called for the nil case
|
39
|
+
transaction_sampler.expects(:notice_transaction_cpu_time).never
|
40
|
+
record_transaction_cpu
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_normal_cpu_burn_positive
|
44
|
+
@process_cpu_start = 3
|
45
|
+
self.expects(:process_cpu).returns(4)
|
46
|
+
assert_equal 1, normal_cpu_burn
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_normal_cpu_burn_negative
|
50
|
+
@process_cpu_start = nil
|
51
|
+
self.expects(:process_cpu).never
|
52
|
+
assert_equal nil, normal_cpu_burn
|
53
|
+
end
|
54
|
+
|
55
|
+
# def test_jruby_cpu_burn_positive
|
56
|
+
# @jruby_cpu_start = 3
|
57
|
+
# self.expects(:jruby_cpu_time).returns(4)
|
58
|
+
# self.expects(:record_jruby_cpu_burn).with(1)
|
59
|
+
# assert_equal 1, jruby_cpu_burn
|
60
|
+
# end
|
61
|
+
|
62
|
+
def test_jruby_cpu_burn_negative
|
63
|
+
@jruby_cpu_start = nil
|
64
|
+
self.expects(:jruby_cpu_time).never
|
65
|
+
self.expects(:record_jruby_cpu_burn).never
|
66
|
+
assert_equal nil, jruby_cpu_burn
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_record_jruby_cpu_burn
|
70
|
+
NewRelic::Agent.get_stats_no_scope(NewRelic::Metrics::USER_TIME).expects(:record_data_point).with(1.0)
|
71
|
+
record_jruby_cpu_burn(1.0)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_cpu_burn_normal
|
75
|
+
self.expects(:normal_cpu_burn).returns(1)
|
76
|
+
self.expects(:jruby_cpu_burn).never
|
77
|
+
assert_equal 1, cpu_burn
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_cpu_burn_jruby
|
81
|
+
self.expects(:normal_cpu_burn).returns(nil)
|
82
|
+
self.expects(:jruby_cpu_burn).returns(2)
|
83
|
+
assert_equal 2, cpu_burn
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_traced
|
87
|
+
NewRelic::Agent.expects(:is_execution_traced?)
|
88
|
+
traced?
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_current_stack_metric
|
92
|
+
self.expects(:metric_name)
|
93
|
+
current_stack_metric
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
@@ -61,9 +61,9 @@ class NewRelic::Agent::TransactionInfoTest < Test::Unit::TestCase
|
|
61
61
|
:apdex_t => 2.0 }
|
62
62
|
|
63
63
|
with_config(config, :do_not_cast => true) do
|
64
|
-
txn_info.
|
64
|
+
txn_info.transaction = stub(:name => 'Controller/foo/bar')
|
65
65
|
assert_equal 1.5, txn_info.apdex_t
|
66
|
-
txn_info.
|
66
|
+
txn_info.transaction = stub(:name => 'Controller/some/other')
|
67
67
|
assert_equal 2.0, txn_info.apdex_t
|
68
68
|
end
|
69
69
|
end
|
@@ -74,9 +74,9 @@ class NewRelic::Agent::TransactionInfoTest < Test::Unit::TestCase
|
|
74
74
|
:apdex_t => 2.0 }
|
75
75
|
|
76
76
|
with_config(config, :do_not_cast => true) do
|
77
|
-
txn_info.
|
77
|
+
txn_info.transaction = stub(:name => 'Controller/foo/bar')
|
78
78
|
assert_equal 6.0, txn_info.transaction_trace_threshold
|
79
|
-
txn_info.
|
79
|
+
txn_info.transaction = stub(:name => 'Controller/some/other')
|
80
80
|
assert_equal 8.0, txn_info.transaction_trace_threshold
|
81
81
|
end
|
82
82
|
end
|
@@ -90,21 +90,10 @@ class NewRelic::Agent::TransactionInfoTest < Test::Unit::TestCase
|
|
90
90
|
}
|
91
91
|
|
92
92
|
with_config(config, :do_not_cast => true) do
|
93
|
-
txn_info.
|
93
|
+
txn_info.transaction = stub(:name => 'Controller/foo/bar')
|
94
94
|
assert_equal 4.0, txn_info.transaction_trace_threshold
|
95
|
-
txn_info.
|
95
|
+
txn_info.transaction = stub(:name => 'Controller/some/other')
|
96
96
|
assert_equal 4.0, txn_info.transaction_trace_threshold
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
100
|
-
def test_transaction_name
|
101
|
-
NewRelic::Agent::TransactionInfo.reset
|
102
|
-
txn = NewRelic::Agent::TransactionInfo.get
|
103
|
-
assert_equal(NewRelic::Agent::TransactionInfo::DEFAULT_TRANSACTION_NAME,
|
104
|
-
txn.transaction_name)
|
105
|
-
assert_equal(false, txn.transaction_name_set?)
|
106
|
-
txn.transaction_name = "foobar"
|
107
|
-
assert_equal("foobar", txn.transaction_name)
|
108
|
-
assert_equal(true, txn.transaction_name_set?)
|
109
|
-
end
|
110
99
|
end
|
@@ -13,7 +13,7 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
|
|
13
13
|
# if it doesn't the core app tests will break. Not strictly necessary but
|
14
14
|
# we'll enforce it with this test for now.
|
15
15
|
def test_trace_entry_returns_segment
|
16
|
-
segment = @builder.trace_entry(
|
16
|
+
segment = @builder.trace_entry(Time.now)
|
17
17
|
assert segment, "Segment should not be nil"
|
18
18
|
assert segment.is_a?(NewRelic::TransactionSample::Segment), "Segment should not be a #{segment.class.name}"
|
19
19
|
end
|
@@ -129,19 +129,7 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
|
|
129
129
|
assert_nil segment.metric_name =~ /Rails\/Application Code Loading/
|
130
130
|
end
|
131
131
|
end
|
132
|
-
|
133
|
-
assert_raise RuntimeError do
|
134
|
-
build_segment("a") do
|
135
|
-
begin
|
136
|
-
build_segment("aa") do
|
137
|
-
build_segment("aaa") do
|
138
|
-
raise "a problem"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
rescue; end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
132
|
+
|
145
133
|
def test_marshal
|
146
134
|
build_segment "a" do
|
147
135
|
build_segment "ab"
|
@@ -213,10 +201,14 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
|
|
213
201
|
assert s.exit_timestamp >= s.entry_timestamp
|
214
202
|
|
215
203
|
children = s.called_segments
|
216
|
-
|
204
|
+
parent = s
|
217
205
|
children.each do |child|
|
218
|
-
|
219
|
-
|
206
|
+
if check_names
|
207
|
+
assert(child.metric_name > parent.metric_name,
|
208
|
+
"#{child.metric_name} !> #{parent.metric_name}")
|
209
|
+
end
|
210
|
+
assert(child.entry_timestamp >= parent.entry_timestamp,
|
211
|
+
"#{child.entry_timestamp} !>= #{parent.entry_timestamp}")
|
220
212
|
last_metric = child
|
221
213
|
|
222
214
|
validate_segment(child, check_names)
|
@@ -224,7 +216,7 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
|
|
224
216
|
end
|
225
217
|
|
226
218
|
def build_segment(metric, time = 0, &proc)
|
227
|
-
@builder.trace_entry(
|
219
|
+
@builder.trace_entry(Time.now.to_f)
|
228
220
|
proc.call if proc
|
229
221
|
@builder.trace_exit(metric, Time.now.to_f)
|
230
222
|
end
|