newrelic_rpm 2.9.9 → 2.10.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (120) hide show
  1. data/CHANGELOG +117 -49
  2. data/bin/mongrel_rpm +2 -2
  3. data/install.rb +42 -33
  4. data/lib/new_relic/agent.rb +149 -39
  5. data/lib/new_relic/agent/agent.rb +139 -122
  6. data/lib/new_relic/agent/busy_calculator.rb +91 -0
  7. data/lib/new_relic/agent/collection_helper.rb +11 -2
  8. data/lib/new_relic/agent/error_collector.rb +33 -27
  9. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +30 -26
  10. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  11. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +316 -105
  12. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
  13. data/lib/new_relic/agent/instrumentation/memcache.rb +18 -12
  14. data/lib/new_relic/agent/instrumentation/merb/errors.rb +2 -1
  15. data/lib/new_relic/agent/instrumentation/metric_frame.rb +258 -0
  16. data/lib/new_relic/agent/instrumentation/net.rb +7 -11
  17. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +1 -1
  18. data/lib/new_relic/agent/instrumentation/rack.rb +109 -0
  19. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +6 -5
  20. data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -7
  21. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
  22. data/lib/new_relic/agent/method_tracer.rb +305 -150
  23. data/lib/new_relic/agent/sampler.rb +34 -0
  24. data/lib/new_relic/agent/samplers/cpu_sampler.rb +11 -1
  25. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
  26. data/lib/new_relic/agent/samplers/memory_sampler.rb +22 -10
  27. data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
  28. data/lib/new_relic/agent/shim_agent.rb +10 -0
  29. data/lib/new_relic/agent/stats_engine.rb +16 -278
  30. data/lib/new_relic/agent/stats_engine/metric_stats.rb +118 -0
  31. data/lib/new_relic/agent/stats_engine/samplers.rb +81 -0
  32. data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
  33. data/lib/new_relic/agent/transaction_sampler.rb +73 -67
  34. data/lib/new_relic/agent/worker_loop.rb +69 -68
  35. data/lib/new_relic/commands/deployments.rb +4 -6
  36. data/lib/new_relic/control.rb +121 -60
  37. data/lib/new_relic/control/external.rb +13 -0
  38. data/lib/new_relic/control/merb.rb +2 -0
  39. data/lib/new_relic/control/rails.rb +16 -6
  40. data/lib/new_relic/control/ruby.rb +8 -5
  41. data/lib/new_relic/control/sinatra.rb +18 -0
  42. data/lib/new_relic/delayed_job_injection.rb +25 -0
  43. data/lib/new_relic/histogram.rb +89 -0
  44. data/lib/new_relic/local_environment.rb +64 -30
  45. data/lib/new_relic/metric_data.rb +15 -6
  46. data/lib/new_relic/metric_parser.rb +14 -1
  47. data/lib/new_relic/metric_parser/active_record.rb +14 -0
  48. data/lib/new_relic/metric_parser/controller.rb +5 -2
  49. data/lib/new_relic/metric_parser/external.rb +50 -0
  50. data/lib/new_relic/metric_parser/other_transaction.rb +15 -0
  51. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  52. data/lib/new_relic/metric_spec.rb +39 -20
  53. data/lib/new_relic/metrics.rb +9 -7
  54. data/lib/new_relic/noticed_error.rb +6 -8
  55. data/lib/new_relic/rack/metric_app.rb +5 -4
  56. data/lib/new_relic/rack/{newrelic.ru → mongrel_rpm.ru} +4 -4
  57. data/lib/new_relic/rack/newrelic.yml +1 -0
  58. data/lib/new_relic/{rack.rb → rack_app.rb} +0 -0
  59. data/lib/new_relic/recipes.rb +1 -1
  60. data/lib/new_relic/stats.rb +40 -26
  61. data/lib/new_relic/transaction_analysis.rb +5 -2
  62. data/lib/new_relic/transaction_sample.rb +134 -55
  63. data/lib/new_relic/version.rb +27 -20
  64. data/lib/new_relic_api.rb +67 -47
  65. data/lib/newrelic_rpm.rb +5 -5
  66. data/lib/tasks/tests.rake +2 -0
  67. data/newrelic.yml +69 -29
  68. data/test/active_record_fixtures.rb +2 -2
  69. data/test/config/newrelic.yml +4 -7
  70. data/test/config/test_control.rb +1 -2
  71. data/test/new_relic/agent/active_record_instrumentation_test.rb +115 -31
  72. data/test/new_relic/agent/agent_controller_test.rb +274 -0
  73. data/test/new_relic/agent/agent_test_controller.rb +42 -6
  74. data/test/new_relic/agent/busy_calculator_test.rb +79 -0
  75. data/test/new_relic/agent/collection_helper_test.rb +10 -3
  76. data/test/new_relic/agent/error_collector_test.rb +35 -17
  77. data/test/new_relic/agent/method_tracer_test.rb +60 -20
  78. data/test/new_relic/agent/metric_data_test.rb +2 -2
  79. data/test/new_relic/agent/metric_frame_test.rb +51 -0
  80. data/test/new_relic/agent/net_instrumentation_test.rb +77 -0
  81. data/test/new_relic/agent/{agent_test.rb → rpm_agent_test.rb} +26 -5
  82. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  83. data/test/new_relic/{samplers_test.rb → agent/stats_engine/samplers_test.rb} +23 -22
  84. data/test/new_relic/agent/{stats_engine_test.rb → stats_engine/stats_engine_test.rb} +19 -101
  85. data/test/new_relic/agent/task_instrumentation_test.rb +176 -0
  86. data/test/new_relic/agent/transaction_sample_builder_test.rb +2 -2
  87. data/test/new_relic/agent/transaction_sample_test.rb +53 -38
  88. data/test/new_relic/agent/transaction_sampler_test.rb +101 -33
  89. data/test/new_relic/agent/worker_loop_test.rb +16 -14
  90. data/test/new_relic/control_test.rb +26 -13
  91. data/test/new_relic/metric_parser_test.rb +31 -1
  92. data/test/new_relic/metric_spec_test.rb +2 -2
  93. data/test/new_relic/stats_test.rb +0 -8
  94. data/test/new_relic/version_number_test.rb +31 -1
  95. data/test/test_helper.rb +37 -1
  96. data/ui/controllers/newrelic_controller.rb +19 -11
  97. data/ui/helpers/google_pie_chart.rb +5 -11
  98. data/ui/helpers/newrelic_helper.rb +40 -35
  99. data/ui/views/layouts/newrelic_default.rhtml +7 -7
  100. data/ui/views/newrelic/_sample.rhtml +5 -1
  101. data/ui/views/newrelic/images/new-relic-rpm-desktop.gif +0 -0
  102. data/ui/views/newrelic/images/textmate.png +0 -0
  103. data/ui/views/newrelic/index.rhtml +13 -1
  104. data/ui/views/newrelic/show_sample.rhtml +5 -2
  105. data/ui/views/newrelic/stylesheets/style.css +54 -3
  106. metadata +65 -145
  107. data/Manifest +0 -143
  108. data/Rakefile +0 -22
  109. data/init.rb +0 -38
  110. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +0 -127
  111. data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +0 -14
  112. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +0 -13
  113. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +0 -38
  114. data/lib/new_relic/agent/patch_const_missing.rb +0 -125
  115. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +0 -22
  116. data/lib/new_relic/metric_parser/database.rb +0 -23
  117. data/newrelic_rpm.gemspec +0 -35
  118. data/test/new_relic/agent/classloader_patch_test.rb +0 -56
  119. data/test/new_relic/agent/controller_test.rb +0 -107
  120. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +0 -70
