Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove trailing whitespace

  • Loading branch information...
commit e3c53bbe09ea9358eb137e3b6862439f6bc44b72 1 parent b2c27e9
@jaggederest jaggederest authored
Showing with 1,294 additions and 1,294 deletions.
  1. +9 −9 init.rb
  2. +2 −2 install.rb
  3. +1 −1  lib/new_relic/agent.rb
  4. +24 −24 lib/new_relic/agent/agent.rb
  5. +19 −19 lib/new_relic/agent/browser_monitoring.rb
  6. +4 −4 lib/new_relic/agent/error_collector.rb
  7. +3 −3 lib/new_relic/agent/instrumentation/acts_as_solr.rb
  8. +1 −1  lib/new_relic/agent/instrumentation/controller_instrumentation.rb
  9. +8 −8 lib/new_relic/agent/instrumentation/data_mapper.rb
  10. +1 −1  lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
  11. +1 −1  lib/new_relic/agent/instrumentation/memcache.rb
  12. +1 −1  lib/new_relic/agent/instrumentation/merb/controller.rb
  13. +1 −1  lib/new_relic/agent/instrumentation/merb/errors.rb
  14. +10 −10 lib/new_relic/agent/instrumentation/queue_time.rb
  15. +1 −1  lib/new_relic/agent/instrumentation/rails/action_web_service.rb
  16. +1 −1  lib/new_relic/agent/instrumentation/rails/errors.rb
  17. +2 −2 lib/new_relic/agent/instrumentation/rails3/action_controller.rb
  18. +1 −1  lib/new_relic/agent/instrumentation/sinatra.rb
  19. +13 −13 lib/new_relic/agent/method_tracer.rb
  20. +3 −3 lib/new_relic/agent/stats_engine/metric_stats.rb
  21. +2 −2 lib/new_relic/agent/stats_engine/samplers.rb
  22. +1 −1  lib/new_relic/agent/stats_engine/transactions.rb
  23. +23 −23 lib/new_relic/agent/transaction_sampler.rb
  24. +2 −2 lib/new_relic/control.rb
  25. +1 −1  lib/new_relic/control/class_methods.rb
  26. +2 −2 lib/new_relic/control/configuration.rb
  27. +4 −4 lib/new_relic/control/frameworks/rails.rb
  28. +2 −2 lib/new_relic/control/instance_methods.rb
  29. +1 −1  lib/new_relic/control/instrumentation.rb
  30. +2 −2 lib/new_relic/control/server_methods.rb
  31. +1 −1  lib/new_relic/delayed_job_injection.rb
  32. +7 −7 lib/new_relic/local_environment.rb
  33. +10 −10 lib/new_relic/rack/browser_monitoring.rb
  34. +5 −5 lib/new_relic/stats.rb
  35. +5 −5 test/active_record_fixtures.rb
  36. +3 −3 test/config/test_control.rb
  37. +7 −7 test/new_relic/agent/agent/connect_test.rb
  38. +13 −13 test/new_relic/agent/agent/start_test.rb
  39. +8 −8 test/new_relic/agent/agent/start_worker_thread_test.rb
  40. +24 −24 test/new_relic/agent/agent_test.rb
  41. +9 −9 test/new_relic/agent/agent_test_controller.rb
  42. +37 −37 test/new_relic/agent/agent_test_controller_test.rb
  43. +9 −9 test/new_relic/agent/browser_monitoring_test.rb
  44. +7 −7 test/new_relic/agent/busy_calculator_test.rb
  45. +9 −9 test/new_relic/agent/error_collector/notice_error_test.rb
  46. +54 −54 test/new_relic/agent/error_collector_test.rb
  47. +69 −69 test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb
  48. +1 −1  test/new_relic/agent/instrumentation/controller_instrumentation_test.rb
  49. +3 −3 test/new_relic/agent/instrumentation/metric_frame_test.rb
  50. +11 −11 test/new_relic/agent/instrumentation/net_instrumentation_test.rb
  51. +19 −19 test/new_relic/agent/instrumentation/queue_time_test.rb
  52. +18 −18 test/new_relic/agent/instrumentation/task_instrumentation_test.rb
  53. +12 −12 test/new_relic/agent/memcache_instrumentation_test.rb
  54. +1 −1  test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb
  55. +13 −13 test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb
  56. +60 −60 test/new_relic/agent/method_tracer_test.rb
  57. +8 −8 test/new_relic/agent/mock_scope_listener.rb
  58. +21 −21 test/new_relic/agent/rpm_agent_test.rb
  59. +17 −17 test/new_relic/agent/stats_engine/metric_stats_test.rb
  60. +4 −4 test/new_relic/agent/stats_engine/samplers_test.rb
  61. +51 −51 test/new_relic/agent/stats_engine/stats_engine_test.rb
  62. +36 −36 test/new_relic/agent/transaction_sample_builder_test.rb
  63. +134 −134 test/new_relic/agent/transaction_sampler_test.rb
  64. +4 −4 test/new_relic/agent/worker_loop_test.rb
  65. +15 −15 test/new_relic/collection_helper_test.rb
  66. +5 −5 test/new_relic/command/deployments_test.rb
  67. +24 −24 test/new_relic/control_test.rb
  68. +9 −9 test/new_relic/local_environment_test.rb
  69. +21 −21 test/new_relic/metric_spec_test.rb
  70. +35 −35 test/new_relic/rack/episodes_test.rb
  71. +46 −46 test/new_relic/stats_test.rb
  72. +15 −15 test/new_relic/transaction_sample_subtest_test.rb
  73. +25 −25 test/new_relic/transaction_sample_test.rb
  74. +11 −11 test/new_relic/version_number_test.rb
  75. +7 −7 test/test_contexts.rb
  76. +6 −6 test/test_helper.rb
  77. +67 −67 ui/helpers/developer_mode_helper.rb
  78. +4 −4 ui/helpers/google_pie_chart.rb
  79. +4 −4 vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb
  80. +3 −3 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb
  81. +7 −7 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb
  82. +1 −1  vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb
  83. +9 −9 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb
  84. +1 −1  vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb
  85. +8 −8 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb
  86. +9 −9 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb
  87. +4 −4 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb
  88. +2 −2 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb
  89. +8 −8 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb
  90. +3 −3 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb
  91. +6 −6 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb
  92. +3 −3 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb
  93. +2 −2 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb
  94. +6 −6 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb
  95. +2 −2 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb
  96. +1 −1  vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb
  97. +4 −4 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb
  98. +3 −3 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb
  99. +4 −4 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb
  100. +1 −1  vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb
  101. +1 −1  vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb
  102. +21 −21 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb
  103. +2 −2 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb
  104. +6 −6 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb
  105. +2 −2 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb
  106. +1 −1  vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb
  107. +1 −1  vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb
  108. +3 −3 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb
  109. +1 −1  vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb
  110. +8 −8 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb
  111. +3 −3 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb
  112. +3 −3 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb
  113. +5 −5 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb
  114. +20 −20 vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb
