newrelic_rpm 3.1.2 → 3.2.0.beta1

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 (69) hide show
  1. data/CHANGELOG +9 -0
  2. data/lib/new_relic/agent.rb +12 -3
  3. data/lib/new_relic/agent/agent.rb +99 -97
  4. data/lib/new_relic/agent/database.rb +203 -0
  5. data/lib/new_relic/agent/instrumentation/active_merchant.rb +2 -0
  6. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -0
  7. data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -0
  8. data/lib/new_relic/agent/instrumentation/data_mapper.rb +2 -0
  9. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -0
  10. data/lib/new_relic/agent/instrumentation/memcache.rb +23 -13
  11. data/lib/new_relic/agent/instrumentation/merb/controller.rb +2 -1
  12. data/lib/new_relic/agent/instrumentation/merb/errors.rb +2 -0
  13. data/lib/new_relic/agent/instrumentation/metric_frame.rb +7 -1
  14. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -0
  15. data/lib/new_relic/agent/instrumentation/net.rb +2 -0
  16. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -0
  17. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +63 -36
  18. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +2 -0
  19. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +5 -2
  20. data/lib/new_relic/agent/instrumentation/rails/errors.rb +4 -2
  21. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +56 -2
  22. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +5 -2
  23. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +3 -1
  24. data/lib/new_relic/agent/instrumentation/sunspot.rb +2 -0
  25. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +2 -1
  26. data/lib/new_relic/agent/shim_agent.rb +1 -0
  27. data/lib/new_relic/agent/sql_sampler.rb +230 -0
  28. data/lib/new_relic/agent/stats_engine/transactions.rb +10 -0
  29. data/lib/new_relic/agent/transaction_sampler.rb +11 -6
  30. data/lib/new_relic/collection_helper.rb +7 -4
  31. data/lib/new_relic/commands/deployments.rb +1 -1
  32. data/lib/new_relic/commands/install.rb +2 -13
  33. data/lib/new_relic/control/class_methods.rb +4 -3
  34. data/lib/new_relic/control/configuration.rb +21 -0
  35. data/lib/new_relic/control/frameworks/rails.rb +1 -1
  36. data/lib/new_relic/control/logging_methods.rb +17 -6
  37. data/lib/new_relic/delayed_job_injection.rb +1 -1
  38. data/lib/new_relic/local_environment.rb +8 -14
  39. data/lib/new_relic/rack/developer_mode.rb +1 -0
  40. data/lib/new_relic/stats.rb +1 -0
  41. data/lib/new_relic/transaction_sample.rb +5 -60
  42. data/lib/new_relic/transaction_sample/segment.rb +7 -82
  43. data/lib/new_relic/version.rb +3 -3
  44. data/newrelic_rpm.gemspec +8 -3
  45. data/test/new_relic/agent/agent/connect_test.rb +95 -0
  46. data/test/new_relic/agent/agent/start_test.rb +0 -85
  47. data/test/new_relic/agent/agent/start_worker_thread_test.rb +1 -0
  48. data/test/new_relic/agent/agent_test.rb +0 -73
  49. data/test/new_relic/agent/browser_monitoring_test.rb +1 -1
  50. data/test/new_relic/agent/database_test.rb +160 -0
  51. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -0
  52. data/test/new_relic/agent/memcache_instrumentation_test.rb +14 -15
  53. data/test/new_relic/agent/sql_sampler_test.rb +135 -0
  54. data/test/new_relic/agent/transaction_sampler_test.rb +12 -3
  55. data/test/new_relic/collection_helper_test.rb +4 -4
  56. data/test/new_relic/control/configuration_test.rb +31 -0
  57. data/test/new_relic/control/logging_methods_test.rb +20 -4
  58. data/test/new_relic/delayed_job_injection_test.rb +1 -1
  59. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  60. data/test/new_relic/stats_test.rb +3 -3
  61. data/test/new_relic/transaction_sample/segment_test.rb +4 -92
  62. data/test/new_relic/transaction_sample_test.rb +1 -1
  63. data/test/test_helper.rb +1 -1
  64. data/ui/helpers/developer_mode_helper.rb +14 -8
  65. data/ui/helpers/google_pie_chart.rb +0 -1
  66. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +5 -0
  67. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
  68. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
  69. metadata +15 -10