@@ -106,9 +106,9 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
106
106
 
107
107
  # Need to allow substantial headroom on the upper bound to prevent
108
108
  # spurious errors.
109
- assert delta >= 30, "delta #{delta} should be between 30 and 100"
109
+ assert delta >= 28, "delta #{delta} should be between 28 and 100"
110
110
  # disable this test for a couple days:
111
- assert delta <= 100, "delta #{delta} should be between 30 and 100"
111
+ assert delta <= 100, "delta #{delta} should be between 28 and 100"
112
112
 
113
113
  # ensure none of the segments have this regex
114
114
  without_code_loading.each_segment do |segment|
@@ -1,8 +1,5 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
2
  require 'new_relic/agent/mock_ar_connection'
3
- ##require 'new_relic/agent/testable_agent'
4
- ##require 'new_relic/agent/transaction_sampler'
5
- ##require 'new_relic/transaction_sample'
6
3
  require 'test/unit'
7
4
 
8
5
  ::SQL_STATEMENT = "SELECT * from sandwiches"
@@ -14,7 +11,7 @@ NewRelic::TransactionSample::Segment.class_eval do
14
11
 
15
12
  end
16
13
  class NewRelic::TransationSampleTest < Test::Unit::TestCase
17
-
14
+ include TransactionSampleTestHelper
18
15
  def setup
