newrelic_rpm 3.5.4.35.beta → 3.5.5.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/CHANGELOG +42 -0
  2. data/GUIDELINES_FOR_CONTRIBUTING.md +3 -0
  3. data/Rakefile +8 -0
  4. data/bin/mongrel_rpm +1 -1
  5. data/init.rb +1 -8
  6. data/lib/new_relic/agent.rb +11 -13
  7. data/lib/new_relic/agent/agent.rb +89 -110
  8. data/lib/new_relic/agent/agent_logger.rb +165 -0
  9. data/lib/new_relic/agent/audit_logger.rb +72 -0
  10. data/lib/new_relic/agent/beacon_configuration.rb +4 -4
  11. data/lib/new_relic/agent/browser_monitoring.rb +13 -7
  12. data/lib/new_relic/agent/busy_calculator.rb +2 -2
  13. data/lib/new_relic/agent/configuration.rb +25 -0
  14. data/lib/new_relic/agent/configuration/defaults.rb +45 -8
  15. data/lib/new_relic/agent/configuration/environment_source.rb +8 -15
  16. data/lib/new_relic/agent/configuration/manager.rb +22 -2
  17. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  18. data/lib/new_relic/agent/configuration/yaml_source.rb +4 -2
  19. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  20. data/lib/new_relic/agent/database.rb +2 -4
  21. data/lib/new_relic/agent/error_collector.rb +4 -9
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  26. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  27. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +7 -7
  28. data/lib/new_relic/agent/instrumentation/data_mapper.rb +1 -1
  29. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  30. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
  31. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
  36. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +4 -4
  37. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  38. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  39. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -3
  40. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/resque.rb +3 -2
  42. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
  43. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +2 -2
  45. data/lib/new_relic/agent/method_tracer.rb +6 -8
  46. data/lib/new_relic/agent/new_relic_service.rb +94 -106
  47. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  48. data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -6
  49. data/lib/new_relic/agent/sql_sampler.rb +3 -18
  50. data/lib/new_relic/agent/stats_engine.rb +0 -5
  51. data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
  52. data/lib/new_relic/agent/stats_engine/samplers.rb +2 -4
  53. data/lib/new_relic/agent/thread.rb +8 -3
  54. data/lib/new_relic/agent/thread_profiler.rb +38 -27
  55. data/lib/new_relic/agent/transaction_info.rb +1 -1
  56. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
  57. data/lib/new_relic/agent/transaction_sampler.rb +3 -7
  58. data/lib/new_relic/agent/worker_loop.rb +3 -11
  59. data/lib/new_relic/control.rb +0 -2
  60. data/lib/new_relic/control/class_methods.rb +8 -2
  61. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  62. data/lib/new_relic/control/frameworks/rails.rb +8 -29
  63. data/lib/new_relic/control/frameworks/rails3.rb +8 -20
  64. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  65. data/lib/new_relic/control/frameworks/ruby.rb +1 -22
  66. data/lib/new_relic/control/instance_methods.rb +12 -34
  67. data/lib/new_relic/control/instrumentation.rb +7 -12
  68. data/lib/new_relic/control/server_methods.rb +5 -8
  69. data/lib/new_relic/delayed_job_injection.rb +1 -1
  70. data/lib/new_relic/local_environment.rb +30 -64
  71. data/lib/new_relic/metric_data.rb +1 -1
  72. data/lib/new_relic/metric_spec.rb +1 -1
  73. data/lib/new_relic/noticed_error.rb +1 -1
  74. data/lib/new_relic/rack/browser_monitoring.rb +5 -5
  75. data/lib/new_relic/stats.rb +9 -7
  76. data/lib/new_relic/transaction_sample.rb +2 -7
  77. data/lib/new_relic/version.rb +1 -1
  78. data/lib/newrelic_rpm.rb +1 -1
  79. data/newrelic_rpm.gemspec.erb +15 -17
  80. data/test/config/newrelic.yml +1 -1
  81. data/test/config/test_control.rb +18 -18
  82. data/test/fixtures/gemspec_no_build.rb +0 -2
  83. data/test/fixtures/gemspec_with_build.rb +0 -2
  84. data/test/fixtures/gemspec_with_build_and_stage.rb +0 -2
  85. data/test/multiverse/README.md +3 -8
  86. data/test/multiverse/suites/agent_only/Envfile +1 -0
  87. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  88. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  89. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  90. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  91. data/test/multiverse/suites/logging/Envfile +4 -0
  92. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  93. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  94. data/test/multiverse/suites/no_load/config/newrelic.yml +1 -2
  95. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +0 -13
  96. data/test/new_relic/agent/agent/connect_test.rb +30 -92
  97. data/test/new_relic/agent/agent/start_test.rb +4 -84
  98. data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -43
  99. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  100. data/test/new_relic/agent/agent_test.rb +10 -9
  101. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  102. data/test/new_relic/agent/browser_monitoring_test.rb +2 -1
  103. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  104. data/test/new_relic/agent/configuration/environment_source_test.rb +25 -20
  105. data/test/new_relic/agent/configuration/manager_test.rb +59 -4
  106. data/test/new_relic/agent/configuration/yaml_source_test.rb +20 -1
  107. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  108. data/test/new_relic/agent/database_test.rb +0 -11
  109. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -3
  110. data/test/new_relic/agent/error_collector_test.rb +11 -7
  111. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +39 -19
  112. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  113. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  114. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +0 -6
  115. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  116. data/test/new_relic/agent/new_relic_service_test.rb +48 -8
  117. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
  118. data/test/new_relic/agent/sql_sampler_test.rb +1 -1
  119. data/test/new_relic/agent/thread_profiler_test.rb +46 -45
  120. data/test/new_relic/agent/thread_test.rb +13 -0
  121. data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -1
  122. data/test/new_relic/agent/worker_loop_test.rb +4 -9
  123. data/test/new_relic/agent_test.rb +6 -9
  124. data/test/new_relic/control/class_methods_test.rb +0 -18
  125. data/test/new_relic/control_test.rb +6 -9
  126. data/test/new_relic/dispatcher_test.rb +54 -0
  127. data/test/new_relic/fake_collector.rb +15 -14
  128. data/test/new_relic/fake_service.rb +4 -1
  129. data/test/new_relic/fakes_sending_data.rb +30 -0
  130. data/test/new_relic/framework_test.rb +53 -0
  131. data/test/new_relic/local_environment_test.rb +5 -2
  132. data/test/new_relic/rack/browser_monitoring_test.rb +2 -1
  133. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  134. data/test/new_relic/stats_test.rb +10 -0
  135. data/test/new_relic/transaction_sample_test.rb +2 -2
  136. data/test/script/ci.sh +1 -1
  137. data/test/test_helper.rb +23 -0
  138. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  139. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  140. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  141. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  142. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  143. metadata +47 -41
  144. data/InstallationNotes.md +0 -15
  145. data/lib/new_relic/control/logging_methods.rb +0 -125
  146. data/test/multiverse/Rakefile +0 -17
  147. data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +0 -422
  148. data/test/new_relic/control/logging_methods_test.rb +0 -211