@@ -49,6 +49,27 @@ module NewRelic
49
49
  end
50
50
  end
51
51
 
52
+ def merge_server_side_config(data)
53
+ remove_server_controlled_configs
54
+ config = Hash.new
55
+ data.each_pair do |key, value|
56
+ if key.include?('.')
57
+ key = key.split('.')
58
+ config[key.first] ||= Hash.new
59
+ config[key.first][key[1]] = value
60
+ else
61
+ config[key] = value
62
+ end
63
+ end
64
+ merge_options(config)
65
+ end
66
+
67
+ def remove_server_controlled_configs
68
+ settings.delete('transaction_tracer')
69
+ settings.delete('error_collector')
70
+ settings.delete('capture_params')
71
+ end
72
+
52
73
  def [](key)
53
74
  fetch(key)
54
75
  end
@@ -80,7 +80,7 @@ module NewRelic
80
80
  rescue Exception => e
81
81
  log!("Error installing New Relic Developer Mode: #{e.inspect}", :error)
82
82
  end
83
- else
83
+ elsif rails_config
84
84
  log!("Developer mode not available for Rails versions prior to 2.2", :warn)
85
85
  end
86
86
  end
@@ -91,15 +91,21 @@ module NewRelic
91
91
  end
92
92
 
93
93
  # Sets up and caches the log path, attempting to create it if it
94
- # does not exist. this comes from the configuration variable
95
- # 'log_file_path' in the configuration file.
94
+ # does not exist. If it does not succeed, it prints an
95
+ # error and returns nil.
96
+ # This comes from the configuration variable 'log_file_path' in the configuration file.
96
97
  def log_path
97
98
  return @log_path if @log_path
98
99
  if log_to_stdout?
99
100
  @log_path = nil
100
101
  else
101
- @log_path = find_or_create_file_path(fetch('log_file_path', 'log'))
102
- log!("Error creating log directory for New Relic log file, using standard out.", :error) unless @log_path
102
+ if ENV['NEW_RELIC_LOG']
103
+ log_path_setting = File.dirname(ENV['NEW_RELIC_LOG'])
104
+ else
105
+ log_path_setting = fetch('log_file_path', 'log')
106
+ end
107
+ @log_path = find_or_create_file_path(log_path_setting)
108
+ log!("Error creating log directory #{log_path_setting}, using standard out for logging.", :warn) unless @log_path
103
109
  end
104
110
  @log_path
105
111
  end
@@ -116,7 +122,8 @@ module NewRelic
116
122
 
117
123
  def log_to_stdout?
118
124
  return true if @stdout
119
- if fetch('log_file_path', 'log') == 'STDOUT'
125
+ destination = ENV['NEW_RELIC_LOG'] || fetch('log_file_path', 'log')
126
+ if destination.upcase == 'STDOUT'
120
127
  @stdout = true
121
128
  end
122
129
  end
@@ -124,7 +131,11 @@ module NewRelic
124
131
  # Retrieves the log file's name from the config file option
125
132
  #'log_file_name', defaulting to 'newrelic_agent.log'
126
133
  def log_file_name
127
- fetch('log_file_name', 'newrelic_agent.log')
134
+ if ENV['NEW_RELIC_LOG']
135
+ File.basename(ENV['NEW_RELIC_LOG'])
136
+ else
137
+ fetch('log_file_name', 'newrelic_agent.log')
138
+ end
128
139
  end
129
140
  end
130
141
  include LoggingMethods
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  DependencyDetection.defer do
15
15
  depends_on do
16
- defined?(::Delayed) && defined?(::Delayed::Worker)
16
+ defined?(::Delayed) && defined?(::Delayed::Worker) && !NewRelic::Control.instance['disable_dj']
17
17
  end
