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
@@ -31,14 +31,18 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
31
31
|
agent.stubs(:stats_engine).returns(stats_engine)
|
32
32
|
@sampler = NewRelic::Agent::TransactionSampler.new
|
33
33
|
stats_engine.transaction_sampler = @sampler
|
34
|
+
@old_sampler = NewRelic::Agent.instance.transaction_sampler
|
35
|
+
NewRelic::Agent.instance.instance_variable_set(:@transaction_sampler, @sampler)
|
34
36
|
@test_config = { :'transaction_tracer.enabled' => true }
|
35
37
|
NewRelic::Agent.config.apply_config(@test_config)
|
38
|
+
@txn = stub('txn', :name => '/path', :custom_parameters => {})
|
36
39
|
end
|
37
40
|
|
38
41
|
def teardown
|
39
42
|
super
|
40
43
|
Thread.current[:transaction_sample_builder] = nil
|
41
44
|
NewRelic::Agent.config.remove_config(@test_config)
|
45
|
+
NewRelic::Agent.instance.instance_variable_set(:@transaction_sampler, @old_sampler)
|
42
46
|
end
|
43
47
|
|
44
48
|
def test_initialize
|
@@ -97,25 +101,25 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
97
101
|
|
98
102
|
def test_notice_push_scope_no_builder
|
99
103
|
@sampler.expects(:builder)
|
100
|
-
assert_equal(nil, @sampler.notice_push_scope(
|
104
|
+
assert_equal(nil, @sampler.notice_push_scope())
|
101
105
|
end
|
102
106
|
|
103
107
|
def test_notice_push_scope_with_builder
|
104
108
|
with_config(:developer_mode => false) do
|
105
109
|
builder = mock('builder')
|
106
|
-
builder.expects(:trace_entry).with(
|
110
|
+
builder.expects(:trace_entry).with(100.0)
|
107
111
|
@sampler.expects(:builder).returns(builder).twice
|
108
|
-
@sampler.notice_push_scope(
|
112
|
+
@sampler.notice_push_scope(Time.at(100))
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
112
116
|
def test_notice_push_scope_in_dev_mode
|
113
117
|
builder = mock('builder')
|
114
|
-
builder.expects(:trace_entry).with(
|
118
|
+
builder.expects(:trace_entry).with(100.0)
|
115
119
|
@sampler.expects(:builder).returns(builder).twice
|
116
120
|
@sampler.expects(:capture_segment_trace)
|
117
121
|
|
118
|
-
@sampler.notice_push_scope(
|
122
|
+
@sampler.notice_push_scope(Time.at(100))
|
119
123
|
end
|
120
124
|
|
121
125
|
def test_scope_depth_no_builder
|
@@ -161,7 +165,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
161
165
|
|
162
166
|
def test_notice_scope_empty_no_builder
|
163
167
|
@sampler.expects(:builder).returns(nil)
|
164
|
-
assert_equal(nil, @sampler.notice_scope_empty)
|
168
|
+
assert_equal(nil, @sampler.notice_scope_empty(@txn))
|
165
169
|
end
|
166
170
|
|
167
171
|
def test_notice_scope_empty_ignored_transaction
|
@@ -169,31 +173,34 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
169
173
|
# the builder should be cached, so only called once
|
170
174
|
@sampler.expects(:builder).returns(builder).once
|
171
175
|
|
172
|
-
builder.expects(:finish_trace).with(100.0)
|
176
|
+
builder.expects(:finish_trace).with(100.0, {})
|
173
177
|
|
174
178
|
@sampler.expects(:clear_builder)
|
175
179
|
|
176
180
|
builder.expects(:ignored?).returns(true)
|
181
|
+
builder.expects(:set_transaction_name).returns(true)
|
177
182
|
|
178
|
-
assert_equal(nil, @sampler.notice_scope_empty(Time.at(100)))
|
183
|
+
assert_equal(nil, @sampler.notice_scope_empty(@txn, Time.at(100)))
|
179
184
|
end
|
180
185
|
|
181
186
|
def test_notice_scope_empty_with_builder
|
182
187
|
builder = mock('builder')
|
183
|
-
|
184
|
-
@sampler.expects(:builder).returns(builder).once
|
188
|
+
@sampler.stubs(:builder).returns(builder)
|
185
189
|
|
186
190
|
|
187
|
-
builder.expects(:finish_trace).with(100.0)
|
191
|
+
builder.expects(:finish_trace).with(100.0, {})
|
188
192
|
@sampler.expects(:clear_builder)
|
189
193
|
|
190
194
|
builder.expects(:ignored?).returns(false)
|
195
|
+
builder.expects(:set_transaction_info).returns(true)
|
196
|
+
builder.expects(:set_transaction_name).returns(true)
|
191
197
|
|
192
198
|
sample = mock('sample')
|
193
199
|
builder.expects(:sample).returns(sample)
|
194
200
|
@sampler.expects(:store_sample).with(sample)
|
195
201
|
|
196
|
-
@sampler.
|
202
|
+
@sampler.notice_transaction(nil, {})
|
203
|
+
@sampler.notice_scope_empty(@txn, Time.at(100))
|
197
204
|
|
198
205
|
assert_equal(sample, @sampler.instance_variable_get('@last_sample'))
|
199
206
|
end
|
@@ -303,28 +310,6 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
303
310
|
assert_equal([2, 3], @sampler.instance_variable_get('@samples'))
|
304
311
|
end
|
305
312
|
|
306
|
-
def test_notice_transaction_disabled
|
307
|
-
builder = mock('builder')
|
308
|
-
builder.expects(:set_transaction_info).never # since we're disabled
|
309
|
-
@sampler.stubs(:builder).returns(builder)
|
310
|
-
with_config(:'transaction_tracer.enabled' => false,
|
311
|
-
:developer_mode => false) do
|
312
|
-
@sampler.notice_transaction('foo')
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
def test_notice_transaction_no_builder
|
317
|
-
@sampler.expects(:builder).returns(nil).once
|
318
|
-
@sampler.notice_transaction('foo')
|
319
|
-
end
|
320
|
-
|
321
|
-
def test_notice_transaction_with_builder
|
322
|
-
builder = mock('builder')
|
323
|
-
builder.expects(:set_transaction_info).with('a path', 'a uri', {:some => :params})
|
324
|
-
@sampler.expects(:builder).returns(builder).twice
|
325
|
-
@sampler.notice_transaction('a path', 'a uri', {:some => :params})
|
326
|
-
end
|
327
|
-
|
328
313
|
def test_ignore_transaction_no_builder
|
329
314
|
@sampler.expects(:builder).returns(nil).once
|
330
315
|
@sampler.ignore_transaction
|
@@ -671,21 +656,20 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
671
656
|
def test_sample_tree
|
672
657
|
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
673
658
|
assert_equal 0, @sampler.scope_depth
|
674
|
-
|
675
659
|
@sampler.notice_first_scope_push Time.now.to_f
|
676
|
-
@sampler.notice_transaction
|
677
|
-
@sampler.notice_push_scope
|
660
|
+
@sampler.notice_transaction(nil, {})
|
661
|
+
@sampler.notice_push_scope
|
678
662
|
|
679
|
-
@sampler.notice_push_scope
|
663
|
+
@sampler.notice_push_scope
|
680
664
|
@sampler.notice_pop_scope "b"
|
681
665
|
|
682
|
-
@sampler.notice_push_scope
|
683
|
-
@sampler.notice_push_scope
|
666
|
+
@sampler.notice_push_scope
|
667
|
+
@sampler.notice_push_scope
|
684
668
|
@sampler.notice_pop_scope "d"
|
685
669
|
@sampler.notice_pop_scope "c"
|
686
670
|
|
687
671
|
@sampler.notice_pop_scope "a"
|
688
|
-
@sampler.notice_scope_empty
|
672
|
+
@sampler.notice_scope_empty(@txn)
|
689
673
|
sample = @sampler.harvest([]).first
|
690
674
|
assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
|
691
675
|
end
|
@@ -700,19 +684,19 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
700
684
|
|
701
685
|
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
702
686
|
@sampler.notice_first_scope_push Time.now.to_f
|
703
|
-
@sampler.notice_transaction
|
704
|
-
@sampler.notice_push_scope
|
687
|
+
@sampler.notice_transaction(nil, {})
|
688
|
+
@sampler.notice_push_scope
|
705
689
|
|
706
|
-
@sampler.notice_push_scope
|
690
|
+
@sampler.notice_push_scope
|
707
691
|
@sampler.notice_pop_scope "b"
|
708
692
|
|
709
|
-
@sampler.notice_push_scope
|
710
|
-
@sampler.notice_push_scope
|
693
|
+
@sampler.notice_push_scope
|
694
|
+
@sampler.notice_push_scope
|
711
695
|
@sampler.notice_pop_scope "d"
|
712
696
|
@sampler.notice_pop_scope "c"
|
713
697
|
|
714
698
|
@sampler.notice_pop_scope "a"
|
715
|
-
@sampler.notice_scope_empty
|
699
|
+
@sampler.notice_scope_empty(@txn)
|
716
700
|
|
717
701
|
sample = @sampler.harvest([]).first
|
718
702
|
assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
|
@@ -789,23 +773,22 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
789
773
|
def test_sample_with_parallel_paths
|
790
774
|
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
791
775
|
assert_equal 0, @sampler.scope_depth
|
792
|
-
|
793
776
|
@sampler.notice_first_scope_push Time.now.to_f
|
794
|
-
@sampler.notice_transaction
|
795
|
-
@sampler.notice_push_scope
|
777
|
+
@sampler.notice_transaction(nil, {})
|
778
|
+
@sampler.notice_push_scope
|
796
779
|
|
797
780
|
assert_equal 1, @sampler.scope_depth
|
798
781
|
|
799
782
|
@sampler.notice_pop_scope "a"
|
800
|
-
@sampler.notice_scope_empty
|
783
|
+
@sampler.notice_scope_empty(@txn)
|
801
784
|
|
802
785
|
assert_equal 0, @sampler.scope_depth
|
803
786
|
|
804
787
|
@sampler.notice_first_scope_push Time.now.to_f
|
805
|
-
@sampler.notice_transaction
|
806
|
-
@sampler.notice_push_scope
|
788
|
+
@sampler.notice_transaction(nil, {})
|
789
|
+
@sampler.notice_push_scope
|
807
790
|
@sampler.notice_pop_scope "a"
|
808
|
-
@sampler.notice_scope_empty
|
791
|
+
@sampler.notice_scope_empty(@txn)
|
809
792
|
|
810
793
|
assert_equal 0, @sampler.scope_depth
|
811
794
|
sample = @sampler.harvest(nil).first
|
@@ -816,13 +799,13 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
816
799
|
def test_double_scope_stack_empty
|
817
800
|
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
818
801
|
@sampler.notice_first_scope_push Time.now.to_f
|
819
|
-
@sampler.notice_transaction
|
820
|
-
@sampler.notice_push_scope
|
802
|
+
@sampler.notice_transaction(nil, {})
|
803
|
+
@sampler.notice_push_scope
|
821
804
|
@sampler.notice_pop_scope "a"
|
822
|
-
@sampler.notice_scope_empty
|
823
|
-
@sampler.notice_scope_empty
|
824
|
-
@sampler.notice_scope_empty
|
825
|
-
@sampler.notice_scope_empty
|
805
|
+
@sampler.notice_scope_empty(@txn)
|
806
|
+
@sampler.notice_scope_empty(@txn)
|
807
|
+
@sampler.notice_scope_empty(@txn)
|
808
|
+
@sampler.notice_scope_empty(@txn)
|
826
809
|
|
827
810
|
assert_not_nil @sampler.harvest(nil)[0]
|
828
811
|
end
|
@@ -856,7 +839,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
856
839
|
with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
|
857
840
|
t = Time.now
|
858
841
|
@sampler.notice_first_scope_push t.to_f
|
859
|
-
@sampler.notice_push_scope
|
842
|
+
@sampler.notice_push_scope((t+1).to_f)
|
860
843
|
|
861
844
|
segment = @sampler.send(:builder).current_segment
|
862
845
|
assert segment[:backtrace]
|
@@ -894,7 +877,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
894
877
|
|
895
878
|
def test_segment_obfuscated
|
896
879
|
@sampler.notice_first_scope_push Time.now.to_f
|
897
|
-
@sampler.notice_push_scope
|
880
|
+
@sampler.notice_push_scope
|
898
881
|
|
899
882
|
orig_sql = "SELECT * from Jim where id=66"
|
900
883
|
|
@@ -912,12 +895,12 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
912
895
|
with_config(:capture_params => capture) do
|
913
896
|
tt = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
914
897
|
@sampler.notice_first_scope_push Time.now.to_f
|
915
|
-
@sampler.notice_transaction(
|
916
|
-
@sampler.notice_scope_empty
|
898
|
+
@sampler.notice_transaction(nil, :param => 'hi')
|
899
|
+
@sampler.notice_scope_empty(@txn)
|
917
900
|
@sampler.harvest(nil)[0]
|
918
901
|
end
|
919
902
|
|
920
|
-
assert_equal (capture
|
903
|
+
assert_equal (capture ? 1 : 0), tt.params[:request_params].length
|
921
904
|
end
|
922
905
|
end
|
923
906
|
end
|
@@ -925,9 +908,9 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
925
908
|
def test_should_not_collect_segments_beyond_limit
|
926
909
|
with_config(:'transaction_tracer.limit_segments' => 3) do
|
927
910
|
run_sample_trace do
|
928
|
-
@sampler.notice_push_scope
|
911
|
+
@sampler.notice_push_scope
|
929
912
|
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'hallah'", nil, 0)
|
930
|
-
@sampler.notice_push_scope
|
913
|
+
@sampler.notice_push_scope
|
931
914
|
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'semolina'", nil, 0)
|
932
915
|
@sampler.notice_pop_scope "a11"
|
933
916
|
@sampler.notice_pop_scope "a1"
|
@@ -938,8 +921,8 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
938
921
|
|
939
922
|
def test_renaming_current_segment_midflight
|
940
923
|
@sampler.start_builder
|
941
|
-
@sampler.notice_push_scope
|
942
|
-
|
924
|
+
segment = @sampler.notice_push_scope
|
925
|
+
segment.metric_name = 'External/www.google.com/Net::HTTP/GET'
|
943
926
|
assert_nothing_raised do
|
944
927
|
@sampler.notice_pop_scope( 'External/www.google.com/Net::HTTP/GET' )
|
945
928
|
end
|
@@ -947,26 +930,48 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
947
930
|
|
948
931
|
def test_adding_segment_parameters
|
949
932
|
@sampler.start_builder
|
950
|
-
@sampler.notice_push_scope
|
933
|
+
@sampler.notice_push_scope
|
951
934
|
@sampler.add_segment_parameters( :transaction_guid => '97612F92E6194080' )
|
952
935
|
assert_equal '97612F92E6194080', @sampler.builder.current_segment[:transaction_guid]
|
953
936
|
end
|
954
937
|
|
938
|
+
class Dummy
|
939
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
940
|
+
def run(n)
|
941
|
+
n.times do
|
942
|
+
perform_action_with_newrelic_trace("smile") do
|
943
|
+
end
|
944
|
+
end
|
945
|
+
end
|
946
|
+
end
|
947
|
+
|
948
|
+
# TODO: this test seems to be destabilizing CI in a way that I don't grok.
|
949
|
+
def sadly_do_not_test_harvest_during_transaction_safety
|
950
|
+
n = 3000
|
951
|
+
harvester = Thread.new do
|
952
|
+
n.times { @sampler.harvest }
|
953
|
+
end
|
954
|
+
|
955
|
+
assert_nothing_raised { Dummy.new.run(n) }
|
956
|
+
|
957
|
+
harvester.join
|
958
|
+
end
|
959
|
+
|
955
960
|
private
|
956
961
|
|
957
962
|
def run_sample_trace(start = Time.now.to_f, stop = nil)
|
963
|
+
@sampler.notice_transaction(nil, {})
|
958
964
|
@sampler.notice_first_scope_push start
|
959
|
-
@sampler.
|
960
|
-
@sampler.notice_push_scope "a"
|
965
|
+
@sampler.notice_push_scope
|
961
966
|
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", nil, 0)
|
962
|
-
@sampler.notice_push_scope
|
967
|
+
@sampler.notice_push_scope
|
963
968
|
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", nil, 0)
|
964
969
|
yield if block_given?
|
965
970
|
@sampler.notice_pop_scope "ab"
|
966
|
-
@sampler.notice_push_scope
|
971
|
+
@sampler.notice_push_scope
|
967
972
|
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", nil, 0)
|
968
973
|
@sampler.notice_pop_scope "ac"
|
969
974
|
@sampler.notice_pop_scope "a"
|
970
|
-
@sampler.notice_scope_empty stop || Time.now.to_f
|
975
|
+
@sampler.notice_scope_empty(@txn, (stop || Time.now.to_f))
|
971
976
|
end
|
972
977
|
end
|
@@ -2,65 +2,70 @@
|
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
4
|
|
5
|
-
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
6
6
|
|
7
|
-
class NewRelic::Agent::
|
7
|
+
class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
attr_reader :txn
|
8
10
|
|
9
|
-
attr_reader :f
|
10
11
|
def setup
|
11
|
-
@
|
12
|
+
@txn = NewRelic::Agent::Transaction.new
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_request_parsing__none
|
15
|
-
assert_nil
|
16
|
-
assert_nil
|
16
|
+
assert_nil txn.uri
|
17
|
+
assert_nil txn.referer
|
17
18
|
end
|
19
|
+
|
18
20
|
def test_request_parsing__path
|
19
21
|
request = stub(:path => '/path?hello=bob#none')
|
20
|
-
|
21
|
-
assert_equal "/path",
|
22
|
+
txn.request = request
|
23
|
+
assert_equal "/path", txn.uri
|
22
24
|
end
|
25
|
+
|
23
26
|
def test_request_parsing__fullpath
|
24
27
|
request = stub(:fullpath => '/path?hello=bob#none')
|
25
|
-
|
26
|
-
assert_equal "/path",
|
28
|
+
txn.request = request
|
29
|
+
assert_equal "/path", txn.uri
|
27
30
|
end
|
31
|
+
|
28
32
|
def test_request_parsing__referer
|
29
33
|
request = stub(:referer => 'https://www.yahoo.com:8080/path/hello?bob=none&foo=bar')
|
30
|
-
|
31
|
-
assert_nil
|
32
|
-
assert_equal "https://www.yahoo.com:8080/path/hello",
|
34
|
+
txn.request = request
|
35
|
+
assert_nil txn.uri
|
36
|
+
assert_equal "https://www.yahoo.com:8080/path/hello", txn.referer
|
33
37
|
end
|
34
38
|
|
35
39
|
def test_request_parsing__uri
|
36
40
|
request = stub(:uri => 'http://creature.com/path?hello=bob#none', :referer => '/path/hello?bob=none&foo=bar')
|
37
|
-
|
38
|
-
assert_equal "/path",
|
39
|
-
assert_equal "/path/hello",
|
41
|
+
txn.request = request
|
42
|
+
assert_equal "/path", txn.uri
|
43
|
+
assert_equal "/path/hello", txn.referer
|
40
44
|
end
|
41
45
|
|
42
46
|
def test_request_parsing__hostname_only
|
43
47
|
request = stub(:uri => 'http://creature.com')
|
44
|
-
|
45
|
-
assert_equal "/",
|
46
|
-
assert_nil
|
48
|
+
txn.request = request
|
49
|
+
assert_equal "/", txn.uri
|
50
|
+
assert_nil txn.referer
|
47
51
|
end
|
52
|
+
|
48
53
|
def test_request_parsing__slash
|
49
54
|
request = stub(:uri => 'http://creature.com/')
|
50
|
-
|
51
|
-
assert_equal "/",
|
52
|
-
assert_nil
|
55
|
+
txn.request = request
|
56
|
+
assert_equal "/", txn.uri
|
57
|
+
assert_nil txn.referer
|
53
58
|
end
|
54
59
|
|
55
60
|
def test_queue_time
|
56
|
-
|
57
|
-
|
58
|
-
assert_equal 500,
|
61
|
+
txn.apdex_start = 1000
|
62
|
+
txn.start_time = 1500
|
63
|
+
assert_equal 500, txn.queue_time
|
59
64
|
end
|
60
65
|
|
61
66
|
def test_update_apdex_records_failed_when_specified
|
62
67
|
stats = NewRelic::Agent::Stats.new
|
63
|
-
NewRelic::Agent::
|
68
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 0.1, true)
|
64
69
|
assert_equal 0, stats.apdex_s
|
65
70
|
assert_equal 0, stats.apdex_t
|
66
71
|
assert_equal 1, stats.apdex_f
|
@@ -69,7 +74,7 @@ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
|
|
69
74
|
def test_update_apdex_records_satisfying
|
70
75
|
stats = NewRelic::Agent::Stats.new
|
71
76
|
with_config(:apdex_t => 1) do
|
72
|
-
NewRelic::Agent::
|
77
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 0.5, false)
|
73
78
|
end
|
74
79
|
assert_equal 1, stats.apdex_s
|
75
80
|
assert_equal 0, stats.apdex_t
|
@@ -79,7 +84,7 @@ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
|
|
79
84
|
def test_update_apdex_records_tolerating
|
80
85
|
stats = NewRelic::Agent::Stats.new
|
81
86
|
with_config(:apdex_t => 1) do
|
82
|
-
NewRelic::Agent::
|
87
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 1.5, false)
|
83
88
|
end
|
84
89
|
assert_equal 0, stats.apdex_s
|
85
90
|
assert_equal 1, stats.apdex_t
|
@@ -89,7 +94,7 @@ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
|
|
89
94
|
def test_update_apdex_records_failing
|
90
95
|
stats = NewRelic::Agent::Stats.new
|
91
96
|
with_config(:apdex_t => 1) do
|
92
|
-
NewRelic::Agent::
|
97
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 4.5, false)
|
93
98
|
end
|
94
99
|
assert_equal 0, stats.apdex_s
|
95
100
|
assert_equal 0, stats.apdex_t
|
@@ -107,31 +112,31 @@ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
|
|
107
112
|
:apdex => 1
|
108
113
|
}
|
109
114
|
|
110
|
-
txn_info.
|
115
|
+
txn_info.transaction.name = 'Controller/slow/txn'
|
111
116
|
with_config(config, :do_not_cast => true) do
|
112
|
-
NewRelic::Agent::
|
113
|
-
NewRelic::Agent::
|
114
|
-
NewRelic::Agent::
|
117
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 3.5, false)
|
118
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 5.5, false)
|
119
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 16.5, false)
|
115
120
|
end
|
116
121
|
assert_equal 1, stats.apdex_s
|
117
122
|
assert_equal 1, stats.apdex_t
|
118
123
|
assert_equal 1, stats.apdex_f
|
119
124
|
|
120
|
-
txn_info.
|
125
|
+
txn_info.transaction.name = 'Controller/fast/txn'
|
121
126
|
with_config(config, :do_not_cast => true) do
|
122
|
-
NewRelic::Agent::
|
123
|
-
NewRelic::Agent::
|
124
|
-
NewRelic::Agent::
|
127
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 0.05, false)
|
128
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 0.2, false)
|
129
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 0.5, false)
|
125
130
|
end
|
126
131
|
assert_equal 2, stats.apdex_s
|
127
132
|
assert_equal 2, stats.apdex_t
|
128
133
|
assert_equal 2, stats.apdex_f
|
129
134
|
|
130
|
-
txn_info.
|
135
|
+
txn_info.transaction.name = 'Controller/other/txn'
|
131
136
|
with_config(config, :do_not_cast => true) do
|
132
|
-
NewRelic::Agent::
|
133
|
-
NewRelic::Agent::
|
134
|
-
NewRelic::Agent::
|
137
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 0.5, false)
|
138
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 2, false)
|
139
|
+
NewRelic::Agent::Transaction.update_apdex(stats, 5, false)
|
135
140
|
end
|
136
141
|
assert_equal 3, stats.apdex_s
|
137
142
|
assert_equal 3, stats.apdex_t
|
@@ -145,11 +150,40 @@ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
|
|
145
150
|
NewRelic::Agent.instance.instance_variable_set(:@stats_engine, stats_engine)
|
146
151
|
|
147
152
|
with_config(:apdex_t => 2.5) do
|
148
|
-
NewRelic::Agent::
|
153
|
+
NewRelic::Agent::Transaction.record_apdex(metric, 1, 1, false)
|
149
154
|
end
|
150
155
|
assert_equal 2.5, stats_engine.lookup_stats('Apdex').min_call_time
|
151
156
|
assert_equal 2.5, stats_engine.lookup_stats('Apdex').max_call_time
|
152
157
|
assert_equal 2.5, stats_engine.lookup_stats('Apdex/Controller/some/txn').min_call_time
|
153
158
|
assert_equal 2.5, stats_engine.lookup_stats('Apdex/Controller/some/txn').max_call_time
|
154
159
|
end
|
160
|
+
|
161
|
+
def test_start_adds_controller_context_to_txn_stack
|
162
|
+
NewRelic::Agent::Transaction.start(:controller)
|
163
|
+
assert_equal 1, NewRelic::Agent::Transaction.stack.size
|
164
|
+
|
165
|
+
NewRelic::Agent::Transaction.start(:controller)
|
166
|
+
assert_equal 2, NewRelic::Agent::Transaction.stack.size
|
167
|
+
|
168
|
+
NewRelic::Agent::Transaction.stop('txn')
|
169
|
+
assert_equal 1, NewRelic::Agent::Transaction.stack.size
|
170
|
+
|
171
|
+
NewRelic::Agent::Transaction.stop('txn')
|
172
|
+
assert_equal 0, NewRelic::Agent::Transaction.stack.size
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_end_applies_transaction_name_rules
|
176
|
+
rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
|
177
|
+
'replacement' => '*',
|
178
|
+
'replace_all' => true)
|
179
|
+
NewRelic::Agent.instance.transaction_rules << rule
|
180
|
+
NewRelic::Agent::Transaction.start(:controller)
|
181
|
+
NewRelic::Agent.set_transaction_name('foo/1/bar/22')
|
182
|
+
NewRelic::Agent::Transaction.freeze_name
|
183
|
+
txn = NewRelic::Agent::Transaction.stop('txn')
|
184
|
+
assert_equal 'Controller/foo/*/bar/*', txn.name
|
185
|
+
ensure
|
186
|
+
NewRelic::Agent.instance.instance_variable_set(:@transaction_rules,
|
187
|
+
NewRelic::Agent::RulesEngine.new)
|
188
|
+
end
|
155
189
|
end
|
@@ -0,0 +1,75 @@
|
|
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/agent_logger'
|
7
|
+
require 'new_relic/agent/null_logger'
|
8
|
+
|
9
|
+
class URIUtilTest < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
fixture_tcp_socket(nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
def dummy_request(uri_string, opts={})
|
15
|
+
uri = URI(uri_string)
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
17
|
+
http.use_ssl = opts.has_key?(:use_ssl) ? opts[:use_ssl] : false
|
18
|
+
req = Net::HTTP::Get.new(opts[:path] || uri.request_uri)
|
19
|
+
[http, req]
|
20
|
+
end
|
21
|
+
|
22
|
+
def filter(uri_string, opts={})
|
23
|
+
NewRelic::Agent::URIUtil.filtered_uri_for(*dummy_request(uri_string, opts))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_filtered_uri_for
|
27
|
+
uri = "http://foo.com/bar/baz"
|
28
|
+
assert_equal("http://foo.com/bar/baz", filter(uri))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_filtered_uri_for_custom_port
|
32
|
+
uri = "http://foo.com:1234/bar/baz"
|
33
|
+
assert_equal("http://foo.com:1234/bar/baz", filter(uri))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_filtered_uri_omits_query_params
|
37
|
+
uri = "http://foo.com/bar/baz?a=1&b=2"
|
38
|
+
assert_equal("http://foo.com/bar/baz", filter(uri))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_filtered_uri_omits_fragment
|
42
|
+
uri = "http://foo.com/bar/baz#fragment"
|
43
|
+
assert_equal("http://foo.com/bar/baz", filter(uri, :path => '/bar/baz#fragment'))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_filtered_uri_omits_query_params_and_fragment
|
47
|
+
uri = "http://foo.com/bar/baz?a=1&b=2#fragment"
|
48
|
+
assert_equal("http://foo.com/bar/baz", filter(uri, :path => '/bar/baz?a=1&b=2#fragment'))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_filtered_uri_reflects_use_of_ssl
|
52
|
+
uri = 'https://foo.com/bar/baz'
|
53
|
+
assert_equal("https://foo.com/bar/baz", filter(uri, :use_ssl => true))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_filtered_uri_reflects_use_of_ssl_with_custom_port
|
57
|
+
uri = 'https://foo.com:9999/bar/baz'
|
58
|
+
assert_equal("https://foo.com:9999/bar/baz", filter(uri, :use_ssl => true))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_filtered_uri_for_with_full_uri_request_path
|
62
|
+
uri = "http://foo.com/bar/baz?a=1&b=2#fragment"
|
63
|
+
assert_equal("http://foo.com/bar/baz", filter(uri, :path => uri))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_filtered_uri_for_with_full_uri_request_path_https
|
67
|
+
uri = "https://foo.com/bar/baz?a=1&b=2#fragment"
|
68
|
+
assert_equal("https://foo.com/bar/baz", filter(uri, :path => uri, :use_ssl => true))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_strips_credentials_embedded_in_uri
|
72
|
+
uri = "http://user:pass@foo.com/bar/baz"
|
73
|
+
assert_equal("http://foo.com/bar/baz", filter(uri, :path => uri))
|
74
|
+
end
|
75
|
+
end
|