@@ -49,7 +49,7 @@ module NewRelic
49
49
  "#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}, metric_id:#{metric_id.inspect}>"
50
50
  end
51
51
 
52
- def to_collector_array(marshaller=nil)
52
+ def to_collector_array(encoder=nil)
53
53
  stat_key = metric_id || { 'name' => metric_spec.name, 'scope' => metric_spec.scope }
54
54
  [ stat_key,
55
55
  [ stats.call_count, stats.total_call_time, stats.total_exclusive_time,
@@ -44,7 +44,7 @@ class NewRelic::MetricSpec
44
44
  # return a new metric spec if the given regex
45
45
  # matches the name or scope.
46
46
  def sub(pattern, replacement, apply_to_scope = true)
47
- NewRelic::Control.instance.log.warn("The sub method on metric specs is deprecated") rescue nil
47
+ ::NewRelic::Agent.logger.warn("The sub method on metric specs is deprecated") rescue nil
48
48
  return nil if name !~ pattern &&
49
49
  (!apply_to_scope || scope.nil? || scope !~ pattern)
50
50
  new_name = name.sub(pattern, replacement)[LENGTH_RANGE]
@@ -45,7 +45,7 @@ class NewRelic::NoticedError
45
45
  end
46
46
  end
47
47
 
48
- def to_collector_array(marshaller=nil)
48
+ def to_collector_array(encoder=nil)
49
49
  [ (@timestamp.to_f * 1000).round, @path, @message, @exception_class,
50
50
  @params ]
51
51
  end
@@ -48,14 +48,14 @@ module NewRelic::Rack
48
48
 
49
49
  head_pos = if x_ua_compatible_found
50
50
  # put at end of header if X-UA-Compatible meta tag found
51
- NewRelic::Agent.logger.debug "Detected X-UA-Compatible meta tag. Attempting to insert RUM header at end of head."
51
+ ::NewRelic::Agent.logger.debug "Detected X-UA-Compatible meta tag. Attempting to insert RUM header at end of head."
52
52
  beginning_of_source.index("</head>")
53
53
  elsif head_open = beginning_of_source.index("<head")
54
- NewRelic::Agent.logger.debug "Attempting to insert RUM header at beginning of head."
54
+ ::NewRelic::Agent.logger.debug "Attempting to insert RUM header at beginning of head."
55
55
  # put at the beginning of the header
56
56
  beginning_of_source.index(">", head_open) + 1
57
57
  else
58
- NewRelic::Agent.logger.debug "Failed to detect head tag. Attempting to insert RUM header at above body tag."
58
+ ::NewRelic::Agent.logger.debug "Failed to detect head tag. Attempting to insert RUM header at above body tag."
59
59
  # otherwise put the header right above body start
60
60
  body_start
61
61
  end
@@ -71,9 +71,9 @@ module NewRelic::Rack
71
71
  source[body_close..-1]
72
72
  else
73
73
  if head_pos
74
- NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Failed to detect head tags."
74
+ ::NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Failed to detect head tags."
75
75
  else
76
- NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Detected head is after detected body close."
76
+ ::NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Detected head is after detected body close."
77
77
  end
78
78
  end
79
79
  end
@@ -219,13 +219,15 @@ module NewRelic
219
219
  super
220
220
  end
221
221
 
222
- def to_json(*a)
223
- {'call_count' => call_count,
224
- 'min_call_time' => min_call_time,
225
- 'max_call_time' => max_call_time,
226
- 'total_call_time' => total_call_time,
227
- 'total_exclusive_time' => total_exclusive_time,
228
- 'sum_of_squares' => sum_of_squares}.to_json(*a)
222
+ def to_json(*_)
223
+ {
224
+ 'call_count' => call_count.to_i,
225
+ 'min_call_time' => min_call_time.to_f,
226
+ 'max_call_time' => max_call_time.to_f,
227
+ 'total_call_time' => total_call_time.to_f,
228
+ 'total_exclusive_time' => total_exclusive_time.to_f,
229
+ 'sum_of_squares' => sum_of_squares.to_f
230
+ }.to_json(*_)
229
231
  end
230
232
 
231
233
 
@@ -62,13 +62,8 @@ module NewRelic
62
62
  @root_segment.to_array ]
63
63
  end
64
64
 
65
- def to_collector_array(marshaller)
66
- trace_tree = if marshaller.respond_to?(:encode_compress)
67
- marshaller.encode_compress(self.to_array)
68
- else
69
- self.to_array
70
- end
71
-
65
+ def to_collector_array(encoder)
66
+ trace_tree = encoder.encode(self.to_array)
72
67
  [ Helper.time_to_millis(@start_time), Helper.time_to_millis(duration),
73
68
  @params[:path], @params[:uri], trace_tree, @guid, nil,
74
69
  !!@force_persist ]
@@ -18,7 +18,7 @@ module NewRelic
18
18
  GEMSPEC_PATH = File.join(File.dirname(__FILE__), '..', '..', 'newrelic_rpm.gemspec')
19
19
  MAJOR = 3
20
20
  MINOR = 5
21
- TINY = 4
21
+ TINY = 5
22
22
  BUILD = parse_build_from_gemspec(GEMSPEC_PATH)
23
23
 
24
24
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
data/lib/newrelic_rpm.rb CHANGED
@@ -28,7 +28,7 @@ if defined?(Merb) && defined?(Merb::BootLoader)
28
28
  end
29
29
  end
30
30
  elsif defined? Rails
31
- if Rails.respond_to?(:version) && Rails.version =~ /^3/
31
+ if Rails.respond_to?(:version) && Rails.version > '3'
32
32
  module NewRelic
33
33
  class Railtie < Rails::Railtie
34
34
 
@@ -27,26 +27,24 @@ EOS
27
27
  "<%= file %>",<% end %>
28
28
  ]