View
18 init.rb
@@ -2,18 +2,18 @@
require 'new_relic/control'
# If you are having problems seeing data, be sure and check the
-# newrelic_agent log files.
-#
+# newrelic_agent log files.
+#
# If you can't find any log files and you don't see anything in your
-# application log files, try uncommenting the two lines at the
-# bottom of this file to verify the plugin is being loaded,
-# then send the output to support@newrelic.com if you are unable to
+# application log files, try uncommenting the two lines at the
+# bottom of this file to verify the plugin is being loaded,
+# then send the output to support@newrelic.com if you are unable to
# resolve the issue.
# Initializer for the NewRelic Agent
# After verison 2.0 of Rails we can access the configuration directly.
-# We need it to add dev mode routes after initialization finished.
+# We need it to add dev mode routes after initialization finished.
begin
@@ -22,9 +22,9 @@
elsif defined?(Rails.configuration)
Rails.configuration
end
-
+
NewRelic::Control.instance.init_plugin :config => current_config
-
+
rescue => e
NewRelic::Control.instance.log! "Error initializing New Relic plugin (#{e})", :error
NewRelic::Control.instance.log! e.backtrace.join("\n"), :error
@@ -32,6 +32,6 @@
end
#ClassLoadingWatcher.flag_const_missing = nil
-#
+#
# ::RAILS_DEFAULT_LOGGER.warn "RPM detected environment: #{NewRelic::Control.instance.local_env.to_s}, RAILS_ENV: #{RAILS_ENV}"
# ::RAILS_DEFAULT_LOGGER.warn "Enabled? #{NewRelic::Control.instance.agent_enabled?}"
View
4 install.rb
@@ -1,9 +1,9 @@
if __FILE__ == $0 || $0 =~ /script\/plugin/
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
- require 'new_relic/command'
+ require 'new_relic/command'
begin
NewRelic::Command::Install.new(:quiet => true, :app_name => 'My Application').run
rescue NewRelic::Command::CommandFailure => e
$stderr.puts e.message
end
-end
+end
View
2  lib/new_relic/agent.rb
@@ -71,7 +71,7 @@ module Agent
require 'new_relic/noticed_error'
require 'new_relic/histogram'
require 'new_relic/timer_lib'
-
+
require 'new_relic/agent'
require 'new_relic/agent/chained_call'
require 'new_relic/agent/browser_monitoring'
View
48 lib/new_relic/agent/agent.rb
@@ -228,7 +228,7 @@ def set_sql_obfuscator(type, &block)
def log
NewRelic::Agent.logger
end
-
+
# Herein lies the corpse of the former 'start' method. May
# it's unmatched flog score rest in pieces.
module Start
@@ -242,13 +242,13 @@ def already_started?
def disabled?
!control.agent_enabled?
end
-
+
def log_dispatcher
dispatcher_name = control.dispatcher.to_s
return if log_if(dispatcher_name.empty?, :info, "No dispatcher detected.")
log.info "Dispatcher: #{dispatcher_name}"
end
-
+
def log_app_names
log.info "Application: #{control.app_names.join(", ")}"
end
@@ -258,7 +258,7 @@ def apdex_f
end
def apdex_f_threshold?
- sampler_config.fetch('transaction_threshold', '') =~ /apdex_f/i
+ sampler_config.fetch('transaction_threshold', '') =~ /apdex_f/i
end
def set_sql_recording!
@@ -275,7 +275,7 @@ def set_sql_recording!
else
@record_sql = :obfuscated
end
-
+
log_sql_transmission_warning?
end
@@ -286,7 +286,7 @@ def log_sql_transmission_warning?
def sampler_config
control.fetch('transaction_tracer', {})
end
-
+
# this entire method should be done on the transaction
# sampler object, rather than here. We should pass in the
# sampler config.
@@ -296,7 +296,7 @@ def config_transaction_tracer
@explain_threshold = sampler_config.fetch('explain_threshold', 0.5).to_f
@explain_enabled = sampler_config.fetch('explain_enabled', true)
set_sql_recording!
-
+
# default to 2.0, string 'apdex_f' will turn into your
# apdex * 4
@slowest_transaction_threshold = sampler_config.fetch('transaction_threshold', 2.0).to_f
@@ -308,23 +308,23 @@ def connect_in_foreground
end
def using_rubinius?
- RUBY_VERSION =~ /rubinius/i
+ RUBY_VERSION =~ /rubinius/i
end
-
+
def using_jruby?
- defined?(JRuby)
+ defined?(JRuby)
end
-
+
def using_sinatra?
defined?(Sinatra::Application)
end
-
+
# we should not set an at_exit block if people are using
# these as they don't do standard at_exit behavior per MRI/YARV
def weird_ruby?
using_rubinius? || using_jruby? || using_sinatra?
end
-
+
def install_exit_handler
if control.send_data_on_exit && !weird_ruby?
# Our shutdown handler needs to run after other shutdown handlers
@@ -340,7 +340,7 @@ def notify_log_file_location
def log_version_and_pid
log.info "New Relic RPM Agent #{NewRelic::VERSION::STRING} Initialized: pid = #{$$}"
end
-
+
def log_if(boolean, level, message)
self.log.send(level, message) if boolean
boolean
@@ -350,7 +350,7 @@ def log_unless(boolean, level, message)
self.log.send(level, message) unless boolean
boolean
end
-
+
def monitoring?
log_unless(control.monitor_mode?, :warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
end
@@ -362,7 +362,7 @@ def has_license_key?
def has_correct_license_key?
has_license_key? && correct_license_length
end
-
+
def correct_license_length
key = control.license_key
log_unless((key.length == 40), :error, "Invalid license key: #{key}")
@@ -371,7 +371,7 @@ def correct_license_length
def using_forking_dispatcher?
log_if([:passenger, :unicorn].include?(control.dispatcher), :info, "Connecting workers after forking.")
end
-
+
def check_config_and_start_agent
return unless monitoring? && has_correct_license_key?
return if using_forking_dispatcher?
@@ -479,7 +479,7 @@ def catch_errors
rescue Exception => e
handle_other_error(e)
end
-
+
def deferred_work!(connection_options)
catch_errors do
NewRelic::Agent.disable_all_tracing do
@@ -500,7 +500,7 @@ def deferred_work!(connection_options)
end
end
include StartWorkerThread
-
+
# Try to launch the worker thread and connect to the server.
#
# See #connect for a description of connection_options.
@@ -515,7 +515,7 @@ def start_worker_thread(connection_options = {})
def control
NewRelic::Control.instance
end
-
+
module Connect
attr_accessor :connect_retry_period
attr_accessor :connect_attempts
@@ -564,7 +564,7 @@ def handle_license_error(error)
log.info "Visit NewRelic.com to obtain a valid license key, or to upgrade your account."
disconnect
end
-
+
def log_seed_token
if control.validate_seed
log.debug "Connecting with validation seed/token: #{control.validate_seed}/#{control.validate_token}"
@@ -608,14 +608,14 @@ def configure_error_collector!(server_enabled)
end
log.debug "Errors will #{enabled ? '' : 'not '}be sent to the RPM service."
end
-
+
def enable_random_samples!(sample_rate)
sample_rate = 10 unless sample_rate.to_i > 0# a sane default for random sampling
@transaction_sampler.random_sampling = true
@transaction_sampler.sampling_rate = sample_rate
log.info "Transaction sampling enabled, rate = #{@transaction_sampler.sampling_rate}"
end
-
+
def configure_transaction_tracer!(server_enabled, sample_rate)
# Ask the server for permission to send transaction samples.
@@ -640,7 +640,7 @@ def set_collector_host!
def query_server_for_configuration
set_collector_host!
-
+
finish_setup(connect_to_server)
end
def finish_setup(config_data)
View
38 lib/new_relic/agent/browser_monitoring.rb
@@ -2,14 +2,14 @@
module NewRelic
module Agent
- class BeaconConfiguration
+ class BeaconConfiguration
attr_reader :browser_timing_header
attr_reader :application_id
attr_reader :browser_monitoring_key
attr_reader :beacon
attr_reader :rum_enabled
attr_reader :license_bytes
-
+
def initialize(connect_data)
@browser_monitoring_key = connect_data['browser_key']
@application_id = connect_data['application_id']
@@ -27,17 +27,17 @@ def license_bytes
@license_bytes
end
end
-
+
def build_browser_timing_header(connect_data)
return "" if !@rum_enabled
return "" if @browser_monitoring_key.nil?
-
+
episodes_url = connect_data['episodes_url']
load_episodes_file = connect_data['rum.load_episodes_file']
load_episodes_file = true if load_episodes_file.nil?
-
+
load_js = load_episodes_file ? "(function(){var d=document;var e=d.createElement(\"script\");e.type=\"text/javascript\";e.async=true;e.src=\"#{episodes_url}\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})()" : ""
-
+
value = "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);#{load_js}</script>"
if value.respond_to?(:html_safe)
value.html_safe
@@ -48,15 +48,15 @@ def build_browser_timing_header(connect_data)
end
module BrowserMonitoring
-
- def browser_timing_header
+
+ def browser_timing_header
return "" if NewRelic::Agent.instance.beacon_configuration.nil?
-
+
return "" if Thread::current[:record_tt] == false || !NewRelic::Agent.is_execution_traced?
-
+
NewRelic::Agent.instance.beacon_configuration.browser_timing_header
end
-
+
def browser_timing_footer
config = NewRelic::Agent.instance.beacon_configuration
return "" if config.nil?
@@ -65,23 +65,23 @@ def browser_timing_footer
return "" if license_key.nil?
return "" if Thread::current[:record_tt] == false || !NewRelic::Agent.is_execution_traced?
-
+
application_id = config.application_id
beacon = config.beacon
-
+
transaction_name = Thread.current[:newrelic_most_recent_transaction] || "<unknown>"
start_time = Thread.current[:newrelic_start_time]
queue_time = (Thread.current[:newrelic_queue_time].to_f * 1000.0).round
-
+
value = ''
if start_time
-
+
obf = obfuscate(transaction_name)
app_time = ((Time.now - start_time).to_f * 1000.0).round
-
+
queue_time = 0.0 if queue_time < 0
app_time = 0.0 if app_time < 0
-
+
value = <<-eos
<script type="text/javascript" charset="utf-8">NREUMQ.push(["nrf2","#{beacon}","#{license_key}",#{application_id},"#{obf}",#{queue_time},#{app_time}])</script>
eos
@@ -92,7 +92,7 @@ def browser_timing_footer
value
end
end
-
+
private
def obfuscate(text)
@@ -103,7 +103,7 @@ def obfuscate(text)
obfuscated.concat((byte ^ key_bytes[index % 13].to_i))
index+=1
}
-
+
[obfuscated].pack("m0").chomp
end
end
View
8 lib/new_relic/agent/error_collector.rb
@@ -97,7 +97,7 @@ def uri_ref_and_root(options)
end
def custom_params_from_opts(options)
- # If anything else is left over, treat it like a custom param:
+ # If anything else is left over, treat it like a custom param:
fetch_from_options(options, :custom_params, {}).merge(options)
end
@@ -109,14 +109,14 @@ def request_params_from_opts(options)
nil
end
end
-
+
def normalized_request_and_custom_params(options)
{
:request_params => normalize_params(request_params_from_opts(options)),
:custom_params => normalize_params(custom_params_from_opts(options))
}
end
-
+
def error_params_from_options(options)
uri_ref_and_root(options).merge(normalized_request_and_custom_params(options))
end
@@ -148,7 +148,7 @@ def over_queue_limit?(exception)
log.warn("The error reporting queue has reached #{MAX_ERROR_QUEUE_LENGTH}. The error detail for this and subsequent errors will not be transmitted to RPM until the queued errors have been sent: #{exception}") if over_limit
over_limit
end
-
+
def add_to_error_queue(noticed_error, exception)
@lock.synchronize do
View
6 lib/new_relic/agent/instrumentation/acts_as_solr.rb
@@ -25,7 +25,7 @@ def parse_query_with_newrelic(*args)
depends_on do
defined?(ActsAsSolr::ParserMethods)
end
-
+
depends_on do
defined?(ActsAsSolr::ClassMethods)
end
@@ -33,7 +33,7 @@ def parse_query_with_newrelic(*args)
depends_on do
defined?(ActsAsSolr::CommonMethods)
end
-
+
executes do
ActsAsSolr::ParserMethods.module_eval do
include NewRelic::Instrumentation::ActsAsSolrInstrumentation::ParserMethodsInstrumentation
@@ -41,7 +41,7 @@ def parse_query_with_newrelic(*args)
alias :parse_query :parse_query_with_newrelic
end
end
-
+
executes do
ActsAsSolr::ClassMethods.module_eval do
%w[find_by_solr find_id_by_solr multi_solr_search count_by_solr].each do |method|
View
2  lib/new_relic/agent/instrumentation/controller_instrumentation.rb
@@ -264,7 +264,7 @@ def perform_action_with_newrelic_trace(*args, &block)
# Look for a metric frame in the thread local and process it.
# Clear the thread local when finished to ensure it only gets called once.
frame_data.record_apdex unless _is_filtered?('ignore_apdex')
-
+
frame_data.pop
end
end
View
16 lib/new_relic/agent/instrumentation/data_mapper.rb
@@ -53,7 +53,7 @@
depends_on do
defined?(DataMapper::Collection)
end
-
+
executes do
DataMapper::Model.class_eval do
add_method_tracer :get, 'ActiveRecord/#{self.name}/get'
@@ -117,13 +117,13 @@
end
DependencyDetection.defer do
-
+
depends_on do
defined?(DataMapper) && defined?(DataMapper::Adapters) && defined?(DataMapper::Adapters::DataObjectsAdapter)
end
-
+
executes do
-
+
# Catch the two entry points into DM::Repository::Adapter that bypass CRUD
# (for when SQL is run directly).
DataMapper::Adapters::DataObjectsAdapter.class_eval do
@@ -140,7 +140,7 @@
depends_on do
defined?(DataMapper) && defined?(DataMapper::Validations) && defined?(DataMapper::Validations::ClassMethods)
end
-
+
# DM::Validations overrides Model#create, but currently in a way that makes it
# impossible to instrument from one place. I've got a patch pending inclusion
# to make it instrumentable by putting the create method inside ClassMethods.
@@ -158,7 +158,7 @@
depends_on do
defined?(DataMapper) && defined?(DataMapper::Transaction)
end
-
+
# NOTE: DM::Transaction basically calls commit() twice, so as-is it will show
# up in traces twice -- second time subordinate to the first's scope. Works
# well enough.
@@ -219,11 +219,11 @@ def log_with_newrelic_instrumentation(msg)
end # NewRelic
DependencyDetection.defer do
-
+
depends_on do
defined?(DataObjects) && defined?(DataObjects::Connection)
end
-
+
executes do
DataObjects::Connection.class_eval do
include ::NewRelic::Agent::Instrumentation::DataMapperInstrumentation
View
2  lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
@@ -8,7 +8,7 @@
depends_on do
defined?(::Delayed) && defined?(::Delayed::Job)
end
-
+
executes do
Delayed::Job.class_eval do
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
View
2  lib/new_relic/agent/instrumentation/memcache.rb
@@ -11,7 +11,7 @@ module Instrumentation
module Memcache
module_function
def instrument_method(the_class, method_name)
- return unless the_class.method_defined? method_name.to_sym
+ return unless the_class.method_defined? method_name.to_sym
the_class.class_eval <<-EOD
def #{method_name}_with_newrelic_trace(*args)
metrics = ["MemCache/#{method_name}",
View
2  lib/new_relic/agent/instrumentation/merb/controller.rb
@@ -5,7 +5,7 @@
depends_on do
defined?(Merb) && defined?(Merb::Controller)
end
-
+
executes do
require 'merb-core/controller/merb_controller'
View
2  lib/new_relic/agent/instrumentation/merb/errors.rb
@@ -18,6 +18,6 @@
}
Merb::Dispatcher::DefaultException.before error_notifier
Exceptions.before error_notifier
-
+
end
end
View
20 lib/new_relic/agent/instrumentation/queue_time.rb
@@ -9,7 +9,7 @@ module QueueTime
ALT_QUEUE_HEADER = 'HTTP_X_QUEUE_TIME'
HEROKU_QUEUE_HEADER = 'HTTP_X_HEROKU_QUEUE_WAIT_TIME'
APP_HEADER = 'HTTP_X_APPLICATION_START'
-
+
HEADER_REGEX = /([^\s\/,(t=)]+)? ?t=([0-9]+)/
SERVER_METRIC = 'WebFrontend/WebServer/'
MIDDLEWARE_METRIC = 'Middleware/'
@@ -31,15 +31,15 @@ def parse_frontend_headers(headers)
# returned for the controller instrumentation
[middleware_start, queue_start, server_start].min
end
-
+
private
-
+
# main method to extract server time info from env hash,
# records individual server metrics and one roll-up for all servers
def parse_server_time_from(env)
end_time = parse_end_time(env)
matches = get_matches_from_header(MAIN_HEADER, env)
-
+
record_individual_server_stats(end_time, matches)
record_rollup_server_stat(end_time, matches)
end
@@ -58,7 +58,7 @@ def parse_middleware_time_from(env)
end
def parse_queue_time_from(env)
- oldest_time = nil
+ oldest_time = nil
end_time = parse_end_time(env)
alternate_length = check_for_alternate_queue_length(env)
if alternate_length
@@ -114,7 +114,7 @@ def record_individual_stat_of_type(type, end_time, matches)
time
}
end
-
+
# goes through the list of servers and records each one in
# reverse order, subtracting the time for each successive
# server from the earlier ones in the list.
@@ -131,7 +131,7 @@ def record_individual_server_stats(end_time, matches) # (Time, [[String, Time]])
def record_individual_middleware_stats(end_time, matches)
record_individual_stat_of_type(:record_middleware_time_for, end_time, matches)
end
-
+
# records the total time for all servers in a rollup metric
def record_rollup_server_stat(end_time, matches) # (Time, [String, Time]) -> nil
record_rollup_stat_of_type(ALL_SERVER_METRIC, end_time, matches)
@@ -150,14 +150,14 @@ def record_rollup_stat_of_type(metric, end_time, matches)
record_time_stat(metric, oldest_time, end_time)
oldest_time
end
-
+
# searches for the first server to touch a request
def find_oldest_time(matches) # [[String, Time]] -> Time
matches.map do |name, time|
time
end.min
end
-
+
# basically just assembles the metric name
def record_server_time_for(name, start_time, end_time) # (Maybe String, Time, Time) -> nil
record_time_stat(SERVER_METRIC + name, start_time, end_time) if name
@@ -195,7 +195,7 @@ def convert_to_microseconds(time) # Time -> Int
return time if time.is_a?(Numeric)
(time.to_f * 1_000_000).to_i
end
-
+
# convert a time from the header value (time in microseconds)
# into a ruby time object
def convert_from_microseconds(int) # Int -> Time
View
2  lib/new_relic/agent/instrumentation/rails/action_web_service.rb
@@ -24,7 +24,7 @@
add_method_tracer :decode_response, "WebService/Soap/XML Decode"
add_method_tracer :encode_response, "WebService/Soap/XML Encode"
end
-
+
if defined?(ActionController) && defined?(ActionController::Base)
ActionController::Base.class_eval do
if method_defined? :perform_invocation
View
2  lib/new_relic/agent/instrumentation/rails/errors.rb
@@ -6,7 +6,7 @@
depends_on do
defined?(Rails) && Rails::VERSION::MAJOR.to_i == 2
end
-
+
executes do
ActionController::Base.class_eval do
View
4 lib/new_relic/agent/instrumentation/rails3/action_controller.rb
@@ -45,11 +45,11 @@ def process_action(*args)
depends_on do
defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3
end
-
+
depends_on do
defined?(ActionController) && defined?(ActionController::Base)
end
-
+
executes do
class ActionController::Base
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
View
2  lib/new_relic/agent/instrumentation/sinatra.rb
@@ -4,7 +4,7 @@
depends_on do
defined?(::Sinatra) && defined?(::Sinatra::Base)
end
-
+
executes do
::Sinatra::Base.class_eval do
include NewRelic::Agent::Instrumentation::Sinatra
View
26 lib/new_relic/agent/method_tracer.rb
@@ -92,7 +92,7 @@ def trace_method_execution_with_scope(metric_names, produce_metric, deduct_call_
end
alias trace_method_execution_no_scope trace_execution_unscoped #:nodoc:
-
+
module TraceExecutionScoped
def agent_instance
NewRelic::Agent.instance
@@ -101,7 +101,7 @@ def agent_instance
def traced?
NewRelic::Agent.is_execution_traced?
end
-
+
def trace_disabled?(options)
!(traced? || options[:force])
end
@@ -120,7 +120,7 @@ def get_stats_unscoped(name)
def main_stat(metric, options)
get_stats_scoped(metric, options[:scoped_metric_only])
end
-
+
def get_metric_stats(metrics, options)
metrics = Array(metrics)
first_name = metrics.shift
@@ -163,7 +163,7 @@ def trace_execution_scoped_header(metric, options, t0=Time.now.to_f)
def trace_execution_scoped_footer(t0, first_name, metric_stats, expected_scope, forced, t1=Time.now.to_f)
log_errors("trace_method_execution footer", first_name) do
duration = t1 - t0
-
+
pop_flag!(forced)
if expected_scope
scope = stat_engine.pop_scope(expected_scope, duration, t1)
@@ -195,7 +195,7 @@ def trace_execution_scoped(metric_names, options={})
trace_execution_scoped_footer(start_time, first_name, metric_stats, expected_scope, options[:force])
end
end
-
+
end
include TraceExecutionScoped
@@ -274,11 +274,11 @@ module ClassMethods
module AddMethodTracer
ALLOWED_KEYS = [:force, :metric, :push_scope, :deduct_call_time_from_parent, :code_header, :code_footer, :scoped_metric_only].freeze
-
+
def unrecognized_keys(expected, given)
given.keys - expected
end
-
+
def any_unrecognized_keys?(expected, given)
unrecognized_keys(expected, given).any?
end
@@ -288,7 +288,7 @@ def check_for_illegal_keys!(options)
raise "Unrecognized options in add_method_tracer_call: #{unrecognized_keys(ALLOWED_KEYS, options).join(', ')}"
end
end
-
+
def set_deduct_call_time_based_on_metric(options)
{:deduct_call_time_from_parent => !!options[:metric]}.merge(options)
end
@@ -300,7 +300,7 @@ def check_for_push_scope_and_metric(options)
end
DEFAULT_SETTINGS = {:push_scope => true, :metric => true, :force => false, :code_header => "", :code_footer => "", :scoped_metric_only => false}.freeze
-
+
def validate_options(options)
raise TypeError.new("provided options must be a Hash") unless options.is_a?(Hash)
check_for_illegal_keys!(options)
@@ -308,12 +308,12 @@ def validate_options(options)
check_for_push_scope_and_metric(options)
options
end
-
+
# Default to the class where the method is defined.
def default_metric_name_code(method_name)
"Custom/#{self.name}/#{method_name.to_s}"
end
-
+
def method_exists?(method_name)
exists = method_defined?(method_name) || private_method_defined?(method_name)
NewRelic::Control.instance.log.warn("Did not trace #{self.name}##{method_name} because that method does not exist") unless exists
@@ -380,10 +380,10 @@ def code_to_eval(method_name, metric_name_code, options)
def add_method_tracer(method_name, metric_name_code=nil, options = {})
return unless method_exists?(method_name)
metric_name_code ||= default_metric_name_code(method_name)
- return if traced_method_exists?(method_name, metric_name_code)
+ return if traced_method_exists?(method_name, metric_name_code)
traced_method = code_to_eval(method_name, metric_name_code, options)
-
+
class_eval traced_method, __FILE__, __LINE__
alias_method _untraced_method_name(method_name, metric_name_code), method_name
alias_method method_name, _traced_method_name(method_name, metric_name_code)
View
6 lib/new_relic/agent/stats_engine/metric_stats.rb
@@ -7,7 +7,7 @@ def initialize(*args)
@mutex = Mutex.new
super
end
-
+
def []=(*args)
@mutex.synchronize {
super
@@ -31,14 +31,14 @@ def delete(*args)
super
}
end
-
+
def delete_if(*args)
@mutex.synchronize {
super
}
end
end
-
+
# The stats hash hashes either a metric name for an unscoped metric,
# or a metric_spec for a scoped metric value.
def lookup_stat(metric_name)
View
4 lib/new_relic/agent/stats_engine/samplers.rb
@@ -33,7 +33,7 @@ def start_sampler_thread
end
private
-
+
def add_sampler_to(sampler_array, sampler)
raise "Sampler #{sampler.inspect} is already registered. Don't call add_sampler directly anymore." if sampler_array.include?(sampler)
sampler_array << sampler
@@ -43,7 +43,7 @@ def add_sampler_to(sampler_array, sampler)
def log_added_sampler(type, sampler)
log.debug "Adding #{type} sampler: #{sampler.inspect}"
end
-
+
public
# Add an instance of Sampler to be invoked about every 10 seconds on a background
View
2  lib/new_relic/agent/stats_engine/transactions.rb
@@ -119,7 +119,7 @@ def collecting_gc?
if !NewRelic::Control.instance.multi_threaded?
@@collecting_gc = true if GC.respond_to?(:time) && GC.respond_to?(:collections) # 1.8.x
@@collecting_gc = true if defined?(GC::Profiler) && GC::Profiler.enabled? # 1.9.2
- end
+ end
end
@@collecting_gc
end
View
46 lib/new_relic/agent/transaction_sampler.rb
@@ -24,7 +24,7 @@ def initialize
# size - it's only used by developer mode
@samples = []
@max_samples = 100
-
+
# @harvest_count is a count of harvests used for random
# sampling - we pull 1 @random_sample in every @sampling_rate harvests
@harvest_count = 0
@@ -50,21 +50,21 @@ def current_sample_id
b=builder
b and b.sample_id
end
-
+
# Enable the transaction sampler - this also registers it with
# the statistics engine.
def enable
@disabled = false
NewRelic::Agent.instance.stats_engine.transaction_sampler = self
end
-
+
# Disable the transaction sampler - this also deregisters it
# with the statistics engine.
def disable
@disabled = true
NewRelic::Agent.instance.stats_engine.remove_transaction_sampler(self)
end
-
+
# Set with an integer value n, this takes one in every n
# harvested samples. It also resets the harvest count to a
# random integer between 0 and (n-1)
@@ -73,14 +73,14 @@ def sampling_rate=(val)
@harvest_count = rand(val.to_i).to_i
end
-
+
# Creates a new transaction sample builder, unless the
# transaction sampler is disabled. Takes a time parameter for
# the start of the transaction sample
def notice_first_scope_push(time)
start_builder(time.to_f) unless disabled
end
-
+
# This delegates to the builder to create a new open transaction
# segment for the specified scope, beginning at the optionally
# specified time.
@@ -94,7 +94,7 @@ def notice_push_scope(scope, time=Time.now)
capture_segment_trace if NewRelic::Control.instance.developer_mode?
end
-
+
# in developer mode, capture the stack trace with the segment.
# this is cpu and memory expensive and therefore should not be
# turned on in production mode
@@ -112,7 +112,7 @@ def capture_segment_trace
segment[:backtrace] = trace
end
end
-
+
# Defaults to zero, otherwise delegated to the transaction
# sample builder
def scope_depth
@@ -120,7 +120,7 @@ def scope_depth
builder.scope_depth
end
-
+
# Informs the transaction sample builder about the end of a
# traced scope
def notice_pop_scope(scope, time = Time.now)
@@ -162,7 +162,7 @@ def store_sample(sample)
store_sample_for_developer_mode(sample)
store_slowest_sample(sample)
end
-
+
# Only active when random sampling is true - this is very rarely
# used. Always store the most recent sample so that random
# sampling can pick a few of the samples to store, upon harvest
@@ -180,19 +180,19 @@ def store_sample_for_developer_mode(sample)
@samples << sample
truncate_samples
end
-
+
# Sets @slowest_sample to the passed in sample if it is slower
# than the current sample in @slowest_sample
def store_slowest_sample(sample)
@slowest_sample = sample if slowest_sample?(@slowest_sample, sample)
end
-
+
# Checks to see if the old sample exists, or if it's duration is
# less than the new sample
def slowest_sample?(old_sample, new_sample)
old_sample.nil? || (new_sample.duration > old_sample.duration)
end
-
+
# Smashes the @samples array down to the length of @max_samples
# by taking the last @max_samples elements of the array
def truncate_samples
@@ -200,13 +200,13 @@ def truncate_samples
@samples = @samples[-@max_samples..-1]
end
end
-
+
# Delegates to the builder to store the path, uri, and
# parameters if the sampler is active
def notice_transaction(path, uri=nil, params={})
builder.set_transaction_info(path, uri, params) if !disabled && builder
end
-
+
# Tells the builder to ignore a transaction, if we are currently
# creating one. Only causes the sample to be ignored upon end of
# the transaction, and does not change the metrics gathered
@@ -219,7 +219,7 @@ def ignore_transaction
def notice_profile(profile)
builder.set_profile(profile) if builder
end
-
+
# Sets the CPU time used by a transaction, delegates to the builder
def notice_transaction_cpu_time(cpu_time)
builder.set_transaction_cpu_time(cpu_time) if builder
@@ -252,7 +252,7 @@ def truncate_message(message)
message
end
end
-
+
# Allows the addition of multiple pieces of metadata to one
# segment - i.e. traced method calls multiple sql queries
def append_new_message(old_message, message)
@@ -262,7 +262,7 @@ def append_new_message(old_message, message)
message
end
end
-
+
# Appends a backtrace to a segment if that segment took longer
# than the specified duration
def append_backtrace(segment, duration)
@@ -278,7 +278,7 @@ def notice_sql(sql, config, duration)
notice_extra_data(sql, duration, :sql, config, :connection_config)
end
end
-
+
# Adds non-sql metadata to a segment - generally the memcached
# key
#
@@ -286,12 +286,12 @@ def notice_sql(sql, config, duration)
def notice_nosql(key, duration)
notice_extra_data(key, duration, :key)
end
-
+
# Every 1/n harvests, adds the most recent sample to the harvest
# array if it exists. Makes sure that the random sample is not
# also the slowest sample for this harvest by `uniq!`ing the
# result array
- #
+ #
# random sampling is very, very seldom used
def add_random_sample_to(result)
return unless @random_sampling && @sampling_rate && @sampling_rate.to_i > 0
@@ -302,7 +302,7 @@ def add_random_sample_to(result)
result.uniq!
nil # don't assume this method returns anything
end
-
+
# Returns an array of slow samples, with either one or two
# elements - one element unless random sampling is enabled. The
# sample returned will be the slowest sample among those
@@ -347,7 +347,7 @@ def reset!
end
private
-
+
# Checks to see if the transaction sampler is disabled, if
# transaction trace recording is disabled by a thread local, or
# if execution is untraced - if so it clears the transaction
View
4 lib/new_relic/control.rb
@@ -41,8 +41,8 @@ module Frameworks; end
# include Configuration
# include ServerMethods
# include Instrumentation
-
-
+
+
end
end
View
2  lib/new_relic/control/class_methods.rb
@@ -5,7 +5,7 @@ module ClassMethods
def instance
@instance ||= new_instance
end
-
+
# Create the concrete class for environment specific behavior:
def new_instance
@local_env = NewRelic::LocalEnvironment.new
View
4 lib/new_relic/control/configuration.rb
@@ -63,7 +63,7 @@ def apdex_t
# Always initialized with a default
fetch('apdex_t').to_f
end
-
+
def license_key
fetch('license_key')
end
@@ -83,7 +83,7 @@ def developer_mode?
def browser_monitoring_auto_instrument?
fetch('browser_monitoring', {}).fetch('auto_instrument', true)
end
-
+
# True if the app runs in multi-threaded mode
def multi_threaded?
fetch('multi_threaded')
View
8 lib/new_relic/control/frameworks/rails.rb
@@ -28,10 +28,10 @@ def init_config(options={})
install_browser_monitoring(rails_config)
end
end
-
+
def install_browser_monitoring(config)
return if config.nil? || !config.respond_to?(:middleware) || !browser_monitoring_auto_instrument?
-
+
require 'new_relic/rack/browser_monitoring'
config.middleware.use NewRelic::Rack::BrowserMonitoring
::RAILS_DEFAULT_LOGGER.info "Installed browser monitoring middleware"
@@ -92,7 +92,7 @@ def rails_gem_list
gem.name + (version ? "(#{version})" : "")
end
end
-
+
# Collect the Rails::Info into an associative array as well as the list of plugins
def append_environment_info
local_env.append_environment_value('Rails version'){ ::Rails::VERSION::STRING }
@@ -121,7 +121,7 @@ def append_environment_info
end
end
end
-
+
def install_shim
super
require 'new_relic/agent/instrumentation/controller_instrumentation'
View
4 lib/new_relic/control/instance_methods.rb
@@ -8,7 +8,7 @@ module InstanceMethods
attr_reader :local_env
-
+
# Initialize the plugin/gem and start the agent. This does the
# necessary configuration based on the framework environment and
# determines whether or not to start the agent. If the agent is
@@ -116,7 +116,7 @@ def bundler_gem_list
[]
end
end
-
+
def config_file
File.expand_path(File.join(root,"config","newrelic.yml"))
end
View
2  lib/new_relic/control/instrumentation.rb
@@ -32,7 +32,7 @@ def add_instrumentation pattern
@instrumentation_files << pattern
end
end
-
+
def install_instrumentation
_install_instrumentation
end
View
4 lib/new_relic/control/server_methods.rb
@@ -34,7 +34,7 @@ def server_from_host(hostname=nil)
# if the host is not an IP address, turn it into one
NewRelic::Control::Server.new host, (self['port'] || (use_ssl? ? 443 : 80)).to_i, convert_to_ip_address(host)
end
-
+
# Check to see if we need to look up the IP address
# If it's an IP address already, we pass it through.
# If it's nil, or localhost, we don't bother.
@@ -48,7 +48,7 @@ def convert_to_ip_address(host)
log.info "Resolved #{host} to #{ip}"
ip
end
-
+
# Look up the ip address of the host using the pure ruby lookup
# to prevent blocking. If that fails, fall back to the regular
# IPSocket library. Return nil if we can't find the host ip
View
2  lib/new_relic/delayed_job_injection.rb
@@ -14,7 +14,7 @@ module DelayedJobInjection
depends_on do
defined?(::Delayed) && defined?(::Delayed::Worker)
end
-
+
executes do
Delayed::Worker.class_eval do
def initialize_with_new_relic(*args)
View
14 lib/new_relic/local_environment.rb
@@ -83,13 +83,13 @@ def gather_ruby_info
gather_jruby_info
end
end
-
+
def gather_jruby_info
append_environment_value('JRuby version') { JRUBY_VERSION }
append_environment_value('Java VM version') { ENV_JAVA['java.vm.version']}
end
-
- # See what the number of cpus is, works only on linux.
+
+ # See what the number of cpus is, works only on linux.
def gather_cpu_info
return unless File.readable? '/proc/cpuinfo'
@processors = append_environment_value('Processors') do
@@ -109,7 +109,7 @@ def gather_os_info
append_environment_value('OS') { `uname -s` } ||
append_environment_value('OS') { ENV['OS'] }
end
-
+
def gather_system_info
gather_architecture_info
gather_cpu_info
@@ -126,7 +126,7 @@ def gather_revision_info
end
def gather_ar_adapter_info
- # The name of the database adapter for the current environment.
+ # The name of the database adapter for the current environment.
append_environment_value 'Database adapter' do
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) &&
ActiveRecord::Base.respond_to?(:configurations)
@@ -165,14 +165,14 @@ def gather_environment_info
append_environment_value 'Dispatcher', @dispatcher.to_s if @dispatcher
append_environment_value 'Dispatcher instance id', @dispatcher_instance_id if @dispatcher_instance_id
append_environment_value('Environment') { NewRelic::Control.instance.env }
-
+
# miscellaneous other helpful debugging information
gather_ruby_info
gather_system_info
gather_revision_info
gather_db_info
end
-
+
# Take a snapshot of the environment information for this application
# Returns an associative array
def snapshot
View
20 lib/new_relic/rack/browser_monitoring.rb
@@ -2,7 +2,7 @@
module NewRelic::Rack
class BrowserMonitoring
-
+
def initialize(app, options = {})
@app = app
end
@@ -10,10 +10,10 @@ def initialize(app, options = {})
# method required by Rack interface
def call(env)
result = @app.call(env) # [status, headers, response]
-
+
if (NewRelic::Agent.browser_timing_header != "") && should_instrument?(result[0], result[1])
response_string = autoinstrument_source(result[2], result[1])
-
+
if (response_string)
Rack::Response.new(response_string, result[0], result[1]).finish
else
@@ -23,18 +23,18 @@ def call(env)
result
end
end
-
+
def should_instrument?(status, headers)
status == 200 && headers["Content-Type"] && headers["Content-Type"].include?("text/html")
end
- def autoinstrument_source(response, headers)
+ def autoinstrument_source(response, headers)
source = nil
response.each {|fragment| (source) ? (source << f) : (source = fragment)}
body_start = source.index("<body")
body_close = source.rindex("</body>")
-
+
if body_start && body_close
footer = NewRelic::Agent.browser_timing_footer
header = NewRelic::Agent.browser_timing_header
@@ -43,16 +43,16 @@ def autoinstrument_source(response, headers)
if head_open
head_close = source.index(">", head_open)
-
+
head_pos = head_close + 1
else
# put the header right above body start
head_pos = body_start
end
-
+
source = source[0..(head_pos-1)] + header + source[head_pos..(body_close-1)] + footer + source[body_close..-1]
-
- headers['Content-Length'] = source.length.to_s if headers['Content-Length']
+
+ headers['Content-Length'] = source.length.to_s if headers['Content-Length']
end
source
View
10 lib/new_relic/stats.rb
@@ -17,7 +17,7 @@ def time_str(value_ms)
"%.0f ms" % value_ms
end
end
-
+
# makes sure we aren't dividing by zero
def checked_calculation(numerator, denominator)
if denominator.nil? || denominator == 0
@@ -26,7 +26,7 @@ def checked_calculation(numerator, denominator)
numerator.to_f / denominator
end
end
-
+
def average_call_time
checked_calculation(total_call_time, call_count)
end
@@ -70,7 +70,7 @@ def should_replace_begin_time?(other)
def update_totals(other)
self.total_call_time += other.total_call_time
self.total_exclusive_time += other.total_exclusive_time
- self.sum_of_squares += other.sum_of_squares
+ self.sum_of_squares += other.sum_of_squares
end
def min_time_less?(other)
@@ -79,7 +79,7 @@ def min_time_less?(other)
def expand_min_max_to(other)
self.min_call_time = other.min_call_time if min_time_less?(other)
- self.max_call_time = other.max_call_time if other.max_call_time > max_call_time
+ self.max_call_time = other.max_call_time if other.max_call_time > max_call_time
end
def merge_attributes(other)
@@ -88,7 +88,7 @@ def merge_attributes(other)
self.call_count += other.call_count
update_boundaries(other)
end
-
+
def merge!(other_stats)
Array(other_stats).each do |other|
merge_attributes(other)
View
10 test/active_record_fixtures.rb
@@ -37,7 +37,7 @@ def connection.log_info *args
end
end
end
-
+
class Shipment < ActiveRecord::Base
self.table_name = 'newrelic_test_shipment'
has_and_belongs_to_many :orders, :class_name => 'ActiveRecordFixtures::Order'
@@ -46,14 +46,14 @@ def self.setup
# no other columns
end
connection.create_table 'orders_shipments', :force => true, :id => false do |t|
- t.column :order_id, :integer
- t.column :shipment_id, :integer
+ t.column :order_id, :integer
+ t.column :shipment_id, :integer
end
end
-
+
def self.teardown
connection.drop_table 'orders_shipments'
connection.drop_table self.table_name
end
- end
+ end
end
View
6 test/config/test_control.rb
@@ -19,10 +19,10 @@ def app
:rails
end
end
-
+
def initialize *args
super
- setup_log
+ setup_log
end
# when running tests, don't write out stderr
def log!(msg, level=:info)
@@ -37,7 +37,7 @@ def install_devmode_route
def draw_with_test_route
draw_without_test_route do | map |
map.connect ':controller/:action/:id'
- yield map
+ yield map
end
end
alias_method_chain :draw, :test_route
View
14 test/new_relic/agent/agent/connect_test.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.join(File.dirname(__FILE__),'..', '..', '..','test_helper'))
+require File.expand_path(File.join(File.dirname(__FILE__),'..', '..', '..','test_helper'))
class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
require 'new_relic/agent/agent'
include NewRelic::Agent::Agent::Connect
@@ -9,7 +9,7 @@ def setup
@connect_attempts = 1
@connect_retry_period = 0
end
-
+
def test_tried_to_connect?
# base case, should default to false
assert !tried_to_connect?({})
@@ -20,7 +20,7 @@ def test_tried_to_connect_connected
@connected = true
assert tried_to_connect?({})
end
-
+
def test_tried_to_connect_forced
# is false if force_reconnect is true
assert !tried_to_connect?({:force_reconnect => true})
@@ -116,7 +116,7 @@ def test_no_seed_token
log.expects(:debug).never
log_seed_token
end
-
+
def mocks_for_positive_environment_for_connect(value_for_control)
control = mocked_control
control.expects(:'[]').with('send_environment_info').once.returns(value_for_control)
@@ -124,7 +124,7 @@ def mocks_for_positive_environment_for_connect(value_for_control)
fake_env.expects(:snapshot).once.returns("snapshot")
control.expects(:local_env).once.returns(fake_env)
end
-
+
def test_environment_for_connect_nil
mocks_for_positive_environment_for_connect(nil)
assert_equal 'snapshot', environment_for_connect
@@ -215,7 +215,7 @@ def test_configure_transaction_tracer_with_random_sampling
configure_transaction_tracer!(true, 10)
assert @should_send_samples
end
-
+
def test_configure_transaction_tracer_positive
@config_should_send_samples = true
@slowest_transaction_threshold = 5
@@ -287,7 +287,7 @@ def test_finish_setup
assert_equal 'pasta sauce', @report_period
assert_equal 'tamales', @url_rules
end
-
+
private
def mocked_control
View
26 test/new_relic/agent/agent/start_test.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
+require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
require 'new_relic/agent/agent'
include NewRelic::Agent::Agent::Start
@@ -14,7 +14,7 @@ def test_already_started_negative
self.expects(:started?).returns(false)
assert !already_started?
end
-
+
def test_disabled_positive
control = mocked_control
control.expects(:agent_enabled?).returns(false)
@@ -79,14 +79,14 @@ def test_set_sql_recording_off
set_sql_recording!
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
end
-
+
def test_set_sql_recording_none
self.expects(:sampler_config).returns({'record_sql' => 'none'})
self.expects(:log_sql_transmission_warning?)
set_sql_recording!
assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
end
-
+
def test_set_sql_recording_raw
self.expects(:sampler_config).returns({'record_sql' => 'raw'})
self.expects(:log_sql_transmission_warning?)
@@ -129,13 +129,13 @@ def test_config_transaction_tracer
fake_sampler_config.expects(:fetch).with('explain_threshold', 0.5)
fake_sampler_config.expects(:fetch).with('explain_enabled', true)
self.expects(:set_sql_recording!)
-
+
fake_sampler_config.expects(:fetch).with('transaction_threshold', 2.0)
self.expects(:apdex_f_threshold?).returns(true)
self.expects(:apdex_f)
config_transaction_tracer
end
-
+
def test_check_config_and_start_agent_disabled
self.expects(:monitoring?).returns(false)
check_config_and_start_agent
@@ -146,7 +146,7 @@ def test_check_config_and_start_agent_incorrect_key
self.expects(:has_correct_license_key?).returns(false)
check_config_and_start_agent
end
-
+
def test_check_config_and_start_agent_forking
self.expects(:monitoring?).returns(true)
self.expects(:has_correct_license_key?).returns(true)
@@ -164,7 +164,7 @@ def test_check_config_and_start_agent_normal
self.expects(:install_exit_handler)
check_config_and_start_agent
end
-
+
def test_check_config_and_start_agent_sync
self.expects(:monitoring?).returns(true)
self.expects(:has_correct_license_key?).returns(true)
@@ -176,17 +176,17 @@ def test_check_config_and_start_agent_sync
self.expects(:install_exit_handler)
check_config_and_start_agent
end
-
+
def test_connect_in_foreground
self.expects(:connect).with({:keep_retrying => false })
connect_in_foreground
end
-
+
def at_exit
yield
end
private :at_exit
-
+
def test_install_exit_handler_positive
control = mocked_control
control.expects(:send_data_on_exit).returns(true)
@@ -199,7 +199,7 @@ def test_install_exit_handler_positive
self.expects(:shutdown)
install_exit_handler
end
-
+
def test_install_exit_handler_negative
control = mocked_control
control.expects(:send_data_on_exit).returns(false)
@@ -321,7 +321,7 @@ def test_log_if_positive
def test_log_if_negative
assert !log_if(false, :warn, "WHEE")
end
-
+
private
def mocked_log
View
16 test/new_relic/agent/agent/start_worker_thread_test.rb
@@ -1,8 +1,8 @@
-require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
+require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
require 'new_relic/agent/agent'
include NewRelic::Agent::Agent::StartWorkerThread
-
+
def test_deferred_work_connects
self.expects(:catch_errors).yields
self.expects(:connect).with('connection_options')
@@ -71,7 +71,7 @@ def test_create_and_run_worker_loop
self.expects(:harvest_and_send_errors)
create_and_run_worker_loop
end
-
+
def test_handle_force_restart
# hooray for methods with no branches
error = mock('exception')
@@ -80,12 +80,12 @@ def test_handle_force_restart
log.expects(:info).with('a message')
self.expects(:reset_stats)
self.expects(:sleep).with(30)
-
+
@metric_ids = 'this is not an empty hash'
@connected = true
-
+
handle_force_restart(error)
-
+
assert_equal({}, @metric_ids)
assert @connected.nil?
end
@@ -125,7 +125,7 @@ def test_handle_other_error
self.expects(:disconnect)
handle_other_error(error)
end
-
+
def test_catch_errors_force_restart
@runs = 0
error = NewRelic::Agent::ForceRestartException.new
@@ -138,7 +138,7 @@ def test_catch_errors_force_restart
end
assert_equal 3, @runs, 'should retry the block when it fails'
end
-
+
private
def mocked_log
View
48 test/new_relic/agent/agent_test.rb
@@ -3,33 +3,33 @@ module NewRelic
module Agent
class AgentTest < Test::Unit::TestCase
def test_sql_normalization
-
+
# basic statement
- assert_equal "INSERT INTO X values(?,?, ? , ?)",
+ assert_equal "INSERT INTO X values(?,?, ? , ?)",
NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT INTO X values('test',0, 1 , 2)")
-
+
# escaped literals
- assert_equal "INSERT INTO X values(?, ?,?, ? , ?)",
+ assert_equal "INSERT INTO X values(?, ?,?, ? , ?)",
NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT INTO X values('', 'jim''s ssn',0, 1 , 'jim''s son''s son')")
-
- # multiple string literals
- assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
+
+ # multiple string literals
+ assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT INTO X values('jim''s ssn','x',0, 1 , 2)")
-
+
# empty string literal
# NOTE: the empty string literal resolves to empty string, which for our purposes is acceptable
- assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
+ assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT INTO X values('','x',0, 1 , 2)")
-
- # try a select statement
+
+ # try a select statement
assert_equal "select * from table where name=? and ssn=?",
NewRelic::Agent.instance.send(:default_sql_obfuscator, "select * from table where name='jim gochee' and ssn=0012211223")
-
+
# number literals embedded in sql - oh well
assert_equal "select * from table_? where name=? and ssn=?",
NewRelic::Agent.instance.send(:default_sql_obfuscator, "select * from table_007 where name='jim gochee' and ssn=0012211223")
end
-
+
def test_sql_normalization__single_quotes
assert_equal "INSERT ? into table",
NewRelic::Agent.instance.send(:default_sql_obfuscator, "INSERT 'this isn''t a real value' into table")
@@ -37,7 +37,7 @@ def test_sql_normalization__single_quotes
NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT '"' into table])
assert_equal "INSERT ? into table",
NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT ' "some text" \" ' into table])
- # could not get this one licked. no biggie
+ # could not get this one licked. no biggie
# assert_equal "INSERT ? into table",
# NewRelic::Agent.instance.send(:default_sql_obfuscator, %q[INSERT '\'' into table])
assert_equal "INSERT ? into table",
@@ -55,31 +55,31 @@ def test_sql_normalization__double_quotes
end
def test_sql_obfuscation_filters
orig = NewRelic::Agent.agent.obfuscator
-
+
NewRelic::Agent.set_sql_obfuscator(:replace) do |sql|
sql = "1" + sql
end
-
+
sql = "SELECT * FROM TABLE 123 'jim'"
-
+
assert_equal "1" + sql, NewRelic::Agent.instance.obfuscator.call(sql)
-
+
NewRelic::Agent.set_sql_obfuscator(:before) do |sql|
sql = "2" + sql
end
-
+
assert_equal "12" + sql, NewRelic::Agent.instance.obfuscator.call(sql)
-
+
NewRelic::Agent.set_sql_obfuscator(:after) do |sql|
sql = sql + "3"
end
-
+
assert_equal "12" + sql + "3", NewRelic::Agent.instance.obfuscator.call(sql)
-
+
NewRelic::Agent.agent.set_sql_obfuscator(:replace, &orig)
end
-
-
+
+
end
end
end
View
18 test/new_relic/agent/agent_test_controller.rb
@@ -1,4 +1,4 @@
-# Defining a test controller class with a superclass, used to
+# Defining a test controller class with a superclass, used to
# verify correct attribute inheritence
class NewRelic::Agent::SuperclassController < ActionController::Base
def base_action
@@ -8,7 +8,7 @@ def base_action
# This is a controller class used in testing controller instrumentation
class NewRelic::Agent::AgentTestController < NewRelic::Agent::SuperclassController
filter_parameter_logging :social_security_number
-
+
@@headers_to_add = nil
def index
@@ -21,7 +21,7 @@ def _filter_parameters(params)
def action_inline
render(:inline => "<%= 'foo' %>fah")
end
-
+
def action_to_render
render :text => params.inspect
end
@@ -40,7 +40,7 @@ def oops
end
class TestException < RuntimeError
end
-
+
def rescue_action_locally(exception)
if exception.is_a? TestException
raise "error in the handler"
@@ -52,22 +52,22 @@ def action_with_error