19
16
  NewRelic::Agent.manual_start
20
17
  end
@@ -22,7 +19,7 @@ class NewRelic::TransationSampleTest < Test::Unit::TestCase
22
19
  def test_sql
23
20
  assert ActiveRecord::Base.test_connection({}).disconnected == false
24
21
 
25
- t = get_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
22
+ t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
26
23
 
27
24
  s = t.prepare_to_send(:obfuscate_sql => true, :explain_enabled => true, :explain_sql => 0.00000001)
28
25
 
@@ -48,7 +45,7 @@ class NewRelic::TransationSampleTest < Test::Unit::TestCase
48
45
  def test_disable_sql
49
46
  t = nil
50
47
  NewRelic::Agent.disable_sql_recording do
51
- t = get_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
48
+ t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
52
49
  end
53
50
 
54
51
  s = t.prepare_to_send(:obfuscate_sql => true, :explain_sql => 0.00000001)
@@ -61,17 +58,17 @@ class NewRelic::TransationSampleTest < Test::Unit::TestCase
61
58
 
62
59
  def test_disable_tt
63
60
  NewRelic::Agent.disable_transaction_tracing do
64
- t = get_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
61
+ t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
65
62
  assert t.nil?
66
63
  end
67
-
68
- t = get_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
64
+ end
65
+ def test_enabled_tt
66
+ t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
69
67
  assert t
70
68
  end
71
69
 
72
-
73
70
  def test_record_sql_off
74
- t = get_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
71
+ t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
75
72
 
76
73
  s = t.prepare_to_send(:obfuscate_sql => true, :explain_sql => 0.00000001, :record_sql => :off)
77
74
 
@@ -82,7 +79,7 @@ class NewRelic::TransationSampleTest < Test::Unit::TestCase
82
79
 
83
80
 
84
81
  def test_record_sql_raw
85
- t = get_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
82
+ t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
86
83
 
87
84
  s = t.prepare_to_send(:obfuscate_sql => true, :explain_sql => 0.00000001, :record_sql => :raw)
88
85
 
@@ -97,7 +94,7 @@ class NewRelic::TransationSampleTest < Test::Unit::TestCase
97
94
 
98
95
 
99
96
  def test_record_sql_obfuscated
100
- t = get_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
97
+ t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
101
98
 
102
99
  s = t.prepare_to_send(:obfuscate_sql => true, :explain_sql => 0.00000001, :record_sql => :obfuscated)
103
100
 
@@ -114,13 +111,39 @@ class NewRelic::TransationSampleTest < Test::Unit::TestCase
114
111
  def test_sql_throw
115
112
  ActiveRecord::Base.test_connection({}).throw = true
116
113
 
117
- t = get_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
114
+ t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
118
115
 
119
116
  # the sql connection will throw
120
117
  t.prepare_to_send(:obfuscate_sql => true, :explain_sql => 0.00000001)
121
118
  end
122
119
 
120
+
123
121
  def test_exclusive_duration