29
29
  s.homepage = "http://www.github.com/newrelic/rpm"
30
- s.post_install_message = <<-EOS
31
- PLEASE NOTE:
32
30
 
33
- Developer Mode is now a Rack middleware.
31
+ <% # Print this version's CHANGELOG as a post_install_message.
32
+ version_count = 0
33
+ changes = []
34
+ File.read(File.join(File.dirname(__FILE__), 'CHANGELOG')).each_line do |line|
35
+ if line.match(/##\s+v[\d.]+\s+##/)
36
+ version_count += 1
37
+ end
38
+ break if version_count >= 2
39
+ changes << line.chomp
40
+ end
41
+ %>
34
42
 
35
- Developer Mode is no longer available in Rails 2.1 and earlier.
36
- However, starting in version 2.12 you can use Developer Mode in any
37
- Rack based framework, in addition to Rails. To install developer mode
38
- in a non-Rails application, just add NewRelic::Rack::DeveloperMode to
39
- your middleware stack.
40
-
41
- If you are using JRuby, we recommend using at least version 1.4 or
42
- later because of issues with the implementation of the timeout library.
43
-
44
- Refer to the README.md file for more information.
45
-
46
- Please see http://github.com/newrelic/rpm/blob/master/CHANGELOG
47
- for a complete description of the features and enhancements available
48
- in this version of the Ruby Agent.
43
+ s.post_install_message = <<'EOS'
44
+ <%= changes.join("\n") %>
49
45
 
46
+ See https://github.com/newrelic/rpm/blob/master/CHANGELOG for a full list of
47
+ changes.
50
48
  EOS
51
49
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "New Relic Ruby Agent"]
52
50
  s.require_paths = ["lib"]