18
18
 
19
19
  executes do
@@ -217,6 +217,7 @@ module NewRelic
217
217
  ObjectSpace.each_object(klass) do |x|
218
218
  return x
219
219
  end
220
+ return nil
220
221
  end
221
222
 
222
223
  # Sets the @mongrel instance variable if we can find a Mongrel::HttpServer
@@ -228,21 +229,13 @@ module NewRelic
228
229
  @mongrel
229
230
  end
230
231
 
231
- # sets the @unicorn instance variable if we can find a Unicorn::HttpServer
232
- def unicorn
233
- return @unicorn if @unicorn
234
- if (defined?(::Unicorn) && defined?(::Unicorn::HttpServer)) && working_jruby?
235
- @unicorn = find_class_in_object_space(::Unicorn::HttpServer)
236
- end
237
- @unicorn
238
- end
239
-
240
232
  private
241
233
 
242
234
  # Although you can override the framework with NEWRELIC_DISPATCHER this
243
235
  # is not advisable since it implies certain api's being available.
244
236
  def discover_dispatcher
245
237
  @dispatcher ||= ENV['NEWRELIC_DISPATCHER'] && ENV['NEWRELIC_DISPATCHER'].to_sym
238
+ @dispatcher ||= ENV['NEW_RELIC_DISPATCHER'] && ENV['NEW_RELIC_DISPATCHER'].to_sym
246
239
  dispatchers = %w[passenger torquebox glassfish thin mongrel litespeed webrick fastcgi unicorn sinatra]
247
240
  while dispatchers.any? && @dispatcher.nil?
248
241
  send 'check_for_'+(dispatchers.shift)
@@ -257,6 +250,7 @@ module NewRelic
257
250
  # of JRuby.
258
251
  @framework ||= case
259
252
  when ENV['NEWRELIC_FRAMEWORK'] then ENV['NEWRELIC_FRAMEWORK'].to_sym
253
+ when ENV['NEW_RELIC_FRAMEWORK'] then ENV['NEW_RELIC_FRAMEWORK'].to_sym
260
254
  when defined?(::NewRelic::TEST) then :test
261
255
  when defined?(::Merb) && defined?(::Merb::Plugins) then :merb
262
256
  when defined?(::Rails) then check_rails_version
@@ -336,11 +330,11 @@ module NewRelic
336
330
  end
337
331
 
338
332
  def check_for_unicorn
339
- return unless defined?(::Unicorn) && defined?(::Unicorn::HttpServer)
340
-
341
- # unlike mongrel, unicorn manages muliple threads and ports, so we
342
- # have to map multiple processes into one instance, as we do with passenger
343
- @dispatcher = :unicorn
333
+ if (defined?(::Unicorn) && defined?(::Unicorn::HttpServer)) && working_jruby?
334
+ v = find_class_in_object_space(::Unicorn::HttpServer)
335
+ @dispatcher = :unicorn if v
336
+ puts "We DETECTED UNICORN???: #{v.inspect}"
337
+ end
344
338
  end
345
339
 
346
340
  def check_for_sinatra
@@ -67,6 +67,7 @@ module NewRelic
67
67
 
68
68
  def reset
69
69
  NewRelic::Agent.instance.transaction_sampler.reset!
70
+ NewRelic::Agent.instance.sql_sampler.reset
70
71
  ::Rack::Response.new{|r| r.redirect('/newrelic/')}.finish
71
72
  end
72
73
 
@@ -47,6 +47,7 @@ module NewRelic
47
47
  def sum_attributes(other)
48
48
  update_totals(other)
49
49
  stack_min_max_from(other)
50
+ self.call_count = [self.call_count, other.call_count].max
50
51
  update_boundaries(other)
51
52
  end
52
53
 
@@ -7,20 +7,6 @@ module NewRelic
7
7
  # into one segment with multiple executions
8
8
  COLLAPSE_SEGMENTS_THRESHOLD = 2