122
+ t = nested_sample
123
+ s1 = t.root_segment.called_segments.first
124
+ assert_equal 3.0, s1.duration
125
+ assert_equal 2.0, s1.exclusive_duration
126
+ end
127
+
128
+ def test_count
129
+ assert_equal 4, nested_sample.count_segments
130
+ end
131
+
132
+
133
+ def test_truncate
134
+ sample = nested_sample
135
+ sample.truncate(2)
136
+ assert_equal 2, sample.count_segments
137
+
138
+ sample = large_sample
139
+ assert_equal 101, large_sample.count_segments
140
+ sample.truncate(2)
141
+ assert_equal 2, sample.count_segments
142
+ assert_equal 101, sample.params[:segment_count]
143
+ end
144
+
145
+ private
146
+ def nested_sample
124
147
  t = NewRelic::TransactionSample.new
125
148
 
126
149
  t.params[:test] = "hi"
@@ -133,39 +156,31 @@ class NewRelic::TransationSampleTest < Test::Unit::TestCase
133
156
 
134
157
  s2.params[:test] = "test"
135
158
 
136
- s2.to_s
137
-
138
159
  s1.add_called_segment(s2)
139
-
140
160
  s2.end_trace 3.0
141
161
  s1.end_trace 4.0
142
162
 
143
- t.to_s
163
+ s3 = t.create_segment(4.0, "post_filter")
164
+ t.root_segment.add_called_segment(s3)
165
+ s3.end_trace 6.0
144
166
 
145
- assert_equal 3.0, s1.duration
146
- assert_equal 2.0, s1.exclusive_duration
167
+ s4 = t.create_segment(6.0, "post_filter")
168
+ t.root_segment.add_called_segment(s4)
169
+ s4.end_trace 7.0
170
+ t
147
171
  end
148
172
 
149
-
150
-
151
- private
152
- def get_sql_transaction(*sql)
153
- sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
154
- sampler.notice_first_scope_push Time.now.to_f
155
- sampler.notice_transaction '/path', nil, :jim => "cool"
156
- sampler.notice_push_scope "a"
157
-
158
- sampler.notice_transaction '/path/2', nil, :jim => "cool"
159
-
160
- sql.each {|sql_statement| sampler.notice_sql(sql_statement, {:adapter => "test"}, 0 ) }
161
-
162
- sleep 1.0
173
+ def large_sample
174
+ t = NewRelic::TransactionSample.new
163
175
 
164
- sampler.notice_pop_scope "a"
165
- sampler.notice_scope_empty
176
+ s1 = t.create_segment(1.0, "controller")
177
+ t.root_segment.add_called_segment(s1)
166
178
 
167
- sampler.samples[0]
179
+ 100.times do
180
+ s1.add_called_segment(t.create_segment(1.0, "segment"))
181
+ end
182
+ t
168
183
  end
169
184
 
170
-
185
+
171
186
  end
@@ -1,18 +1,32 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
- ##require 'new_relic/agent/transaction_sampler'
3
2
 
4
- NewRelic::Agent::TransactionSampler.send :public, :builder
5
-
6
- class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
3
+ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
7
4
 
5
+ module MockGCStats
6
+
7
+ def time
8
+ return 0 if @@values.empty?
9
+ raise "too many calls" if @@index >= @@values.size
10
+ @@curtime ||= 0
11
+ @@curtime += (@@values[@@index] * 1e09).to_i
12
+ @@index += 1
13
+ @@curtime
14
+ end
15
+
16
+ def self.mock_values= array
17
+ @@values = array
18
+ @@index = 0
19
+ end
20
+
21
+ end
22
+
8
23
  def setup
9
24
  Thread::current[:record_sql] = nil
10
- mock_agent = mock()
11
- stats_engine_mock = mock()
12
- stats_engine_mock.stubs(:add_scope_stack_listener)
13
- mock_agent.stubs(:stats_engine).returns(stats_engine_mock)
14
- mock_agent.stubs(:set_sql_obfuscator).returns(stats_engine_mock)
15
- @sampler = NewRelic::Agent::TransactionSampler.new(mock_agent)
25
+ agent = NewRelic::Agent.instance
26
+ stats_engine = NewRelic::Agent::StatsEngine.new
27
+ agent.stubs(:stats_engine).returns(stats_engine)
28
+ @sampler = NewRelic::Agent::TransactionSampler.new
29
+ stats_engine.transaction_sampler = @sampler
16
30
  end