@@ -24,7 +24,7 @@ test:
24
24
  - a
25
25
  - b
26
26
  - c
27
- log_file_path: <%= ::Rails::VERSION::MAJOR == 3 ? Rails.root : RAILS_ROOT %>/log
27
+ log_file_path: <%= ::Rails::VERSION::MAJOR >= 3 ? Rails.root : RAILS_ROOT %>/log
28
28
 
29
29
  # Some fixtures for newrelic.yml parsing tests
30
30
  erb_value: <%= 'hey'*3 %>
@@ -1,34 +1,34 @@
1
1
  require 'new_relic/control/frameworks/rails'
2
2
  require 'new_relic/control/frameworks/rails3'
3
+ require 'new_relic/control/frameworks/rails4'
3
4
 
4
- if defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i == 3
5
- parent_class = NewRelic::Control::Frameworks::Rails3
6
- else
7
- parent_class = NewRelic::Control::Frameworks::Rails
5
+ if defined?(::Rails) && ::Rails.respond_to?(:version)
6
+ parent_class = case ::Rails.version.to_i
7
+ when 4
8
+ NewRelic::Control::Frameworks::Rails4
9
+ when 3
10
+ NewRelic::Control::Frameworks::Rails3
11
+ end
8
12
  end
9
-
13
+ parent_class ||= NewRelic::Control::Frameworks::Rails
10
14
 
11
15
  class NewRelic::Control::Frameworks::Test < parent_class
12
16
  def env
13
17
  'test'
14
18
  end
19
+
15
20
  def app
16
- if defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i == 3
17
- :rails3
18
- else
19
- :rails
21
+ if defined?(::Rails::VERSION)
22
+ if ::Rails::VERSION::MAJOR.to_i == 4
23
+ :rails4
24
+ elsif ::Rails::VERSION::MAJOR.to_i == 3
25
+ :rails3
26
+ else
27
+ :rails
28
+ end
20
29
  end
21
30
  end
22
31
 
23
- def initialize *args
24
- super
25
- setup_log
26
- end
27
- # when running tests, don't write out stderr
28
- def log!(msg, level=:info)
29
- log.send level, msg if log
30
- end
31
-
32
32
  # Add the default route in case it's missing. Need it for testing.
33
33
  def install_devmode_route
34
34
  super
@@ -125,7 +125,6 @@ EOS
125
125
  "lib/new_relic/control/frameworks/sinatra.rb",
126
126
  "lib/new_relic/control/instance_methods.rb",
127
127
  "lib/new_relic/control/instrumentation.rb",
128
- "lib/new_relic/control/logging_methods.rb",
129
128
  "lib/new_relic/control/profiling.rb",
130
129
  "lib/new_relic/control/server_methods.rb",
