ghazel-newrelic_rpm 3.1.0.1 → 3.4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/CHANGELOG +120 -35
  2. data/LICENSE +29 -2
  3. data/README.rdoc +2 -2
  4. data/bin/mongrel_rpm +0 -0
  5. data/bin/newrelic +0 -0
  6. data/bin/newrelic_cmd +0 -0
  7. data/lib/new_relic/agent.rb +50 -38
  8. data/lib/new_relic/agent/agent.rb +459 -337
  9. data/lib/new_relic/agent/beacon_configuration.rb +71 -11
  10. data/lib/new_relic/agent/browser_monitoring.rb +73 -14
  11. data/lib/new_relic/agent/busy_calculator.rb +11 -3
  12. data/lib/new_relic/agent/chained_call.rb +2 -2
  13. data/lib/new_relic/agent/database.rb +223 -0
  14. data/lib/new_relic/agent/error_collector.rb +231 -183
  15. data/lib/new_relic/agent/instrumentation.rb +2 -2
  16. data/lib/new_relic/agent/instrumentation/active_merchant.rb +10 -2
  17. data/lib/new_relic/agent/instrumentation/active_record.rb +138 -0
  18. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +7 -1
  19. data/lib/new_relic/agent/instrumentation/authlogic.rb +6 -0
  20. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +46 -14
  21. data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -2
  22. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +11 -3
  23. data/lib/new_relic/agent/instrumentation/memcache.rb +49 -25
  24. data/lib/new_relic/agent/instrumentation/merb/controller.rb +7 -2
  25. data/lib/new_relic/agent/instrumentation/merb/errors.rb +7 -1
  26. data/lib/new_relic/agent/instrumentation/metric_frame.rb +31 -4
  27. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -5
  28. data/lib/new_relic/agent/instrumentation/net.rb +8 -2
  29. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -2
  30. data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +66 -35
  32. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +7 -1
  33. data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -1
  34. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +121 -1
  35. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +7 -1
  36. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +21 -0
  37. data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
  38. data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -20
  39. data/lib/new_relic/agent/instrumentation/sunspot.rb +6 -0
  40. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +7 -2
  41. data/lib/new_relic/agent/method_tracer.rb +205 -99
  42. data/lib/new_relic/agent/new_relic_service.rb +221 -0
  43. data/lib/new_relic/agent/pipe_channel_manager.rb +161 -0
  44. data/lib/new_relic/agent/pipe_service.rb +54 -0
  45. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +89 -0
  46. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -7
  47. data/lib/new_relic/agent/shim_agent.rb +5 -5
  48. data/lib/new_relic/agent/sql_sampler.rb +282 -0
  49. data/lib/new_relic/agent/stats_engine.rb +2 -0
  50. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  51. data/lib/new_relic/agent/stats_engine/metric_stats.rb +35 -30
  52. data/lib/new_relic/agent/stats_engine/samplers.rb +10 -4
  53. data/lib/new_relic/agent/stats_engine/transactions.rb +28 -87
  54. data/lib/new_relic/agent/transaction_info.rb +74 -0
  55. data/lib/new_relic/agent/transaction_sample_builder.rb +18 -3
  56. data/lib/new_relic/agent/transaction_sampler.rb +108 -20
  57. data/lib/new_relic/agent/worker_loop.rb +14 -6
  58. data/lib/new_relic/collection_helper.rb +19 -11
  59. data/lib/new_relic/command.rb +1 -1
  60. data/lib/new_relic/commands/deployments.rb +2 -2
  61. data/lib/new_relic/commands/install.rb +2 -13
  62. data/lib/new_relic/control.rb +2 -3
  63. data/lib/new_relic/control/class_methods.rb +12 -6
  64. data/lib/new_relic/control/configuration.rb +57 -8
  65. data/lib/new_relic/control/frameworks.rb +10 -0
  66. data/lib/new_relic/control/frameworks/external.rb +4 -4
  67. data/lib/new_relic/control/frameworks/merb.rb +2 -1
  68. data/lib/new_relic/control/frameworks/rails.rb +35 -22
  69. data/lib/new_relic/control/frameworks/rails3.rb +12 -7
  70. data/lib/new_relic/control/frameworks/ruby.rb +5 -5
  71. data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
  72. data/lib/new_relic/control/instance_methods.rb +38 -12
  73. data/lib/new_relic/control/instrumentation.rb +23 -4
  74. data/lib/new_relic/control/logging_methods.rb +70 -15
  75. data/lib/new_relic/control/server_methods.rb +22 -9
  76. data/lib/new_relic/delayed_job_injection.rb +16 -3
  77. data/lib/new_relic/helper.rb +21 -0
  78. data/lib/new_relic/language_support.rb +95 -0
  79. data/lib/new_relic/local_environment.rb +92 -48
  80. data/lib/new_relic/metric_data.rb +7 -2
  81. data/lib/new_relic/metric_spec.rb +12 -9
  82. data/lib/new_relic/noticed_error.rb +6 -1
  83. data/lib/new_relic/rack/browser_monitoring.rb +18 -19
  84. data/lib/new_relic/rack/developer_mode.rb +3 -2
  85. data/lib/new_relic/recipes.rb +8 -4
  86. data/lib/new_relic/stats.rb +17 -60
  87. data/lib/new_relic/transaction_analysis.rb +2 -1
  88. data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
  89. data/lib/new_relic/transaction_sample.rb +60 -75
  90. data/lib/new_relic/transaction_sample/segment.rb +31 -79
  91. data/lib/new_relic/version.rb +2 -2
  92. data/lib/newrelic_rpm.rb +1 -1
  93. data/newrelic.yml +2 -2
  94. data/newrelic_rpm.gemspec +46 -54
  95. data/test/active_record_fixtures.rb +3 -3
  96. data/test/config/newrelic.yml +1 -1
  97. data/test/fixtures/proc_cpuinfo.txt +575 -0
  98. data/test/new_relic/agent/agent/connect_test.rb +128 -25
  99. data/test/new_relic/agent/agent/start_test.rb +9 -94
  100. data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -4
  101. data/test/new_relic/agent/agent_test.rb +51 -78
  102. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  103. data/test/new_relic/agent/agent_test_controller_test.rb +49 -33
  104. data/test/new_relic/agent/beacon_configuration_test.rb +12 -5
  105. data/test/new_relic/agent/browser_monitoring_test.rb +99 -50
  106. data/test/new_relic/agent/database_test.rb +161 -0
  107. data/test/new_relic/agent/error_collector_test.rb +47 -23
  108. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +96 -42
  109. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
  110. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
  111. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -11
  112. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +9 -9
  113. data/test/new_relic/agent/instrumentation/queue_time_test.rb +6 -11
  114. data/test/new_relic/agent/memcache_instrumentation_test.rb +54 -18
  115. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
  116. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  117. data/test/new_relic/agent/method_tracer_test.rb +3 -2
  118. data/test/new_relic/agent/new_relic_service_test.rb +151 -0
  119. data/test/new_relic/agent/pipe_channel_manager_test.rb +114 -0
  120. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  121. data/test/new_relic/agent/rpm_agent_test.rb +4 -31
  122. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  123. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +19 -18
  124. data/test/new_relic/agent/stats_engine_test.rb +41 -6
  125. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  126. data/test/new_relic/agent/transaction_sample_builder_test.rb +27 -4
  127. data/test/new_relic/agent/transaction_sampler_test.rb +68 -46
  128. data/test/new_relic/agent/worker_loop_test.rb +3 -3
  129. data/test/new_relic/agent_test.rb +242 -0
  130. data/test/new_relic/collection_helper_test.rb +50 -28
  131. data/test/new_relic/control/configuration_test.rb +77 -0
  132. data/test/new_relic/control/logging_methods_test.rb +49 -21
  133. data/test/new_relic/control_test.rb +115 -54
  134. data/test/new_relic/delayed_job_injection_test.rb +21 -0
  135. data/test/new_relic/fake_collector.rb +210 -0
  136. data/test/new_relic/fake_service.rb +44 -0
  137. data/test/new_relic/local_environment_test.rb +14 -1
  138. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  139. data/test/new_relic/rack/browser_monitoring_test.rb +84 -23
  140. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  141. data/test/new_relic/rack/developer_mode_test.rb +31 -0
  142. data/test/new_relic/stats_test.rb +3 -18
  143. data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
  144. data/test/new_relic/transaction_analysis_test.rb +3 -3
  145. data/test/new_relic/transaction_sample/segment_test.rb +15 -80
  146. data/test/new_relic/transaction_sample_test.rb +25 -18
  147. data/test/script/build_test_gem.sh +51 -0
  148. data/test/script/ci.sh +140 -0
  149. data/test/script/ci_agent-tests_runner.sh +82 -0
  150. data/test/script/ci_bench.sh +52 -0
  151. data/test/script/ci_multiverse_runner.sh +63 -0
  152. data/test/test_contexts.rb +1 -0
  153. data/test/test_helper.rb +18 -5
  154. data/ui/helpers/developer_mode_helper.rb +14 -8
  155. data/ui/helpers/google_pie_chart.rb +0 -1
  156. data/ui/views/newrelic/index.rhtml +2 -2
  157. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
  158. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +10 -0
  159. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
  160. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +17 -4
  161. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
  162. metadata +50 -36
  163. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +0 -108
  164. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +0 -112
  165. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  166. data/lib/new_relic/data_serialization.rb +0 -84
  167. data/lib/new_relic/histogram.rb +0 -91
  168. data/lib/new_relic/rack/metric_app.rb +0 -65
  169. data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
  170. data/lib/new_relic/rack/newrelic.yml +0 -27
  171. data/lib/new_relic/rack_app.rb +0 -6
  172. data/test/new_relic/data_serialization_test.rb +0 -70
  173. data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
  174. data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
  175. data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