9
9
 
10
- # columns for a mysql explain plan
11
- MYSQL_EXPLAIN_COLUMNS = [
12
- "Id",
13
- "Select Type",
14
- "Table",
15
- "Type",
16
- "Possible Keys",
17
- "Key",
18
- "Key Length",
19
- "Ref",
20
- "Rows",
21
- "Extra"
22
- ].freeze
23
-
24
10
  class TransactionSample
25
11
 
26
12
  attr_accessor :params, :root_segment
@@ -32,48 +18,7 @@ module NewRelic
32
18
  @@start_time = Time.now
33
19
 
34
20
  include TransactionAnalysis
35
-
36
- class << self
37
- def obfuscate_sql(sql)
38
- NewRelic::Agent.instance.obfuscator.call(sql)
39
- end
40
-
41
- # Returns a cached connection for a given ActiveRecord
42
- # configuration - these are stored or reopened as needed, and if
43
- # we cannot get one, we ignore it and move on without explaining
44
- # the sql
45
- def get_connection(config)
46
- @@connections ||= {}
47
-
48
- connection = @@connections[config]
49
-
50
- return connection if connection
51
-
52
- begin
53
- connection = ActiveRecord::Base.send("#{config[:adapter]}_connection", config)
54
- @@connections[config] = connection
55
- rescue => e
56
- NewRelic::Agent.agent.log.error("Caught exception #{e} trying to get connection to DB for explain. Control: #{config}")
57
- NewRelic::Agent.agent.log.error(e.backtrace.join("\n"))
58
- nil
59
- end
60
- end
61
-
62
- # Closes all the connections in the internal connection cache
63
- def close_connections
64
- @@connections ||= {}
65
- @@connections.values.each do |connection|
66
- begin
67
- connection.disconnect!
68
- rescue
69
- end
70
- end
71
-
72
- @@connections = {}
73
- end
74
-
75
- end
76
-
21
+
77
22
  def initialize(time = Time.now.to_f, sample_id = nil)
78
23
  @sample_id = sample_id || object_id
79
24
  @start_time = time
@@ -213,7 +158,7 @@ module NewRelic
213
158
  begin
214
159
  build_segment_for_transfer(sample, @root_segment, sample.root_segment, options)
215
160
  ensure
216
- self.class.close_connections
161
+ NewRelic::Agent::Database.close_connections
217
162
  end
218
163
 
219
164
  sample.root_segment.end_trace(@root_segment.exit_timestamp)
@@ -280,9 +225,9 @@ module NewRelic
280
225
  end
281
226
 
282
227
  target_called_segment[:sql] = case options[:record_sql]
283
- when :raw then v
284
- when :obfuscated then TransactionSample.obfuscate_sql(v)
285
- else raise "Invalid value for record_sql: #{options[:record_sql]}"
228
+ when :raw then v
229
+ when :obfuscated then NewRelic::Agent::Database.obfuscate_sql(v)
230
+ else raise "Invalid value for record_sql: #{options[:record_sql]}"
286
231
  end if options[:record_sql]
287
232
  when :connection_config
288
233
  # don't copy it
@@ -174,95 +174,20 @@ module NewRelic
174
174
  end
175
175
  nil
176
176
  end
177
-
178
- # Perform this in the runtime environment of a managed
179
- # application, to explain the sql statement executed within a
180
- # segment of a transaction sample. Returns an array of
181
- # explanations (which is an array rows consisting of an array of
182
- # strings for each column returned by the the explain query)
183
- # Note this happens only for statements whose execution time
184
- # exceeds a threshold (e.g. 500ms) and only within the slowest
185
- # transaction in a report period, selected for shipment to New
186
- # Relic
177
+
187
178
  def explain_sql
