wd_newrelic_rpm 3.5.6 → 3.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +43 -3
- data/Gemfile +6 -2
- data/LICENSE +23 -0
- data/lib/new_relic/agent.rb +50 -3
- data/lib/new_relic/agent/agent.rb +40 -60
- data/lib/new_relic/agent/configuration/defaults.rb +9 -3
- data/lib/new_relic/agent/configuration/server_source.rb +4 -0
- data/lib/new_relic/agent/cross_app_monitor.rb +239 -0
- data/lib/new_relic/agent/cross_app_tracing.rb +281 -0
- data/lib/new_relic/agent/database.rb +28 -10
- data/lib/new_relic/agent/error_collector.rb +5 -0
- data/lib/new_relic/agent/event_listener.rb +4 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +58 -39
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +16 -3
- data/lib/new_relic/agent/instrumentation/net.rb +13 -11
- data/lib/new_relic/agent/instrumentation/queue_time.rb +50 -192
- data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +145 -0
- data/lib/new_relic/agent/instrumentation/rails4/errors.rb +45 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +10 -10
- data/lib/new_relic/agent/instrumentation/sinatra.rb +19 -9
- data/lib/new_relic/agent/new_relic_service.rb +63 -9
- data/lib/new_relic/agent/pipe_service.rb +8 -12
- data/lib/new_relic/agent/rules_engine.rb +72 -0
- data/lib/new_relic/agent/shim_agent.rb +0 -1
- data/lib/new_relic/agent/sql_sampler.rb +3 -2
- data/lib/new_relic/agent/stats.rb +149 -0
- data/lib/new_relic/agent/stats_engine.rb +9 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -24
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +84 -185
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +58 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +10 -2
- data/lib/new_relic/agent/transaction_info.rb +31 -6
- data/lib/new_relic/agent/transaction_sample_builder.rb +19 -8
- data/lib/new_relic/agent/transaction_sampler.rb +17 -10
- data/lib/new_relic/helper.rb +32 -0
- data/lib/new_relic/local_environment.rb +24 -32
- data/lib/new_relic/okjson.rb +599 -0
- data/lib/new_relic/transaction_sample.rb +2 -1
- data/lib/new_relic/transaction_sample/segment.rb +2 -1
- data/lib/new_relic/version.rb +1 -1
- data/newrelic.yml +27 -41
- data/test/multiverse/suites/agent_only/Envfile +5 -1
- data/test/multiverse/suites/agent_only/audit_log_test.rb +2 -4
- data/test/multiverse/suites/agent_only/config/newrelic.yml +1 -2
- data/test/multiverse/suites/agent_only/{cross_process_test.rb → cross_application_tracing_test.rb} +3 -3
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +66 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +9 -22
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +57 -0
- data/test/multiverse/suites/agent_only/start_up_test.rb +1 -1
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +17 -6
- data/test/multiverse/suites/rails/error_tracing_test.rb +20 -8
- data/test/multiverse/suites/rails/queue_time_test.rb +2 -2
- data/test/multiverse/suites/resque/instrumentation_test.rb +4 -3
- data/test/multiverse/suites/sinatra/Envfile +2 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +1 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +5 -5
- data/test/multiverse/suites/sinatra/sinatra_test.rb +77 -10
- data/test/new_relic/agent/agent/connect_test.rb +45 -1
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +0 -3
- data/test/new_relic/agent/agent_test.rb +20 -40
- data/test/new_relic/agent/agent_test_controller_test.rb +27 -60
- data/test/new_relic/agent/busy_calculator_test.rb +1 -1
- data/test/new_relic/agent/configuration/server_source_test.rb +8 -3
- data/test/new_relic/agent/cross_app_monitor_test.rb +237 -0
- data/test/new_relic/agent/database_test.rb +60 -16
- data/test/new_relic/agent/error_collector_test.rb +28 -4
- data/test/new_relic/agent/event_listener_test.rb +23 -2
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +85 -12
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +95 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +436 -59
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +58 -357
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -5
- data/test/new_relic/agent/method_tracer_test.rb +4 -2
- data/test/new_relic/agent/new_relic_service_test.rb +108 -6
- data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
- data/test/new_relic/agent/pipe_service_test.rb +9 -9
- data/test/new_relic/agent/rpm_agent_test.rb +0 -11
- data/test/new_relic/agent/rules_engine_test.rb +82 -0
- data/test/new_relic/agent/shim_agent_test.rb +0 -4
- data/test/new_relic/agent/sql_sampler_test.rb +7 -0
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +85 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +110 -23
- data/test/new_relic/agent/stats_engine_test.rb +1 -46
- data/test/new_relic/agent/stats_hash_test.rb +93 -0
- data/test/new_relic/agent/stats_test.rb +197 -0
- data/test/new_relic/agent/transaction_info_test.rb +63 -11
- data/test/new_relic/agent/transaction_sample_builder_test.rb +10 -3
- data/test/new_relic/agent/transaction_sampler_test.rb +92 -80
- data/test/new_relic/agent/worker_loop_test.rb +1 -1
- data/test/new_relic/agent_test.rb +35 -5
- data/test/new_relic/control_test.rb +1 -1
- data/test/new_relic/fake_collector.rb +87 -9
- data/test/new_relic/helper_test.rb +24 -0
- data/test/new_relic/metric_data_test.rb +11 -11
- data/test/new_relic/metric_spec_test.rb +1 -1
- data/test/script/ci.sh +1 -1
- data/test/test_contexts.rb +0 -1
- data/test/test_helper.rb +21 -3
- metadata +34 -41
- data/lib/new_relic/agent/cross_process_monitoring.rb +0 -187
- data/lib/new_relic/stats.rb +0 -337
- data/test/new_relic/agent/cross_process_monitoring_test.rb +0 -190
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +0 -133
- data/test/new_relic/fakes_sending_data.rb +0 -30
- data/test/new_relic/stats_test.rb +0 -421
@@ -5,13 +5,13 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
5
5
|
def teardown
|
6
6
|
NewRelic::Agent::Database::Obfuscator.instance.reset
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def test_process_resultset
|
10
10
|
resultset = [["column"]]
|
11
11
|
assert_equal([nil, [["column"]]],
|
12
12
|
NewRelic::Agent::Database.process_resultset(resultset))
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def test_explain_sql_select_with_mysql_connection
|
16
16
|
config = {:adapter => 'mysql'}
|
17
17
|
config.default('val')
|
@@ -30,7 +30,7 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
30
30
|
|
31
31
|
result = NewRelic::Agent::Database.explain_sql(sql, config)
|
32
32
|
assert_equal(plan.keys.sort, result[0].sort)
|
33
|
-
assert_equal(plan.values.compact.sort, result[1][0].compact.sort)
|
33
|
+
assert_equal(plan.values.compact.sort, result[1][0].compact.sort)
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_explain_sql_one_select_with_pg_connection
|
@@ -50,6 +50,44 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
50
50
|
NewRelic::Agent::Database.explain_sql(sql, config))
|
51
51
|
end
|
52
52
|
|
53
|
+
def test_dont_collect_explain_for_parameterized_query
|
54
|
+
config = {:adapter => 'postgresql'}
|
55
|
+
config.default('val')
|
56
|
+
connection = mock('connection')
|
57
|
+
connection.expects(:execute).never
|
58
|
+
NewRelic::Agent::Database.stubs(:get_connection).with(config).returns(connection)
|
59
|
+
expects_logging(:debug, 'Unable to collect explain plan for parameterized query.')
|
60
|
+
|
61
|
+
sql = 'SELECT * FROM table WHERE id = $1'
|
62
|
+
assert_equal [], NewRelic::Agent::Database.explain_sql(sql, config)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_do_collect_explain_for_parameter_looking_literal
|
66
|
+
config = {:adapter => 'postgresql'}
|
67
|
+
config.default('val')
|
68
|
+
connection = mock('connection')
|
69
|
+
plan = [{"QUERY PLAN"=>"Some Jazz"}]
|
70
|
+
connection.stubs(:execute).returns(plan)
|
71
|
+
NewRelic::Agent::Database.stubs(:get_connection).with(config).returns(connection)
|
72
|
+
|
73
|
+
sql = "SELECT * FROM table WHERE id = 'noise $11'"
|
74
|
+
assert_equal([['QUERY PLAN'], [["Some Jazz"]]],
|
75
|
+
NewRelic::Agent::Database.explain_sql(sql, config))
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_dont_collect_explain_for_truncated_query
|
79
|
+
config = {:adapter => 'postgresql'}
|
80
|
+
config.default('val')
|
81
|
+
connection = mock('connection')
|
82
|
+
connection.expects(:execute).never
|
83
|
+
NewRelic::Agent::Database.stubs(:get_connection).with(config).returns(connection)
|
84
|
+
expects_logging(:debug, 'Unable to collect explain plan for truncated query.')
|
85
|
+
|
86
|
+
sql = 'SELECT * FROM table WHERE id IN (1,2,3,4,5...'
|
87
|
+
assert_equal [], NewRelic::Agent::Database.explain_sql(sql, config)
|
88
|
+
|
89
|
+
end
|
90
|
+
|
53
91
|
def test_explain_sql_no_sql
|
54
92
|
assert_equal(nil, NewRelic::Agent::Database.explain_sql(nil, nil))
|
55
93
|
end
|
@@ -71,8 +109,8 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
71
109
|
config = mock('config')
|
72
110
|
config.stubs(:[]).returns(nil)
|
73
111
|
assert_equal([], NewRelic::Agent::Database.explain_sql('SELECT', config))
|
74
|
-
end
|
75
|
-
|
112
|
+
end
|
113
|
+
|
76
114
|
def test_obfuscation_mysql_basic
|
77
115
|
insert = %q[INSERT INTO `X` values("test",0, 1 , 2, 'test')]
|
78
116
|
assert_equal("INSERT INTO `X` values(?,?, ? , ?, ?)",
|
@@ -90,9 +128,9 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
90
128
|
select = NewRelic::Agent::Database::Statement.new(%q[SELECT "table"."column" FROM "table" WHERE "table"."column" = 'value' AND "table"."other_column" = 'other value' LIMIT 1])
|
91
129
|
select.adapter = :postgresql
|
92
130
|
assert_equal(%q[SELECT "table"."column" FROM "table" WHERE "table"."column" = ? AND "table"."other_column" = ? LIMIT ?],
|
93
|
-
NewRelic::Agent::Database.obfuscate_sql(select))
|
131
|
+
NewRelic::Agent::Database.obfuscate_sql(select))
|
94
132
|
end
|
95
|
-
|
133
|
+
|
96
134
|
def test_obfuscation_escaped_literals
|
97
135
|
insert = %q[INSERT INTO X values('', 'jim''s ssn',0, 1 , 'jim''s son''s son', """jim''s"" hat", "\"jim''s secret\"")]
|
98
136
|
assert_equal("INSERT INTO X values(?, ?,?, ? , ?, ?, ?)",
|
@@ -104,7 +142,7 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
104
142
|
assert_equal(%q[SELECT * FROM `table_007` LIMIT ?],
|
105
143
|
NewRelic::Agent::Database.obfuscate_sql(select))
|
106
144
|
end
|
107
|
-
|
145
|
+
|
108
146
|
def test_obfuscation_postgresql_integers_in_identifiers
|
109
147
|
select = NewRelic::Agent::Database::Statement.new(%q[SELECT * FROM "table_007" LIMIT 1])
|
110
148
|
select.adapter = :postgresql
|
@@ -112,25 +150,31 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
112
150
|
NewRelic::Agent::Database.obfuscate_sql(select))
|
113
151
|
end
|
114
152
|
|
153
|
+
def test_obfuscation_of_truncated_query
|
154
|
+
insert = "INSERT INTO data (blah) VALUES ('abcdefg..."
|
155
|
+
assert_equal("Query too large (over 16k characters) to safely obfuscate",
|
156
|
+
NewRelic::Agent::Database.obfuscate_sql(insert))
|
157
|
+
end
|
158
|
+
|
115
159
|
def test_sql_obfuscation_filters
|
116
160
|
NewRelic::Agent::Database.set_sql_obfuscator(:replace) do |string|
|
117
161
|
"1" + string
|
118
162
|
end
|
119
|
-
|
163
|
+
|
120
164
|
sql = "SELECT * FROM TABLE 123 'jim'"
|
121
|
-
|
165
|
+
|
122
166
|
assert_equal "1" + sql, NewRelic::Agent::Database.obfuscate_sql(sql)
|
123
|
-
|
167
|
+
|
124
168
|
NewRelic::Agent::Database.set_sql_obfuscator(:before) do |string|
|
125
169
|
"2" + string
|
126
170
|
end
|
127
|
-
|
171
|
+
|
128
172
|
assert_equal "12" + sql, NewRelic::Agent::Database.obfuscate_sql(sql)
|
129
|
-
|
173
|
+
|
130
174
|
NewRelic::Agent::Database.set_sql_obfuscator(:after) do |string|
|
131
175
|
string + "3"
|
132
176
|
end
|
133
|
-
|
177
|
+
|
134
178
|
assert_equal "12" + sql + "3", NewRelic::Agent::Database.obfuscate_sql(sql)
|
135
179
|
|
136
180
|
NewRelic::Agent::Database::Obfuscator.instance.reset
|
@@ -140,11 +184,11 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
140
184
|
foo_connection = mock('foo connection')
|
141
185
|
bar_connection = mock('bar connection')
|
142
186
|
NewRelic::Agent::Database::ConnectionManager.instance.instance_eval do
|
143
|
-
@connections = { :foo => foo_connection, :bar => bar_connection }
|
187
|
+
@connections = { :foo => foo_connection, :bar => bar_connection }
|
144
188
|
end
|
145
189
|
foo_connection.expects(:disconnect!)
|
146
190
|
bar_connection.expects(:disconnect!)
|
147
|
-
|
191
|
+
|
148
192
|
NewRelic::Agent::Database.close_connections
|
149
193
|
end
|
150
194
|
end
|
@@ -162,10 +162,10 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
162
162
|
|
163
163
|
def test_exclude_block
|
164
164
|
@error_collector.ignore_error_filter &wrapped_filter_proc
|
165
|
-
|
165
|
+
|
166
166
|
@error_collector.notice_error(IOError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
|
167
167
|
@error_collector.notice_error(StandardError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
|
168
|
-
|
168
|
+
|
169
169
|
errors = @error_collector.harvest_errors([])
|
170
170
|
|
171
171
|
assert_equal 1, errors.length
|
@@ -192,6 +192,30 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
+
def test_increment_error_count_record_summary_and_txn_metric
|
196
|
+
txn_info = NewRelic::Agent::TransactionInfo.new
|
197
|
+
txn_info.transaction_name = 'Controller/class/method'
|
198
|
+
NewRelic::Agent::TransactionInfo.stubs(:get).returns(txn_info)
|
199
|
+
|
200
|
+
stats_engine = NewRelic::Agent.instance.stats_engine
|
201
|
+
stats_engine.reset_stats
|
202
|
+
@error_collector.increment_error_count!(StandardError.new('Boo'))
|
203
|
+
assert_equal(1, stats_engine.get_stats('Errors/all').call_count,
|
204
|
+
'Missing Errors/all metric')
|
205
|
+
assert_equal(1, stats_engine.get_stats('Errors/Controller/class/method').call_count,
|
206
|
+
'Missing Errors/Controller/class/method metric')
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_doesnt_increment_error_count_on_transaction_if_nameless
|
210
|
+
txn_info = NewRelic::Agent::TransactionInfo.new
|
211
|
+
NewRelic::Agent::TransactionInfo.stubs(:get).returns(txn_info)
|
212
|
+
|
213
|
+
stats_engine = NewRelic::Agent.instance.stats_engine
|
214
|
+
stats_engine.reset_stats
|
215
|
+
@error_collector.increment_error_count!(StandardError.new('Boo'))
|
216
|
+
assert_equal(0, stats_engine.get_stats('Errors/(unknown)').call_count)
|
217
|
+
end
|
218
|
+
|
195
219
|
private
|
196
220
|
|
197
221
|
def expects_error_count_increase(increase)
|
@@ -203,7 +227,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
203
227
|
def get_error_stats
|
204
228
|
NewRelic::Agent.get_stats("Errors/all").call_count
|
205
229
|
end
|
206
|
-
|
230
|
+
|
207
231
|
def wrapped_filter_proc
|
208
232
|
Proc.new do |e|
|
209
233
|
if e.is_a? IOError
|
@@ -213,7 +237,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
213
237
|
end
|
214
238
|
end
|
215
239
|
end
|
216
|
-
|
240
|
+
|
217
241
|
def silence_stream(*args)
|
218
242
|
super
|
219
243
|
rescue NoMethodError
|
@@ -14,6 +14,24 @@ class EventListenerTest < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
|
18
|
+
#
|
19
|
+
# Helpers
|
20
|
+
#
|
21
|
+
|
22
|
+
def assert_was_called
|
23
|
+
assert @called, "Event wasn't called"
|
24
|
+
end
|
25
|
+
|
26
|
+
def assert_was_not_called
|
27
|
+
assert !@called, "Event was called"
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
#
|
32
|
+
# Tests
|
33
|
+
#
|
34
|
+
|
17
35
|
def test_notifies
|
18
36
|
@events.subscribe(:before_call, &@check_method)
|
19
37
|
@events.notify(:before_call, :env => "env")
|
@@ -37,9 +55,12 @@ class EventListenerTest < Test::Unit::TestCase
|
|
37
55
|
@events.subscribe(:my_event) {}
|
38
56
|
end
|
39
57
|
|
58
|
+
def test_clear
|
59
|
+
@events.subscribe(:after_call, &@check_method)
|
60
|
+
@events.clear
|
61
|
+
@events.notify(:after_call)
|
40
62
|
|
41
|
-
|
42
|
-
assert @called, "Event wasn't called"
|
63
|
+
assert_was_not_called
|
43
64
|
end
|
44
65
|
|
45
66
|
end
|
@@ -45,7 +45,7 @@ module NewRelic::Agent::Instrumentation
|
|
45
45
|
t = BrowserMonitoringTimings.new(1000, @transaction)
|
46
46
|
original = t.app_time_in_seconds
|
47
47
|
|
48
|
-
Time.stubs(:now).returns(3000)
|
48
|
+
Time.stubs(:now).returns(Time.at(3000))
|
49
49
|
later = t.app_time_in_seconds
|
50
50
|
|
51
51
|
assert_equal original, later
|
@@ -5,30 +5,103 @@ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Test::Un
|
|
5
5
|
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
6
6
|
end
|
7
7
|
|
8
|
+
def setup
|
9
|
+
@object = TestObject.new
|
10
|
+
end
|
11
|
+
|
8
12
|
def test_detect_upstream_wait_basic
|
9
13
|
start_time = Time.now
|
10
|
-
object = TestObject.new
|
11
14
|
# should return the start time above by default
|
12
|
-
object.expects(:newrelic_request_headers).returns({:request => 'headers'}).twice
|
13
|
-
|
14
|
-
|
15
|
+
@object.expects(:newrelic_request_headers).returns({:request => 'headers'}).twice
|
16
|
+
NewRelic::Agent::Instrumentation::QueueTime.expects(:parse_frontend_timestamp) \
|
17
|
+
.with({:request => 'headers'}, start_time).returns(start_time)
|
18
|
+
assert_equal(start_time, @object.send(:_detect_upstream_wait, start_time))
|
15
19
|
end
|
16
20
|
|
17
21
|
def test_detect_upstream_wait_with_upstream
|
18
22
|
start_time = Time.now
|
19
23
|
runs_at = start_time + 1
|
20
|
-
object = TestObject.new
|
21
|
-
object.expects(:newrelic_request_headers).returns(true).twice
|
22
|
-
|
23
|
-
|
24
|
+
@object = TestObject.new
|
25
|
+
@object.expects(:newrelic_request_headers).returns(true).twice
|
26
|
+
NewRelic::Agent::Instrumentation::QueueTime.expects(:parse_frontend_timestamp) \
|
27
|
+
.with(true, runs_at).returns(start_time)
|
28
|
+
assert_equal(start_time, @object.send(:_detect_upstream_wait, runs_at))
|
24
29
|
end
|
25
30
|
|
26
31
|
def test_detect_upstream_wait_swallows_errors
|
27
32
|
start_time = Time.now
|
28
|
-
object = TestObject.new
|
29
33
|
# should return the start time above when an error is raised
|
30
|
-
object.expects(:newrelic_request_headers).returns({:request => 'headers'}).twice
|
31
|
-
|
32
|
-
|
34
|
+
@object.expects(:newrelic_request_headers).returns({:request => 'headers'}).twice
|
35
|
+
NewRelic::Agent::Instrumentation::QueueTime.expects(:parse_frontend_timestamp) \
|
36
|
+
.with({:request => 'headers'}, start_time).raises("an error")
|
37
|
+
assert_equal(start_time, @object.send(:_detect_upstream_wait, start_time))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_transaction_name_calls_newrelic_metric_path
|
41
|
+
@object.stubs(:newrelic_metric_path).returns('some/wacky/path')
|
42
|
+
assert_equal('Controller/some/wacky/path', @object.send(:transaction_name))
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_transaction_name_applies_category_and_path
|
46
|
+
assert_equal('Controller/metric/path',
|
47
|
+
@object.send(:transaction_name,
|
48
|
+
:category => :controller,
|
49
|
+
:path => 'metric/path'))
|
50
|
+
assert_equal('OtherTransaction/Background/metric/path',
|
51
|
+
@object.send(:transaction_name,
|
52
|
+
:category => :task, :path => 'metric/path'))
|
53
|
+
assert_equal('Controller/Rack/metric/path',
|
54
|
+
@object.send(:transaction_name,
|
55
|
+
:category => :rack, :path => 'metric/path'))
|
56
|
+
assert_equal('Controller/metric/path',
|
57
|
+
@object.send(:transaction_name,
|
58
|
+
:category => :uri, :path => 'metric/path'))
|
59
|
+
assert_equal('Controller/Sinatra/metric/path',
|
60
|
+
@object.send(:transaction_name,
|
61
|
+
:category => :sinatra,
|
62
|
+
:path => 'metric/path'))
|
63
|
+
assert_equal('Blarg/metric/path',
|
64
|
+
@object.send(:transaction_name,
|
65
|
+
:category => 'Blarg', :path => 'metric/path'))
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_transaction_name_uses_class_name_if_path_not_specified
|
70
|
+
assert_equal('Controller/NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject',
|
71
|
+
@object.send(:transaction_name, :category => :controller))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_transaction_name_applies_action_name_if_specified_and_not_path
|
75
|
+
assert_equal('Controller/NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject/action',
|
76
|
+
@object.send(:transaction_name, :category => :controller,
|
77
|
+
:name => 'action'))
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_transaction_name_applies_name_rules
|
81
|
+
rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
|
82
|
+
'replacement' => '*',
|
83
|
+
'replace_all' => true)
|
84
|
+
NewRelic::Agent.instance.transaction_rules << rule
|
85
|
+
assert_equal('foo/*/bar/*',
|
86
|
+
@object.send(:transaction_name, :category => 'foo',
|
87
|
+
:path => '1/bar/22'))
|
88
|
+
ensure
|
89
|
+
NewRelic::Agent.instance.instance_variable_set(:@transaction_rules,
|
90
|
+
NewRelic::Agent::RulesEngine.new)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_path_class_and_action
|
94
|
+
result = @object.send(:path_class_and_action, {})
|
95
|
+
assert_equal("NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject", result)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_path_class_and_action_with_name
|
99
|
+
result = @object.send(:path_class_and_action, :name => "test")
|
100
|
+
assert_equal("NewRelic::Agent::Instrumentation::ControllerInstrumentationTest::TestObject/test", result)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_path_class_and_action_with_overridden_class_name
|
104
|
+
result = @object.send(:path_class_and_action, :name => "perform", :class_name => 'Resque')
|
105
|
+
assert_equal("Resque/perform", result)
|
33
106
|
end
|
34
107
|
end
|
@@ -53,4 +53,99 @@ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
|
|
53
53
|
f.start = 1500
|
54
54
|
assert_equal 500, f.queue_time
|
55
55
|
end
|
56
|
+
|
57
|
+
def test_update_apdex_records_failed_when_specified
|
58
|
+
stats = NewRelic::Agent::Stats.new
|
59
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 0.1, true)
|
60
|
+
assert_equal 0, stats.apdex_s
|
61
|
+
assert_equal 0, stats.apdex_t
|
62
|
+
assert_equal 1, stats.apdex_f
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_update_apdex_records_satisfying
|
66
|
+
stats = NewRelic::Agent::Stats.new
|
67
|
+
with_config(:apdex_t => 1) do
|
68
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 0.5, false)
|
69
|
+
end
|
70
|
+
assert_equal 1, stats.apdex_s
|
71
|
+
assert_equal 0, stats.apdex_t
|
72
|
+
assert_equal 0, stats.apdex_f
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_update_apdex_records_tolerating
|
76
|
+
stats = NewRelic::Agent::Stats.new
|
77
|
+
with_config(:apdex_t => 1) do
|
78
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 1.5, false)
|
79
|
+
end
|
80
|
+
assert_equal 0, stats.apdex_s
|
81
|
+
assert_equal 1, stats.apdex_t
|
82
|
+
assert_equal 0, stats.apdex_f
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_update_apdex_records_failing
|
86
|
+
stats = NewRelic::Agent::Stats.new
|
87
|
+
with_config(:apdex_t => 1) do
|
88
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 4.5, false)
|
89
|
+
end
|
90
|
+
assert_equal 0, stats.apdex_s
|
91
|
+
assert_equal 0, stats.apdex_t
|
92
|
+
assert_equal 1, stats.apdex_f
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_update_apdex_records_correct_apdex_for_key_transaction
|
96
|
+
txn_info = NewRelic::Agent::TransactionInfo.get
|
97
|
+
stats = NewRelic::Agent::Stats.new
|
98
|
+
config = {
|
99
|
+
:web_transactions_apdex => {
|
100
|
+
'Controller/slow/txn' => 4,
|
101
|
+
'Controller/fast/txn' => 0.1,
|
102
|
+
},
|
103
|
+
:apdex => 1
|
104
|
+
}
|
105
|
+
|
106
|
+
txn_info.transaction_name = 'Controller/slow/txn'
|
107
|
+
with_config(config, :do_not_cast => true) do
|
108
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 3.5, false)
|
109
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 5.5, false)
|
110
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 16.5, false)
|
111
|
+
end
|
112
|
+
assert_equal 1, stats.apdex_s
|
113
|
+
assert_equal 1, stats.apdex_t
|
114
|
+
assert_equal 1, stats.apdex_f
|
115
|
+
|
116
|
+
txn_info.transaction_name = 'Controller/fast/txn'
|
117
|
+
with_config(config, :do_not_cast => true) do
|
118
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 0.05, false)
|
119
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 0.2, false)
|
120
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 0.5, false)
|
121
|
+
end
|
122
|
+
assert_equal 2, stats.apdex_s
|
123
|
+
assert_equal 2, stats.apdex_t
|
124
|
+
assert_equal 2, stats.apdex_f
|
125
|
+
|
126
|
+
txn_info.transaction_name = 'Controller/other/txn'
|
127
|
+
with_config(config, :do_not_cast => true) do
|
128
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 0.5, false)
|
129
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 2, false)
|
130
|
+
NewRelic::Agent::Instrumentation::MetricFrame.update_apdex(stats, 5, false)
|
131
|
+
end
|
132
|
+
assert_equal 3, stats.apdex_s
|
133
|
+
assert_equal 3, stats.apdex_t
|
134
|
+
assert_equal 3, stats.apdex_f
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_record_apdex_stores_apdex_t_in_min_and_max
|
138
|
+
stats_engine = NewRelic::Agent.instance.stats_engine
|
139
|
+
stats_engine.reset_stats
|
140
|
+
metric = stub(:apdex_metric_path => 'Apdex/Controller/some/txn')
|
141
|
+
NewRelic::Agent.instance.instance_variable_set(:@stats_engine, stats_engine)
|
142
|
+
|
143
|
+
with_config(:apdex_t => 2.5) do
|
144
|
+
NewRelic::Agent::Instrumentation::MetricFrame.record_apdex(metric, 1, 1, false)
|
145
|
+
end
|
146
|
+
assert_equal 2.5, stats_engine.lookup_stats('Apdex').min_call_time
|
147
|
+
assert_equal 2.5, stats_engine.lookup_stats('Apdex').max_call_time
|
148
|
+
assert_equal 2.5, stats_engine.lookup_stats('Apdex/Controller/some/txn').min_call_time
|
149
|
+
assert_equal 2.5, stats_engine.lookup_stats('Apdex/Controller/some/txn').max_call_time
|
150
|
+
end
|
56
151
|
end
|