@@ -1,40 +0,0 @@
1
- require 'new_relic/agent/sampler'
2
- require 'new_relic/delayed_job_injection'
3
-
4
- module NewRelic
5
- module Agent
6
- module Samplers
7
- class DelayedJobLockSampler < NewRelic::Agent::Sampler
8
- def initialize
9
- super :delayed_job_lock
10
- raise Unsupported, "DJ instrumentation disabled" if NewRelic::Control.instance['disable_dj']
11
- raise Unsupported, "No DJ worker present" unless NewRelic::DelayedJobInjection.worker_name
12
- end
13
-
14
- def stats
15
- stats_engine.get_stats("Custom/DJ Locked Jobs", false)
16
- end
17
-
18
- def local_env
19
- NewRelic::Control.instance.local_env
20
- end
21
-
22
- def worker_name
23
- local_env.dispatcher_instance_id
24
- end
25
-
26
- def locked_jobs
27
- Delayed::Job.count(:conditions => {:locked_by => NewRelic::DelayedJobInjection.worker_name})
28
- end
29
-
30
- def self.supported_on_this_platform?
31
- defined?(Delayed::Job)
32
- end
33
-
34
- def poll
35
- stats.record_data_point locked_jobs
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,84 +0,0 @@
1
- require 'fileutils'
2
- module NewRelic
3
- class DataSerialization
4
- module ClassMethods
5
- def should_send_data?
6
- NewRelic::Control.instance.disable_serialization? || (File.size(file_path) >= max_size)
7
- rescue Exception => e
8
- # This is not what we really should do here, but the fail-safe
9
- # behavior is to do what the older agent did: send data every
10
- # time we think we might want to send data.
11
- true
12
- end
13
-
14
- def read_and_write_to_file
15
- with_locked_store do |f|
16
- result = (yield get_data_from_file(f))
17
- f.rewind
18
- f.write(dump(result)) if result
19
- end
20
- end
21
-
22
- private
23
-
24
- def open_arguments
25
- if defined?(Encoding)
26
- [file_path, File::RDWR | File::CREAT, {:internal_encoding => nil}]
27
- else
28
- [file_path, File::RDWR | File::CREAT]
29
- end
30
- end
31
-
32
- def with_locked_store
33
- File.open(*open_arguments) do |f|
34
- f.flock(File::LOCK_EX)
35
- begin
36
- yield(f)
37
- ensure
38
- f.flock(File::LOCK_UN)
39
- end
40
- end
41
- rescue Exception => e
42
- NewRelic::Control.instance.log.error("Error serializing data to disk: #{e.inspect}")
43
- NewRelic::Control.instance.log.debug(e.backtrace.split("\n"))
44
- end
45
-
46
- def get_data_from_file(f)
47
- data = f.read
48
- result = load(data)
49
- f.truncate(0)
50
- result
51
- end
52
-
53
- def max_size
54
- 10_000
55
- end
56
-
57
- def create_file_if_needed
58
- FileUtils.touch(file_path) unless File.exists?(file_path)
59
- end
60
-
61
- def dump(object)
62
- Marshal.dump(object)
63
- end
64
-
65
- def load(dump)
66
- Marshal.load(dump)
67
- rescue ArgumentError => e
68
- nil
69
- end
70
-
71
- def truncate_file
72
- create_file_if_needed
73
- File.truncate(file_path, 0)
74
- end
75
-
76
- def file_path
77
- # TODO get configuration from main control
78
- './log/newrelic_agent_store.db'
79
- end
80
- end
81
- extend ClassMethods
82
- end
83
- end
84
-
@@ -1,91 +0,0 @@
1
- # Histogram is used for organizing response times
2
- # into an 'Exponential Histogram'. Feature based in part on DHH proposal:
3
- # http://37signals.com/svn/posts/1836-the-problem-with-averages
4
- #
5
- # Histogram builds a set of buckets of geometrically growing size, with the assumption that most
6
- # apps have long-tail response times, and therefore you need the most granularity at the lowest
7
- # r/t level.
8
- module NewRelic
9
- class Histogram
10
-
11
- # Used to stub out API methods when the agent is not enabled
12
- module Shim
13
- def process(response_time); end
14
- end
15
- # Stores statistics for response times falling in a particular range.
16
- # A bucket has a min and max response time. A response time event
17
- # falls in a bucket if min <= r/t < max. A bucket also
18
- # has an associated metric for reporting data to New Relic. The
19
- # bucket range is encoded in the metic name
20
- class Bucket
21
-
22
- attr_reader :min, :max, :stats
23
-
24
- def initialize(min, max = nil)
25
- @min = min
26
- @max = max
27
- end
28
-
29
- def stats
30
- NewRelic::Agent.get_stats("Response Times/#{min_millis}/#{max_millis}")
31
- end
32
-
33
- # This has return value like <=> but does something more
34
- # than simply compare. If the value falls within range for
35
- # the bucket, increment count and return 0; otherwise return
36
- # a value < 0 if the value belongs in a bucket with a lower range
37
- # you can guess what it returns if the value belongs in a bucket
38
- # with a higher range. (Hint: it's not 0, and it's not less than zero.)
39
- def process(value)
40
- if value < min
41
- return -1
42
-
43
- # max == nil means unlimited max (last bucket)
44
- elsif max && value >= max
45
- return 1
46
-
47
- else
48
- stats.record_data_point(value)
49
- return 0
50
- end
51
- end
52
-
53
- def min_millis
54
- (min * 1000).round
55
- end
56
-
57
- def max_millis
58
- max.nil? ? nil : (max * 1000).round
59
- end
60
-
61
- def to_s
62
- "#{min_millis} - #{max_millis}: #{stats.call_count}"
63
- end
64
- end
65
-
66
- attr_reader :buckets
67
-
68
- # Histogram uses apdex T / 10 as its minimum bucket size, and grows from there.
69
- # 30 data points should be adequate resolution.
70
- def initialize(first_bucket_max = 0.010, bucket_count = 30, multiplier = 1.3)
71
- @buckets = []
72
-
73
- min = 0
74
- max = first_bucket_max
75
-
76
- (bucket_count - 1).times do
77
- @buckets << Bucket.new(min, max)
78
- min = max
79
- max *= multiplier
80
- end
81
- @buckets << Bucket.new(max)
82
- end
83
-
84
- def process(response_time)
85
- buckets.each do |bucket|
86
- found = bucket.process(response_time)
87
- return if found == 0
88
- end
89
- end
90
- end
91
- end
@@ -1,65 +0,0 @@
1
- require 'fileutils'
2
- module NewRelic
3
- module Rack
4
- class MetricApp
5
- def initialize(options)
6
- if options[:install]
7
- src = File.join(File.dirname(__FILE__), "newrelic.yml")
8
- require 'new_relic/command'
9
- begin
10
- NewRelic::Command::Install.new(:quiet => true, :src_file => src).run
11
- NewRelic::Agent.logger.info "A newrelic.yml template was copied to #{File.expand_path('.')}."
12
- NewRelic::Agent.logger.info "Please add a license key to the file and restart #{$0}"
13
- exit 0
14
- rescue NewRelic::Command::CommandFailure => e
15
- NewRelic::Agent.logger.error e.message
16
- exit 1
17
- end
18
- end
19
- options[:app_name] ||= 'EPM Monitor'
20
- options[:disable_samplers] = true
21
- NewRelic::Agent.manual_start options
22
- NewRelic::Agent.logger.warn "This rack app is deprecated - it will be removed in the next version of the Ruby Agent"
23
- unless NewRelic::Control.instance.license_key
24
- raise "Please add a valid license key to newrelic.yml."
25
- end
26
- end
27
- def call(env)
28
- request = ::Rack::Request.new env
29
- params = request.params
30
- if !(params['uri'] || params['metric'])
31
- [400, { 'Content-Type' => 'text/plain' }, "Missing 'uri' or 'metric' parameter: #{params.inspect}" ]
32
- elsif !params['value']
33
- [400, { 'Content-Type' => 'text/plain' }, "Missing 'value' parameter: #{params.inspect}" ]
34
- else
35
- NewRelic::Agent.record_transaction( params['value'].to_f, params )
36
- ::Rack::Response.new(params.collect { |k, v| "#{k}=#{v} " }.join).finish
37
- end
38
- end
39
- end
40
- class Status
41
- def call(env)
42
- request = ::Rack::Request.new env
43
- data_url = "http://#{env['HTTP_HOST']}/metrics/path?value=nnn"
44
- body = StringIO.new
45
- body.puts "<html><body>"
46
- body.puts "<h1>New Relic Actively Monitoring #{NewRelic::Control.instance.app_names.join(' and ')}</h1>"
47
- body.puts "<p>To submit a metric value, use <a href='#{data_url}'>#{data_url}</a></p>"
48
- body.puts "<h2>Request Details</h2>"
49
- body.puts "<dl>"
50
- body.puts "<dt>ip<dd>#{request.ip}"
51
- body.puts "<dt>host<dd>#{request.host}"
52
- body.puts "<dt>path<dd>#{request.url}"
53
- body.puts "<dt>query<dd>#{request.query_string}"
54
- body.puts "<dt>params<dd>#{request.params.inspect}"
55
- body.puts "</dl>"
56
- body.puts "<h2>Complete ENV</h2>"
57
- body.puts "<ul>"
58
- body.puts env.to_a.map{|k,v| "<li>#{k} = #{v}</li>" }.join("\n")
59
- body.puts "</ul></body></html>"
60
- response = ::Rack::Response.new body.string
61
- response.finish
62
- end
63
- end
64
- end
65
- end
@@ -1,28 +0,0 @@
1
- # This is so that we don't detect a dispatcher like mongrel and think we are
2
- # monitoring it.
3
- ENV['NEWRELIC_DISPATCHER'] = 'none'
4
-
5
- $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..','..'))
6
-
7
- require 'new_relic/rack_app'
8
-
9
- # Valid options which may be present in this binding:
10
- # :license_key optional license key override
11
- # :app_name optional name of app
12
- # :logging optional, false to omit request logging to stdout
13
-
14
- # use Rack::CommonLogger unless options[:logging] == false
15
- # use Rack::ShowExceptions
16
- # use Rack::Reloader if ENV['RACK_ENV'] == 'development'
17
-
18
- puts "This Rack Metric Collection system is deprecated - it will be removed in the next version of the Ruby Agent"
19
-
20
- map "/newrelic/record_value" do
21
- run NewRelic::Rack::MetricApp.new(options)
22
- end
23
-
24
- map "/" do
25
- run NewRelic::Rack::Status.new
26
- end
27
-
28
-
@@ -1,27 +0,0 @@
1
- #
2
- # This file configures the Rack NewRelic Metric Application. Place a copy of this file
3
- # in the directory where you start the mongrel_rpm process.
4
- #
5
- # <%= generated_for_user %>
6
- #
7
- common: &default_settings
8
- log_level: info
9
- enabled: true
10
-
11
- # This is the key generated by script/create_admin
12
- license_key: '<%= license_key %>'
13
-
14
- # Replace this with the name of the application feeding
15
- # metrics into the Metric application;
16
- app_name: Application Monitor
17
-
18
- # Set RACK_ENV to one of the following:
19
-
20
- production:
21
- <<: *default_settings
22
- app_name: Production Monitor
23
-
24
- staging:
25
- <<: *default_settings
26
- app_name: Staging Monitor
27
-
@@ -1,6 +0,0 @@
1
- require 'rack/response'
2
- require 'newrelic_rpm'
3
-
4
- # Rack middlewares and applications used by New Relic
5
- require 'new_relic/rack/metric_app'
6
- require 'new_relic/rack/developer_mode'
@@ -1,70 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
- require 'new_relic/data_serialization'
3
- class NewRelic::DataSerializationTest < Test::Unit::TestCase
4
- def test_read_and_write_from_file_read_only
5
- file = './log/newrelic_agent_store.db'
6
- File.open(file, 'w') do |f|
7
- f.write(Marshal.dump('a happy string'))
8
- end
9
- NewRelic::DataSerialization.read_and_write_to_file do |data|
10
- assert_equal('a happy string', data, "should pull the dumped item from the file")
11
- nil # must explicitly return nil or the return value will be dumped
12
- end
13
- assert_equal(0, File.size(file), "Should not leave any data in the file")
14
- end
15
-
16
- def test_read_and_write_to_file_dumping_contents
17
- file = './log/newrelic_agent_store.db'
18
- expected_contents = Marshal.dump('a happy string')
19
- NewRelic::DataSerialization.read_and_write_to_file do
20
- 'a happy string'
21
- end
22
- assert_equal(expected_contents, File.read(file), "should have dumped the contents")
23
- end
24
-
25
- def test_read_and_write_to_file_yields_old_data
26
- file = './log/newrelic_agent_store.db'
27
- expected_contents = 'a happy string'
28
- File.open(file, 'w') do |f|
29
- f.write(Marshal.dump(expected_contents))
30
- end
31
- contents = nil
32
- NewRelic::DataSerialization.read_and_write_to_file do |old_data|
33
- contents = old_data
34
- 'a happy string'
35
- end
36
- assert_equal(contents, expected_contents, "should have dumped the contents")
37
- end
38
-
39
- def test_read_and_write_to_file_round_trip
40
- old_data = nil
41
- NewRelic::DataSerialization.read_and_write_to_file do |data|
42
- old_data = data
43
- 'a' * 30
44
- end
45
- NewRelic::DataSerialization.read_and_write_to_file do |data|
46
- assert_equal('a'*30, data, "should be the same after serialization")
47
- end
48
- end
49
-
50
- def test_should_send_data
51
- NewRelic::DataSerialization.expects(:max_size).returns(20)
52
- NewRelic::DataSerialization.read_and_write_to_file do
53
- "a" * 30
54
- end
55
- assert(NewRelic::DataSerialization.should_send_data?, 'Should be over limit')
56
- end
57
-
58
- def test_should_send_data_disabled
59
- NewRelic::Control.instance.expects(:disable_serialization?).returns(true)
60
- assert(NewRelic::DataSerialization.should_send_data?, 'should send data when disabled')
61
- end
62
-
63
- def test_should_send_data_under_limit
64
- NewRelic::DataSerialization.expects(:max_size).returns(50)
65
- NewRelic::DataSerialization.read_and_write_to_file do
66
- "a" * 5
67
- end
68
- assert(!NewRelic::DataSerialization.should_send_data?, 'Should be under the limit')
69
- end
70
- end
File without changes
File without changes
File without changes