17
31
 
18
32
  def test_multiple_samples
@@ -28,6 +42,56 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
28
42
  assert_equal "a", samples.last.root_segment.called_segments[0].metric_name
29
43
  end
30
44
 
45
+ def test_sample_tree
46
+ assert_equal 0, @sampler.scope_depth
47
+
48
+ @sampler.notice_first_scope_push Time.now.to_f
49
+ @sampler.notice_transaction "/path", nil, {}
50
+ @sampler.notice_push_scope "a"
51
+
52
+ @sampler.notice_push_scope "b"
53
+ @sampler.notice_pop_scope "b"
54
+
55
+ @sampler.notice_push_scope "c"
56
+ @sampler.notice_push_scope "d"
57
+ @sampler.notice_pop_scope "d"
58
+ @sampler.notice_pop_scope "c"
59
+
60
+ @sampler.notice_pop_scope "a"
61
+ @sampler.notice_scope_empty
62
+ sample = @sampler.harvest([],0.0).first
63
+ assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
64
+
65
+ end
66
+
67
+ def test_sample__gc_stats
68
+ GC.extend MockGCStats
69
+ # These are effectively Garbage Collects, detected each time GC.time is
70
+ # called by the transaction sampler. One time value in seconds for each call.
71
+ MockGCStats.mock_values = [0,0,0,1,0,0,1,0,0,0,0,0,0,0,0]
72
+ assert_equal 0, @sampler.scope_depth
73
+
74
+ @sampler.notice_first_scope_push Time.now.to_f
75
+ @sampler.notice_transaction "/path", nil, {}
76
+ @sampler.notice_push_scope "a"
77
+
78
+ @sampler.notice_push_scope "b"
79
+ @sampler.notice_pop_scope "b"
80
+
81
+ @sampler.notice_push_scope "c"
82
+ @sampler.notice_push_scope "d"
83
+ @sampler.notice_pop_scope "d"
84
+ @sampler.notice_pop_scope "c"
85
+
86
+ @sampler.notice_pop_scope "a"
87
+ @sampler.notice_scope_empty
88
+
89
+ sample = @sampler.harvest([],0.0).first
90
+ assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
91
+ ensure
92
+ MockGCStats.mock_values = []
93
+ end
94
+
31
95
  def test_sample_id
32
96
  run_sample_trace do
33
97
  assert @sampler.current_sample_id != 0, @sampler.current_sample_id
@@ -49,10 +113,10 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
49
113
  not_as_slow = @sampler.harvest(slowest, 0)[0]
50
114
  assert not_as_slow == slowest
51
115
 
52
- run_sample_trace { sleep 0.6 }
116
+ run_sample_trace { sleep 0.601 }
53
117
  new_slowest = @sampler.harvest(slowest, 0)[0]
54
118
  assert new_slowest != slowest
55
- assert new_slowest.duration >= 0.6
119
+ assert new_slowest.duration >= 0.600, "Slowest duration must be > 0.6: #{new_slowest.duration}"
56
120
  end
57
121
 
58
122
 
@@ -103,6 +167,10 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
103
167
  @sampler.notice_push_scope "a"
104
168
  @sampler.notice_pop_scope "a"
105
169
  @sampler.notice_scope_empty
170
+
171
+ assert_equal 0, @sampler.scope_depth
172
+ sample = @sampler.harvest(nil, 0.0).first
173
+ assert_equal "ROOT{a}", sample.to_s_compact
106
174
  end
107
175
 
108
176
  def test_double_scope_stack_empty
@@ -128,7 +196,7 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
128
196
 
129
197
  @sampler.notice_sql("test", nil, 0)
130
198
 
131
- segment = @sampler.builder.current_segment
199
+ segment = @sampler.send(:builder).current_segment
132
200
 
133
201
  assert_nil segment[:sql]
134
202
  end