188
- return @explain_sql if @explain_sql
189
- sql = params[:sql]
190
- return nil unless sql && params[:connection_config]
191
- statement = sql.split(";\n")[0] # only explain the first
192
- @explain_sql = explain_statement(statement, params[:connection_config])
193
- return @explain_sql || []
194
- end
195
-
196
- def explain_statement(statement, config)
197
- if is_select?(statement)
198
- handle_exception_in_explain do
199
- connection = NewRelic::TransactionSample.get_connection(config)
200
- plan = nil
201
- if connection
202
- plan = process_resultset(connection.execute("EXPLAIN #{statement}"))
203
- end
204
- return plan
205
- end
206
- end
179
+ NewRelic::Agent::Database.explain_sql(params[:sql],
180
+ params[:connection_config])
207
181
  end
208
-
209
- def is_select?(statement)
210
- # split the string into at most two segments on the
211
- # system-defined field separator character
212
- first_word, rest_of_statement = statement.split($;, 2)
213
- (first_word.upcase == 'SELECT')
214
- end
215
-
216
- def process_resultset(items)
217
- # The resultset type varies for different drivers. Only thing you can count on is
218
- # that it implements each. Also: can't use select_rows because the native postgres
219
- # driver doesn't know that method.
220
-
221
- headers = []
222
- values = []
223
- if items.respond_to?(:each_hash)
224
- items.each_hash do |row|
225
- headers = row.keys
226
- values << headers.map{|h| row[h] }
227
- end
228
- elsif items.respond_to?(:each)
229
- items.each do |row|
230
- if row.kind_of?(Hash)
231
- headers = row.keys
232
- values << headers.map{|h| row[h] }
233
- else
234
- values << row
235
- end
236
- end
237
- else
238
- values = [items]
239
- end
240
-
241
- headers = nil if headers.empty?
242
- [headers, values]
243
- end
244
-
245
- def handle_exception_in_explain
246
- yield
247
- rescue Exception => e
248
- begin
249
- # guarantees no throw from explain_sql
250
- NewRelic::Control.instance.log.error("Error getting query plan: #{e.message}")
251
- NewRelic::Control.instance.log.debug(e.backtrace.join("\n"))
252
- rescue Exception
253
- # double exception. throw up your hands
254
- end
182
+
183
+ def obfuscated_sql
184
+ NewRelic::Agent::Database.obfuscate_sql(params[:sql])
255
185
  end
256
-
257
-
186
+
258
187
  def params=(p)
259
188
  @params = p
260
189
  end
261
190
 
262
- def obfuscated_sql
263
- TransactionSample.obfuscate_sql(params[:sql])
264
- end
265
-
266
191
  def called_segments=(segments)
267
192
  @called_segments = segments
268
193
  end
@@ -2,9 +2,9 @@
2
2
  module NewRelic
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 3
5
- MINOR = 1
6
- TINY = 2
7
- BUILD = nil # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
5
+ MINOR = 2
6
+ TINY = 0
7
+ BUILD = 'beta1' #'0' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
10
10
 