131
130
  "lib/new_relic/delayed_job_injection.rb",
@@ -300,7 +299,6 @@ EOS
300
299
  "test/new_relic/command/deployments_test.rb",
301
300
  "test/new_relic/control/class_methods_test.rb",
302
301
  "test/new_relic/control/frameworks/rails_test.rb",
303
- "test/new_relic/control/logging_methods_test.rb",
304
302
  "test/new_relic/control_test.rb",
305
303
  "test/new_relic/delayed_job_injection_test.rb",
306
304
  "test/new_relic/fake_collector.rb",
@@ -125,7 +125,6 @@ EOS
125
125
  "lib/new_relic/control/frameworks/sinatra.rb",
126
126
  "lib/new_relic/control/instance_methods.rb",
127
127
  "lib/new_relic/control/instrumentation.rb",
128
- "lib/new_relic/control/logging_methods.rb",
129
128
  "lib/new_relic/control/profiling.rb",
130
129
  "lib/new_relic/control/server_methods.rb",
131
130
  "lib/new_relic/delayed_job_injection.rb",
@@ -300,7 +299,6 @@ EOS
300
299
  "test/new_relic/command/deployments_test.rb",
301
300
  "test/new_relic/control/class_methods_test.rb",
302
301
  "test/new_relic/control/frameworks/rails_test.rb",
303
- "test/new_relic/control/logging_methods_test.rb",
304
302
  "test/new_relic/control_test.rb",
305
303
  "test/new_relic/delayed_job_injection_test.rb",
306
304
  "test/new_relic/fake_collector.rb",
@@ -125,7 +125,6 @@ EOS
125
125
  "lib/new_relic/control/frameworks/sinatra.rb",
126
126
  "lib/new_relic/control/instance_methods.rb",
127
127
  "lib/new_relic/control/instrumentation.rb",
128
- "lib/new_relic/control/logging_methods.rb",
129
128
  "lib/new_relic/control/profiling.rb",
130
129
  "lib/new_relic/control/server_methods.rb",
131
130
  "lib/new_relic/delayed_job_injection.rb",
@@ -300,7 +299,6 @@ EOS
300
299
  "test/new_relic/command/deployments_test.rb",
301
300
  "test/new_relic/control/class_methods_test.rb",
302
301
  "test/new_relic/control/frameworks/rails_test.rb",
303
- "test/new_relic/control/logging_methods_test.rb",
304
302
  "test/new_relic/control_test.rb",
305
303
  "test/new_relic/delayed_job_injection_test.rb",
306
304
  "test/new_relic/fake_collector.rb",
@@ -13,22 +13,17 @@ painless.
13
13
 
14
14
  ## Getting started
15
15
 
16
- To run tests against the agent invoke the runner script.
17
-
18
- script/runner
19
-
20
-
21
16
  You can invoke this via rake
22
17
 
23
- rake test
18
+ rake test:multiverse
24
19
 
25
20
  If you only want to run some test suites you can filter by their names
26
21
 
27
- script/runner sinatra
22
+ rake test:multiverse[sinatra]
28
23
 
29
24
  You can run tests of multiverse itself with
30
25
 
31
- rake test:self
26
+ rake test:multiverse:self
32
27
 
33
28
  ### Adding a test suite
34
29
 
@@ -1,3 +1,4 @@
1
1
  gemfile <<-RB
2
2
  gem 'rack'
3
+ gem 'mocha', '< 0.13'
3
4
  RB