@@ -140,7 +208,7 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
140
208
 
141
209
  @sampler.notice_sql("test", nil, 1)
142
210
 
143
- segment = @sampler.builder.current_segment
211
+ segment = @sampler.send(:builder).current_segment
144
212
 
145
213
  assert segment[:sql]
146
214
  assert segment[:backtrace]
@@ -152,7 +220,7 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
152
220
  @sampler.notice_first_scope_push t.to_f
153
221
  @sampler.notice_push_scope 'Bill', (t+1.second).to_f
154
222
 
155
- segment = @sampler.builder.current_segment
223
+ segment = @sampler.send(:builder).current_segment
156
224
  assert segment[:backtrace]
157
225
  end
158
226
 
@@ -164,7 +232,7 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
164
232
 
165
233
  @sampler.notice_sql("test", nil, 1)
166
234
 
167
- segment = @sampler.builder.current_segment
235
+ segment = @sampler.send(:builder).current_segment
168
236
 
169
237
  assert segment[:sql]
170
238
  assert_nil segment[:backtrace]
@@ -182,7 +250,7 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
182
250
  len += sql.length
183
251
  end
184
252
 
185
- segment = @sampler.builder.current_segment
253
+ segment = @sampler.send(:builder).current_segment
186
254
 
187
255
  sql = segment[:sql]
188
256
 
@@ -198,7 +266,7 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
198
266
 
199
267
  @sampler.notice_sql(orig_sql, nil, 0)
200
268
 
201
- segment = @sampler.builder.current_segment
269
+ segment = @sampler.send(:builder).current_segment
202
270
 
203
271
  assert_equal orig_sql, segment[:sql]
204
272
  assert_equal "SELECT * from Jim where id=?", segment.obfuscated_sql
@@ -223,52 +291,52 @@ class NewRelic::Agent::TransationSamplerTest < Test::Unit::TestCase
223
291
 
224
292
  # basic statement
225
293
  assert_equal "INSERT INTO X values(?,?, ? , ?)",
226
- @sampler.default_sql_obfuscator("INSERT INTO X values('test',0, 1 , 2)")
294
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT INTO X values('test',0, 1 , 2)")
227
295
 
228
296
  # escaped literals
229
297
  assert_equal "INSERT INTO X values(?, ?,?, ? , ?)",
230
- @sampler.default_sql_obfuscator("INSERT INTO X values('', 'jim''s ssn',0, 1 , 'jim''s son''s son')")
298
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT INTO X values('', 'jim''s ssn',0, 1 , 'jim''s son''s son')")
231
299
 
232
300
  # multiple string literals
233
301
  assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
234
- @sampler.default_sql_obfuscator("INSERT INTO X values('jim''s ssn','x',0, 1 , 2)")
302
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT INTO X values('jim''s ssn','x',0, 1 , 2)")
235
303
 
236
304
  # empty string literal
237
305
  # NOTE: the empty string literal resolves to empty string, which for our purposes is acceptable
238
306
  assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
239
- @sampler.default_sql_obfuscator("INSERT INTO X values('','x',0, 1 , 2)")
307
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT INTO X values('','x',0, 1 , 2)")
240
308
 
241
309
  # try a select statement
242
310
  assert_equal "select * from table where name=? and ssn=?",
243
- @sampler.default_sql_obfuscator("select * from table where name='jim gochee' and ssn=0012211223")
311
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, "select * from table where name='jim gochee' and ssn=0012211223")
244
312
 
245
313
  # number literals embedded in sql - oh well
246
314
  assert_equal "select * from table_? where name=? and ssn=?",
247
- @sampler.default_sql_obfuscator("select * from table_007 where name='jim gochee' and ssn=0012211223")
315
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, "select * from table_007 where name='jim gochee' and ssn=0012211223")
248
316
  end
249
317
 
250
318
  def test_sql_normalization__single_quotes
251
319
  assert_equal "INSERT ? into table",
252
- @sampler.default_sql_obfuscator("INSERT 'this isn''t a real value' into table")
320
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT 'this isn''t a real value' into table")
253
321
  assert_equal "INSERT ? into table",