data/newrelic_rpm.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{newrelic_rpm}
8
- s.version = "3.1.2"
8
+ s.version = "3.2.0.beta1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bill Kayser", "Jon Guymon", "Justin George", "Darin Swanson"]
12
- s.date = %q{2011-09-07}
12
+ s.date = %q{2011-09-23}
13
13
  s.description = %q{New Relic is a performance management system, developed by New Relic,
14
14
  Inc (http://www.newrelic.com). New Relic provides you with deep
15
15
  information about the performance of your web application as it runs
@@ -44,6 +44,7 @@ http://github.com/newrelic/rpm/
44
44
  "lib/new_relic/agent/browser_monitoring.rb",
45
45
  "lib/new_relic/agent/busy_calculator.rb",
46
46
  "lib/new_relic/agent/chained_call.rb",
47
+ "lib/new_relic/agent/database.rb",
47
48
  "lib/new_relic/agent/error_collector.rb",
48
49
  "lib/new_relic/agent/instrumentation.rb",
49
50
  "lib/new_relic/agent/instrumentation/active_merchant.rb",
@@ -78,6 +79,7 @@ http://github.com/newrelic/rpm/
78
79
  "lib/new_relic/agent/samplers/memory_sampler.rb",
79
80
  "lib/new_relic/agent/samplers/object_sampler.rb",
80
81
  "lib/new_relic/agent/shim_agent.rb",
82
+ "lib/new_relic/agent/sql_sampler.rb",
81
83
  "lib/new_relic/agent/stats_engine.rb",
82
84
  "lib/new_relic/agent/stats_engine/metric_stats.rb",
83
85
  "lib/new_relic/agent/stats_engine/samplers.rb",
@@ -147,6 +149,7 @@ http://github.com/newrelic/rpm/
147
149
  "test/new_relic/agent/beacon_configuration_test.rb",
148
150
  "test/new_relic/agent/browser_monitoring_test.rb",
149
151
  "test/new_relic/agent/busy_calculator_test.rb",
152
+ "test/new_relic/agent/database_test.rb",
150
153
  "test/new_relic/agent/error_collector/notice_error_test.rb",
151
154
  "test/new_relic/agent/error_collector_test.rb",
152
155
  "test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb",
@@ -166,6 +169,7 @@ http://github.com/newrelic/rpm/
166
169
  "test/new_relic/agent/rpm_agent_test.rb",
167
170
  "test/new_relic/agent/sampler_test.rb",
168
171
  "test/new_relic/agent/shim_agent_test.rb",
172
+ "test/new_relic/agent/sql_sampler_test.rb",
169
173
  "test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb",
170
174
  "test/new_relic/agent/stats_engine/metric_stats_test.rb",
171
175
  "test/new_relic/agent/stats_engine/samplers_test.rb",
@@ -187,6 +191,7 @@ http://github.com/newrelic/rpm/
187
191
  "test/new_relic/metric_spec_test.rb",
188
192
  "test/new_relic/rack/all_test.rb",
189
193
  "test/new_relic/rack/browser_monitoring_test.rb",
194
+ "test/new_relic/rack/developer_mode_helper_test.rb",
190
195
  "test/new_relic/rack/developer_mode_test.rb",
191
196
  "test/new_relic/stats_test.rb",
192
197
  "test/new_relic/transaction_analysis/segment_summary_test.rb",
@@ -297,7 +302,7 @@ Refer to the README.md file for more information.
297
302
 
298
303
  Please see http://github.com/newrelic/rpm/blob/master/CHANGELOG
299
304
  for a complete description of the features and enhancements available
300
- in version 3.1 of the Ruby Agent.
305
+ in version 3.2 of the Ruby Agent.
301
306
 
302
307
  }
303
308
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "New Relic Ruby Agent"]
@@ -206,6 +206,22 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
206
206
  enable_random_samples!(sampling_rate)
207
207
  end
208
208
 
209
+ def test_config_transaction_tracer
210
+ @transaction_sampler = mock('transaction sampler', :configure! => true)
211
+ fake_sampler_config = mock('sampler config')
212
+ self.expects(:sampler_config).times(5).returns(fake_sampler_config)
213
+ fake_sampler_config.expects(:fetch).with('enabled', true)
214
+ fake_sampler_config.expects(:fetch).with('random_sample', false)
215
+ fake_sampler_config.expects(:fetch).with('explain_threshold', 0.5)
216
+ fake_sampler_config.expects(:fetch).with('explain_enabled', true)
217
+ self.expects(:set_sql_recording!)
218
+
219
+ fake_sampler_config.expects(:fetch).with('transaction_threshold', 2.0)
220
+ self.expects(:apdex_f_threshold?).returns(true)
221
+ self.expects(:apdex_f)
222
+ config_transaction_tracer
223
+ end
224
+
209
225
  def test_configure_transaction_tracer_with_random_sampling
210
226
  @config_should_send_samples = true
211
227
  @should_send_random_samples = true
@@ -238,6 +254,76 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
238
254
  assert !@should_send_samples
239
255
  end
240
256
 