@@ -0,0 +1,99 @@
1
+ # RUBY-981 Audit Log
2
+
3
+ require 'newrelic_rpm'
4
+ require 'fake_collector'
5
+ require 'mocha'
6
+
7
+ class AuditLogTest < Test::Unit::TestCase
8
+ # Initialization
9
+ def setup
10
+ $collector ||= NewRelic::FakeCollector.new
11
+ $collector.reset
12
+ $collector.run
13
+
14
+ @string_log = StringIO.new
15
+ NewRelic::Agent::AuditLogger.any_instance.stubs(:ensure_log_path).returns(@string_log)
16
+ end
17
+
18
+ def teardown
19
+ $collector.reset
20
+ end
21
+
22
+ def audit_log_contents
23
+ if @contents.nil?
24
+ @string_log.rewind
25
+ @contents = @string_log.read
26
+ end
27
+ @contents
28
+ end
29
+
30
+ def assert_audit_log_contains(needle)
31
+ # Original request bodies dumped to the log have symbol keys, but once
32
+ # they go through a dump/load, they're strings again, so we strip
33
+ # double-quotes and colons from the log, and the strings we searching for.
34
+ regex = /[:"]/
35
+ needle = needle.gsub(regex, '')
36
+ haystack = audit_log_contents.gsub(regex, '')
37
+ assert(haystack.include?(needle), "Expected log to contain '#{needle}'")
38
+ end
39
+
40
+ # Because we don't generate a strictly machine-readable representation of
41
+ # request bodies for the audit log, the transformation into strings is
42
+ # effectively one-way. This, combined with the fact that Hash traversal order
43
+ # is arbitrary in Ruby 1.8.x means that it's difficult to directly assert that
44
+ # some object graph made it into the audit log (due to different possible
45
+ # orderings of the key/value pairs in Hashes that were embedded in the request
46
+ # body). So, this method traverses an object graph and only makes assertions
47
+ # about the terminal (non-Array-or-Hash) nodes therein.
48
+ def assert_audit_log_contains_object(o, format)
49
+ if format == :json
50
+ assert_audit_log_contains(JSON.dump(o))
51
+ else
52
+ case o
53
+ when Hash
54
+ o.each do |k,v|
55
+ assert_audit_log_contains_object(v, format)
56
+ end
57
+ when Array
58
+ o.each do |el|
59
+ assert_audit_log_contains_object(el, format)
60
+ end
61
+ else
62
+ assert_audit_log_contains(o.inspect)
63
+ end
64
+ end
65
+ end
66
+
67
+ def run_agent_with_options(options)
68
+ NewRelic::Agent.manual_start(options)
69
+ yield NewRelic::Agent.agent if block_given?
70
+ NewRelic::Agent.shutdown
71
+ end
72
+
73
+ def test_logs_nothing_by_default
74
+ run_agent_with_options({})
75
+ assert_equal('', audit_log_contents)
76
+ end
77
+
78
+ def test_logs_nothing_when_disabled
79
+ run_agent_with_options({ :'audit_log.enabled' => false })
80
+ assert_equal('', audit_log_contents)
81
+ end
82
+
83
+ def test_logs_request_bodies_human_readably_ish
84
+ format = NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported? ? :json : :pruby
85
+ run_agent_with_options({ :'audit_log.enabled' => true }) do |agent|
86
+ agent.sql_sampler.notice_first_scope_push(nil)
87
+ agent.sql_sampler.notice_sql("select * from test",
88
+ "Database/test/select",
89
+ nil, 1.5)
90
+ agent.sql_sampler.notice_scope_empty
91
+ agent.send(:harvest_and_send_slowest_sql)
92
+ end
93
+
94
+ $collector.agent_data.each do |req|
95
+ body = $collector.unpack_inner_blobs(req)
96
+ assert_audit_log_contains_object(body, format)
97
+ end
98
+ end
99
+ end
@@ -43,7 +43,7 @@ class MarshalingTest < Test::Unit::TestCase
43
43
 
44
44
  assert_equal(666,
45
45
  $collector.agent_data.select{|x| x.action == 'transaction_sample_data'}[0].body[0])
46
- assert_equal(expected_sample.to_collector_array(marshaller),
46
+ assert_equal(expected_sample.to_collector_array(marshaller.default_encoder),
47
47
  $collector.agent_data.select{|x| x.action == 'transaction_sample_data'}[0].body[1][0])
48
48
  end
49
49
 
@@ -0,0 +1,7 @@
1
+ # don't start the agent
2
+ self.newrelic_gemfile_options=(':require => false')
3
+ gemfile <<-RB
4
+ # stub file system so we can test that newrelic.yml can be loaded from
5
+ # various places.
6
+ gem 'fakefs', :require => 'fakefs/safe'
7
+ RB
@@ -0,0 +1,106 @@
1
+ # Test the logic for loading the newrelic.yml config file.
2
+ #
3
+ # We will look at (in this priority):
4
+ # 1. ENV['NRCONFIG'] (if set)
5
+ # 2. ./config/newrelic.yml
6
+ # 3. ./newrelic.yml
7
+ # 4. ~/.newrelic/newrelic.yml
8
+ # 5. ~/newrelic.yml
9
+ #
10
+ # If this fails the agent will attempt to dial Lew Cirne's cell phone and ask
11
+ # that he verbally describe how it should be configured.
12
+ class ConfigFileLoadingTest < Test::Unit::TestCase
13
+
14
+ def setup
15
+ # While FakeFS stubs out all the File system related libraries (i.e. File,
16
+ # FileUtils, Dir, etc.) It doesn't handle the Logger library that is used
17
+ # to create the agent log file. Therefore we check for the presence of the
18
+ # log directory in the FakeFS, then error when we try to open the file in
19
+ # the Real FS. Set the log file to /dev/null to work around this issue.
20
+ # It's incidental to the functionality being tested.
21
+ #
22
+ # '/dev/null' can be changed to 'stdout' if more debugging output is needed
23
+ # in these tests.
24
+ ENV['NEW_RELIC_LOG'] = '/dev/null'
25
+
26
+ # Figure out where multiverse is in the real file system.
27
+ @cwd = Dir.pwd
28
+ # Use a fake file system so we don't damage the real one.
29
+ FakeFS.activate!
30
+ FakeFS::FileSystem.clear
31
+
32
+ # require the agent after we're in FakeFS
33
+ require 'newrelic_rpm'
34
+
35
+ FileUtils.mkdir_p(@cwd)
36
+ end
37
+
38
+ def teardown
39
+ ENV['NEW_RELIC_LOG'] = nil
40
+ FakeFS.deactivate!
41
+ end
42
+
43
+ def setup_config(path, manual_config_options = {})
44
+ NewRelic::Agent.shutdown
45
+ FileUtils.mkdir_p(File.dirname(path))
46
+ Dir.chdir @cwd
47
+ File.open(path, 'w') do |f|
48
+ f.print <<-YAML
49
+ development:
50
+ foo: "success!!"
51
+ test:
52
+ foo: "success!!"
53
+ bazbangbarn:
54
+ i_am: "bazbangbarn"
55
+ YAML
56
+ end
57
+ NewRelic::Agent.reset_config
58
+ NewRelic::Agent.manual_start(manual_config_options)
59
+ end
60
+
61
+ def assert_config_read_from(path)
62
+ setup_config(path)
63
+ assert NewRelic::Agent.config[:foo] == "success!!", "Failed to read yaml config from #{path.inspect}\n\n#{NewRelic::Agent.config.inspect}"
64
+ end
65
+
66
+ def assert_config_not_read_from(path)
67
+ setup_config(path)
68
+ assert NewRelic::Agent.config[:foo] != "success!!", "Read yaml config from #{path.inspect}\n\n#{NewRelic::Agent.config.inspect}"
69
+ end
70
+
71
+ def test_config_loads_from_config_newrelic_yml
72
+ assert_config_read_from(File.dirname(__FILE__) + "/config/newrelic.yml")
73
+ end
74
+
75
+ def test_config_loads_from_newrelic_yml
76
+ assert_config_read_from(File.dirname(__FILE__) + "/newrelic.yml")
77
+ end
78
+
79
+ def test_config_loads_from_home_newrelic_yml
80
+ assert_config_read_from(ENV['HOME'] + "/newrelic.yml")
81
+ end
82
+
83
+ def test_config_loads_from_home_dot_newrelic_newrelic_yml
84
+ assert_config_read_from(ENV['HOME'] + "/.newrelic/newrelic.yml")
85
+ end
86
+
87
+ def test_config_loads_from_env_NRCONFIG
88
+ ENV["NRCONFIG"] = "/tmp/foo/bar.yml"
89
+ assert_config_read_from("/tmp/foo/bar.yml")
90
+ ensure
91
+ ENV["NRCONFIG"] = nil
92
+ end
93
+
94
+ def test_config_isnt_loaded_from_somewhere_crazy
95
+ assert_config_not_read_from(File.dirname(__FILE__) + "/somewhere/crazy/newrelic.yml")
96
+ end
97
+
98
+ def test_config_will_load_settings_for_environment_passed_manual_start
99
+ path = File.dirname(__FILE__) + "/config/newrelic.yml"
100
+
101
+ # pass an env key to NewRelic::Agent.manual_start which should cause it to
102
+ # load that section of newrelic.yml
103
+ setup_config(path, {:env => 'bazbangbarn'} )
104
+ assert_equal 'bazbangbarn', NewRelic::Agent.config[:i_am], "Agent.config did not load bazbangbarn config as requested"
105
+ end
106
+ end