254
- @sampler.default_sql_obfuscator(%q[INSERT '"' into table])
322
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT '"' into table])
255
323
  assert_equal "INSERT ? into table",
256
- @sampler.default_sql_obfuscator(%q[INSERT ' "some text" \" ' into table])
324
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT ' "some text" \" ' into table])
257
325
  # could not get this one licked. no biggie
258
326
  # assert_equal "INSERT ? into table",
259
- # @sampler.default_sql_obfuscator(%q[INSERT '\'' into table])
327
+ # NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT '\'' into table])
260
328
  assert_equal "INSERT ? into table",
261
- @sampler.default_sql_obfuscator(%q[INSERT ''' ' into table])
329
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT ''' ' into table])
262
330
  end
263
331
  def test_sql_normalization__double_quotes
264
332
  assert_equal "INSERT ? into table",
265
- @sampler.default_sql_obfuscator(%q[INSERT "this isn't a real value" into table])
333
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT "this isn't a real value" into table])
266
334
  assert_equal "INSERT ? into table",
267
- @sampler.default_sql_obfuscator(%q[INSERT "'" into table])
335
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT "'" into table])
268
336
  assert_equal "INSERT ? into table",
269
- @sampler.default_sql_obfuscator(%q[INSERT " \" " into table])
337
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT " \" " into table])
270
338
  assert_equal "INSERT ? into table",
271
- @sampler.default_sql_obfuscator(%q[INSERT " 'some text' " into table])
339
+ NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT " 'some text' " into table])
272
340
  end
273
341
  def test_sql_obfuscation_filters
274
342
  orig = NewRelic::Agent.agent.obfuscator
@@ -28,8 +28,8 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
28
28
  def test_add_tasks_with_different_periods
29
29
  @last_executed = nil
30
30
 
31
- period1 = 0.2
32
- period2 = 0.35
31
+ period1 = 0.5
32
+ period2 = 0.7
33
33
 
34
34
  @worker_loop.add_task(period1) do
35
35
  @last_executed = 1
@@ -40,24 +40,24 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
40
40
  end
41
41
 
42
42
  @worker_loop.run_next_task
43
- assert_equal @last_executed, 1 # 0.2 s
44
- check_test_timestamp(0.2)
43
+ assert_equal @last_executed, 1
44
+ check_test_timestamp(0.5)
45
45
 
46
46
  @worker_loop.run_next_task
47
- assert_equal @last_executed, 2 # 0.35 s
48
- check_test_timestamp(0.35)
47
+ assert_equal @last_executed, 2
48
+ check_test_timestamp(0.7)
49
49
 
50
50
  @worker_loop.run_next_task
51
- assert_equal @last_executed, 1 # 0.4 s
52
- check_test_timestamp(0.4)
51
+ assert_equal @last_executed, 1
52
+ check_test_timestamp(1.0)
53
53
 
54
54
  @worker_loop.run_next_task
55
- assert_equal @last_executed, 1 # 0.6 s
56
- check_test_timestamp(0.6)
55
+ assert_equal @last_executed, 2
56
+ check_test_timestamp(1.4)
57
57
 
58
58
  @worker_loop.run_next_task
59
- assert_equal @last_executed, 2 # 0.7 s
60
- check_test_timestamp(0.7)
59
+ assert_equal @last_executed, 1
60
+ check_test_timestamp(1.5)
61
61
  end
62
62
 
63
63
  def test_task_error__standard
@@ -93,9 +93,11 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
93
93
  end
94
94
 
95
95
  private
96
+ # The test is expected to have lasted no less than expected
97
+ # and no more than expected + 100 ms.
96
98
  def check_test_timestamp(expected)
97
99
  ts = Time.now - @test_start_time
98
- delta = (expected - ts).abs
99
- assert(delta < 0.05, "#{delta} exceeds 50 milliseconds")
100
+ delta = ts - expected
101
+ assert(delta <= 0.250, "#{ts} duration includes a delay of #{delta} that exceeds 250 milliseconds")
100
102
  end
101
103
  end