257
+ def test_apdex_f
258
+ NewRelic::Control.instance.expects(:apdex_t).returns(10)
259
+ assert_equal 40, apdex_f
260
+ end
261
+
262
+ def test_apdex_f_threshold_positive
263
+ self.expects(:sampler_config).returns({'transaction_threshold' => 'apdex_f'})
264
+ assert apdex_f_threshold?
265
+ end
266
+
267
+ def test_apdex_f_threshold_negative
268
+ self.expects(:sampler_config).returns({'transaction_threshold' => 'WHEE'})
269
+ assert !apdex_f_threshold?
270
+ end
271
+
272
+ def test_set_sql_recording_default
273
+ self.expects(:sampler_config).returns({})
274
+ self.expects(:log_sql_transmission_warning?)
275
+ set_sql_recording!
276
+ assert_equal :obfuscated, @record_sql, " should default to :obfuscated, was #{@record_sql}"
277
+ end
278
+
279
+ def test_set_sql_recording_off
280
+ self.expects(:sampler_config).returns({'record_sql' => 'off'})
281
+ self.expects(:log_sql_transmission_warning?)
282
+ set_sql_recording!
283
+ assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
284
+ end
285
+
286
+ def test_set_sql_recording_none
287
+ self.expects(:sampler_config).returns({'record_sql' => 'none'})
288
+ self.expects(:log_sql_transmission_warning?)
289
+ set_sql_recording!
290
+ assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
291
+ end
292
+
293
+ def test_set_sql_recording_raw
294
+ self.expects(:sampler_config).returns({'record_sql' => 'raw'})
295
+ self.expects(:log_sql_transmission_warning?)
296
+ set_sql_recording!
297
+ assert_equal :raw, @record_sql, "should be set to :raw, was #{@record_sql}"
298
+ end
299
+
300
+ def test_set_sql_recording_falsy
301
+ self.expects(:sampler_config).returns({'record_sql' => false})
302
+ self.expects(:log_sql_transmission_warning?)
303
+ set_sql_recording!
304
+ assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
305
+ end
306
+
307
+ def test_log_sql_transmission_warning_negative
308
+ log = mocked_log
309
+ @record_sql = :obfuscated
310
+ log.expects(:warn).never
311
+ log_sql_transmission_warning?
312
+ end
313
+
314
+ def test_log_sql_transmission_warning_positive
315
+ log = mocked_log
316
+ @record_sql = :raw
317
+ log.expects(:warn).with('Agent is configured to send raw SQL to the service')
318
+ log_sql_transmission_warning?
319
+ end
320
+
321
+ def test_sampler_config
322
+ control = mocked_control
323
+ control.expects(:fetch).with('transaction_tracer', {})
324
+ sampler_config
325
+ end
326
+
241
327
  def test_set_collector_host_positive
242
328
  control = mocked_control
243
329
  self.expects(:invoke_remote).with(:get_redirect_host).returns('collector-deux.newrelic.com')
@@ -279,9 +365,12 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
279
365
  'collect_errors' => true,
280
366
  'sample_rate' => 10
281
367
  }
368
+ control = mocked_control
369
+ control.expects(:fetch).with('transaction_tracer', {}).returns({'enabled' => true}).at_least_once
282
370
  self.expects(:log_connection!).with(config)
283
371
  self.expects(:configure_transaction_tracer!).with(true, 10)
284
372
  self.expects(:configure_error_collector!).with(true)
373
+ @transaction_sampler = mock('transaction sampler', :configure! => true)
285
374
  finish_setup(config)
286
375
  assert_equal 'fishsticks', @agent_id
287
376
  assert_equal 'pasta sauce', @report_period
@@ -296,6 +385,12 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
296
385
  fake_control
297
386
  end
298
387
 
388
+ def mocked_log
389
+ fake_log = mock('log')
390
+ self.stubs(:log).returns(fake_log)
391
+ fake_log
392
+ end
393
+
299
394
  def mocked_error_collector
300
395
  fake_collector = mock('error collector')
301
396
  self.stubs(:error_collector).returns(fake_collector)