newrelic_rpm 2.8.11 → 2.9.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +267 -0
- data/LICENSE +1 -1
- data/Manifest +142 -0
- data/README.md +138 -0
- data/Rakefile +10 -28
- data/bin/mongrel_rpm +33 -0
- data/cert/cacert.pem +34 -0
- data/init.rb +38 -0
- data/lib/new_relic/agent/agent.rb +160 -347
- data/lib/new_relic/agent/collection_helper.rb +13 -24
- data/lib/new_relic/agent/error_collector.rb +29 -15
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +63 -76
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +90 -48
- data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +72 -47
- data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +14 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +10 -1
- data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +5 -7
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +3 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +7 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +34 -7
- data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +20 -12
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -4
- data/lib/new_relic/agent/method_tracer.rb +159 -135
- data/lib/new_relic/agent/patch_const_missing.rb +46 -26
- data/lib/new_relic/agent/sampler.rb +12 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +44 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +126 -0
- data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
- data/lib/new_relic/agent/shim_agent.rb +11 -0
- data/lib/new_relic/agent/stats_engine.rb +85 -46
- data/lib/new_relic/agent/transaction_sampler.rb +63 -38
- data/lib/new_relic/agent/worker_loop.rb +8 -18
- data/lib/new_relic/agent.rb +200 -25
- data/lib/new_relic/commands/deployments.rb +9 -9
- data/lib/new_relic/control/merb.rb +22 -0
- data/lib/new_relic/control/rails.rb +141 -0
- data/lib/new_relic/{config → control}/ruby.rb +13 -2
- data/lib/new_relic/control.rb +424 -0
- data/lib/new_relic/local_environment.rb +201 -79
- data/lib/new_relic/metric_data.rb +7 -0
- data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
- data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
- data/lib/new_relic/metric_parser/active_record.rb +11 -0
- data/lib/new_relic/metric_parser/controller.rb +51 -0
- data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
- data/lib/new_relic/metric_parser/database.rb +23 -0
- data/lib/new_relic/metric_parser/errors.rb +6 -0
- data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
- data/lib/new_relic/metric_parser/view.rb +61 -0
- data/lib/new_relic/metric_parser/web_service.rb +9 -0
- data/lib/new_relic/metric_parser.rb +107 -0
- data/lib/new_relic/metric_spec.rb +5 -0
- data/lib/new_relic/noticed_error.rb +5 -1
- data/lib/new_relic/rack/metric_app.rb +57 -0
- data/lib/new_relic/rack/newrelic.ru +25 -0
- data/lib/new_relic/rack/newrelic.yml +25 -0
- data/lib/new_relic/rack.rb +5 -0
- data/lib/new_relic/recipes.rb +10 -3
- data/lib/new_relic/stats.rb +130 -144
- data/lib/new_relic/transaction_analysis.rb +7 -8
- data/lib/new_relic/transaction_sample.rb +86 -10
- data/lib/new_relic/version.rb +41 -160
- data/lib/new_relic_api.rb +7 -6
- data/lib/newrelic_rpm.rb +30 -17
- data/lib/tasks/{agent_tests.rake → tests.rake} +1 -1
- data/newrelic.yml +115 -62
- data/newrelic_rpm.gemspec +36 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +21 -3
- data/test/config/{test_config.rb → test_control.rb} +14 -10
- data/test/new_relic/agent/active_record_instrumentation_test.rb +189 -0
- data/test/new_relic/agent/agent_test.rb +104 -0
- data/test/new_relic/agent/agent_test_controller.rb +18 -1
- data/test/new_relic/agent/classloader_patch_test.rb +56 -0
- data/test/new_relic/agent/{tc_collection_helper.rb → collection_helper_test.rb} +28 -23
- data/test/new_relic/agent/controller_test.rb +107 -0
- data/test/new_relic/agent/dispatcher_instrumentation_test.rb +70 -0
- data/test/new_relic/agent/error_collector_test.rb +155 -0
- data/test/new_relic/agent/{tc_method_tracer.rb → method_tracer_test.rb} +6 -12
- data/test/new_relic/agent/metric_data_test.rb +56 -0
- data/test/new_relic/agent/stats_engine_test.rb +266 -0
- data/test/new_relic/agent/{tc_transaction_sample_builder.rb → transaction_sample_builder_test.rb} +6 -5
- data/test/new_relic/agent/{tc_transaction_sample.rb → transaction_sample_test.rb} +9 -13
- data/test/new_relic/agent/transaction_sampler_test.rb +317 -0
- data/test/new_relic/agent/{tc_worker_loop.rb → worker_loop_test.rb} +1 -1
- data/test/new_relic/control_test.rb +97 -0
- data/test/new_relic/{tc_deployments_api.rb → deployments_api_test.rb} +8 -4
- data/test/new_relic/environment_test.rb +75 -0
- data/test/new_relic/metric_parser_test.rb +142 -0
- data/test/new_relic/{tc_metric_spec.rb → metric_spec_test.rb} +28 -1
- data/test/new_relic/samplers_test.rb +71 -0
- data/test/new_relic/{tc_shim_agent.rb → shim_agent_test.rb} +1 -1
- data/test/new_relic/stats_test.rb +291 -0
- data/test/new_relic/version_number_test.rb +46 -0
- data/test/test_helper.rb +7 -30
- data/test/ui/newrelic_controller_test.rb +14 -0
- data/test/ui/{tc_newrelic_helper.rb → newrelic_helper_test.rb} +16 -7
- data/ui/controllers/newrelic_controller.rb +17 -3
- data/ui/helpers/newrelic_helper.rb +44 -15
- data/ui/views/layouts/newrelic_default.rhtml +7 -8
- data/ui/views/newrelic/_sample.rhtml +5 -2
- data/ui/views/newrelic/_segment.rhtml +1 -1
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +4 -4
- data/ui/views/newrelic/_show_sample_detail.rhtml +3 -1
- data/ui/views/newrelic/_show_sample_sql.rhtml +2 -1
- data/ui/views/newrelic/explain_sql.rhtml +2 -5
- data/ui/views/newrelic/images/file_icon.png +0 -0
- data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/index.rhtml +21 -13
- data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
- data/ui/views/newrelic/show_sample.rhtml +18 -3
- data/ui/views/newrelic/stylesheets/style.css +39 -0
- data/ui/views/newrelic/threads.rhtml +52 -0
- metadata +192 -70
- data/README +0 -136
- data/lib/new_relic/agent/instrumentation/rails/rails.rb +0 -6
- data/lib/new_relic/agent/samplers/cpu.rb +0 -29
- data/lib/new_relic/agent/samplers/memory.rb +0 -53
- data/lib/new_relic/agent/samplers/mongrel.rb +0 -26
- data/lib/new_relic/agent/synchronize.rb +0 -40
- data/lib/new_relic/config/merb.rb +0 -35
- data/lib/new_relic/config/rails.rb +0 -114
- data/lib/new_relic/config.rb +0 -279
- data/lib/new_relic/shim_agent.rb +0 -96
- data/test/new_relic/agent/model_fixture.rb +0 -15
- data/test/new_relic/agent/tc_active_record.rb +0 -90
- data/test/new_relic/agent/tc_agent.rb +0 -148
- data/test/new_relic/agent/tc_controller.rb +0 -77
- data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +0 -52
- data/test/new_relic/agent/tc_error_collector.rb +0 -127
- data/test/new_relic/agent/tc_stats_engine.rb +0 -218
- data/test/new_relic/agent/tc_synchronize.rb +0 -37
- data/test/new_relic/agent/tc_transaction_sampler.rb +0 -302
- data/test/new_relic/tc_config.rb +0 -36
- data/test/new_relic/tc_environment.rb +0 -94
- data/test/new_relic/tc_stats.rb +0 -141
data/lib/new_relic/config.rb
DELETED
@@ -1,279 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'new_relic/local_environment'
|
3
|
-
require 'singleton'
|
4
|
-
require 'erb'
|
5
|
-
require 'net/https'
|
6
|
-
require 'logger'
|
7
|
-
|
8
|
-
# Configuration supports the behavior of the agent which is dependent
|
9
|
-
# on what environment is being monitored: rails, merb, ruby, etc
|
10
|
-
# It is an abstract factory with concrete implementations under
|
11
|
-
# the config folder.
|
12
|
-
module NewRelic
|
13
|
-
|
14
|
-
class Config
|
15
|
-
|
16
|
-
attr_accessor :log_file, :env
|
17
|
-
|
18
|
-
# Structs holding info for the remote server and proxy server
|
19
|
-
class Server < Struct.new :host, :port
|
20
|
-
def to_s; "#{host}:#{port}"; end
|
21
|
-
end
|
22
|
-
|
23
|
-
ProxyServer = Struct.new :host, :port, :user, :password
|
24
|
-
|
25
|
-
def self.instance
|
26
|
-
@instance ||= new_instance
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@settings = nil
|
32
|
-
|
33
|
-
# Initialize the agent: install instrumentation and start the agent if
|
34
|
-
# appropriate. Subclasses may have different arguments for this when
|
35
|
-
# they are being called from different locations.
|
36
|
-
def start_plugin(*args)
|
37
|
-
if tracers_enabled?
|
38
|
-
start_agent
|
39
|
-
else
|
40
|
-
require 'new_relic/shim_agent'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Get the app config info. It should already have been collected but
|
45
|
-
# if not we will memoize it to be safe.
|
46
|
-
def app_config_info
|
47
|
-
@app_config_info ||= gather_info
|
48
|
-
end
|
49
|
-
|
50
|
-
def [](key)
|
51
|
-
fetch(key)
|
52
|
-
end
|
53
|
-
####################################
|
54
|
-
def settings
|
55
|
-
if @settings.nil?
|
56
|
-
@settings = (@yaml && @yaml[env]) || {}
|
57
|
-
@settings['apdex_t'] ||= 1.0
|
58
|
-
end
|
59
|
-
@settings
|
60
|
-
end
|
61
|
-
|
62
|
-
def []=(key, value)
|
63
|
-
settings[key] = value
|
64
|
-
end
|
65
|
-
|
66
|
-
def set_config(key,value)
|
67
|
-
self[key]=value
|
68
|
-
end
|
69
|
-
|
70
|
-
def fetch(key, default=nil)
|
71
|
-
settings[key].nil? ? default : settings[key]
|
72
|
-
end
|
73
|
-
|
74
|
-
###################################
|
75
|
-
# Agent config conveniences
|
76
|
-
|
77
|
-
def newrelic_root
|
78
|
-
File.expand_path(File.join(__FILE__, "..","..",".."))
|
79
|
-
end
|
80
|
-
def connect_to_server?
|
81
|
-
fetch('enabled', nil)
|
82
|
-
end
|
83
|
-
def developer_mode?
|
84
|
-
fetch('developer', nil)
|
85
|
-
end
|
86
|
-
def tracers_enabled?
|
87
|
-
!(ENV['NEWRELIC_ENABLE'].to_s =~ /false|off|no/i) &&
|
88
|
-
(developer_mode? || connect_to_server?)
|
89
|
-
end
|
90
|
-
def app_name
|
91
|
-
fetch('app_name', nil)
|
92
|
-
end
|
93
|
-
|
94
|
-
def use_ssl?
|
95
|
-
@use_ssl ||= fetch('ssl', false)
|
96
|
-
end
|
97
|
-
|
98
|
-
def server
|
99
|
-
@remote_server ||=
|
100
|
-
NewRelic::Config::Server.new convert_to_ip_address(fetch('host', 'collector.newrelic.com')), fetch('port', use_ssl? ? 443 : 80).to_i
|
101
|
-
end
|
102
|
-
|
103
|
-
def api_server
|
104
|
-
@api_server ||=
|
105
|
-
NewRelic::Config::Server.new fetch('api_host', 'rpm.newrelic.com'), fetch('api_port', fetch('port', use_ssl? ? 443 : 80)).to_i
|
106
|
-
end
|
107
|
-
|
108
|
-
def proxy_server
|
109
|
-
@proxy_server ||=
|
110
|
-
NewRelic::Config::ProxyServer.new convert_to_ip_address(fetch('proxy_host', nil)), fetch('proxy_port', nil),
|
111
|
-
fetch('proxy_user', nil), fetch('proxy_pass', nil)
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
# Return the Net::HTTP with proxy configuration given the NewRelic::Config::Server object.
|
116
|
-
# Default is the collector but for api calls you need to pass api_server
|
117
|
-
def http_connection(host = server)
|
118
|
-
# Proxy returns regular HTTP if @proxy_host is nil (the default)
|
119
|
-
http = Net::HTTP::Proxy(proxy_server.host, proxy_server.port,
|
120
|
-
proxy_server.user, proxy_server.password).new(host.host, host.port)
|
121
|
-
if use_ssl?
|
122
|
-
http.use_ssl = true
|
123
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
124
|
-
end
|
125
|
-
http
|
126
|
-
end
|
127
|
-
|
128
|
-
def to_s
|
129
|
-
puts self.inspect
|
130
|
-
"Config[#{self.app}]"
|
131
|
-
end
|
132
|
-
|
133
|
-
def log
|
134
|
-
# If we try to get a log before one has been set up, return a stdout log
|
135
|
-
unless @log
|
136
|
-
@log = Logger.new(STDOUT)
|
137
|
-
@log.level = Logger::WARN
|
138
|
-
end
|
139
|
-
@log
|
140
|
-
end
|
141
|
-
|
142
|
-
def setup_log(identifier)
|
143
|
-
@log_file = "#{log_path}/#{log_file_name(identifier)}"
|
144
|
-
@log = Logger.new @log_file
|
145
|
-
|
146
|
-
# change the format just for our logger
|
147
|
-
|
148
|
-
def @log.format_message(severity, timestamp, progname, msg)
|
149
|
-
"[#{timestamp.strftime("%m/%d/%y %H:%M:%S")} (#{$$})] #{severity} : #{msg}\n"
|
150
|
-
end
|
151
|
-
|
152
|
-
# set the log level as specified in the config file
|
153
|
-
case fetch("log_level","info").downcase
|
154
|
-
when "debug"; @log.level = Logger::DEBUG
|
155
|
-
when "info"; @log.level = Logger::INFO
|
156
|
-
when "warn"; @log.level = Logger::WARN
|
157
|
-
when "error"; @log.level = Logger::ERROR
|
158
|
-
when "fatal"; @log.level = Logger::FATAL
|
159
|
-
else @log.level = Logger::INFO
|
160
|
-
end
|
161
|
-
@log
|
162
|
-
end
|
163
|
-
|
164
|
-
def local_env
|
165
|
-
@local_env ||= NewRelic::LocalEnvironment.new
|
166
|
-
end
|
167
|
-
|
168
|
-
# send the given message to STDERR so that it shows
|
169
|
-
# up in the console. This should be used for important informational messages at boot.
|
170
|
-
# The to_stderr may be implemented differently by different config subclasses.
|
171
|
-
# This will NOT print anything if the environment is unknown because this is
|
172
|
-
# probably not an environment the agent will be running in.
|
173
|
-
def log!(msg, level=:info)
|
174
|
-
return if @settings && !tracers_enabled?
|
175
|
-
to_stderr msg
|
176
|
-
log.send level, msg if log
|
177
|
-
end
|
178
|
-
|
179
|
-
protected
|
180
|
-
|
181
|
-
def convert_to_ip_address(host)
|
182
|
-
return nil unless host
|
183
|
-
if host.downcase == "localhost"
|
184
|
-
ip_address = host
|
185
|
-
else
|
186
|
-
begin
|
187
|
-
ip_address = Resolv.getaddress(host)
|
188
|
-
rescue => e
|
189
|
-
log.debug "DNS Error caching with Resolv: #{e}"
|
190
|
-
begin
|
191
|
-
ip_address = IPSocket::getaddress host
|
192
|
-
rescue => e
|
193
|
-
log.warn "DNS Error looking up IP address: #{e}"
|
194
|
-
raise NewRelic::Agent::IgnoreSilentlyException.new
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
log.info "Resolved #{host} to #{ip_address}"
|
199
|
-
ip_address
|
200
|
-
end
|
201
|
-
|
202
|
-
# Collect miscellaneous interesting info about the environment
|
203
|
-
# Called when the agent is started
|
204
|
-
def gather_info
|
205
|
-
[[:app, app]]
|
206
|
-
end
|
207
|
-
|
208
|
-
def to_stderr(msg)
|
209
|
-
STDERR.puts "** [NewRelic] " + msg
|
210
|
-
end
|
211
|
-
|
212
|
-
def start_agent
|
213
|
-
require 'new_relic/agent.rb'
|
214
|
-
app_config_info
|
215
|
-
NewRelic::Agent::Agent.instance.start(local_env.environment, local_env.identifier)
|
216
|
-
end
|
217
|
-
|
218
|
-
def config_file
|
219
|
-
File.expand_path(File.join(root,"config","newrelic.yml"))
|
220
|
-
end
|
221
|
-
|
222
|
-
def log_path
|
223
|
-
path = File.join(root,'log')
|
224
|
-
unless File.directory? path
|
225
|
-
path = '.'
|
226
|
-
end
|
227
|
-
File.expand_path(path)
|
228
|
-
end
|
229
|
-
|
230
|
-
def log_file_name(identifier="")
|
231
|
-
identifier ||= ""
|
232
|
-
"newrelic_agent.#{identifier.gsub(/[^-\w.]/, '_')}.log"
|
233
|
-
end
|
234
|
-
|
235
|
-
# Create the concrete class for environment specific behavior:
|
236
|
-
def self.new_instance
|
237
|
-
case
|
238
|
-
when defined? NewRelic::TEST
|
239
|
-
require 'config/test_config'
|
240
|
-
NewRelic::Config::Test.new
|
241
|
-
when defined? Merb::Plugins then
|
242
|
-
require 'new_relic/config/merb'
|
243
|
-
NewRelic::Config::Merb.new
|
244
|
-
when defined? Rails then
|
245
|
-
require 'new_relic/config/rails'
|
246
|
-
NewRelic::Config::Rails.new
|
247
|
-
else
|
248
|
-
require 'new_relic/config/ruby'
|
249
|
-
NewRelic::Config::Ruby.new
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
# Return a hash of settings you want to override in the newrelic.yml
|
254
|
-
# file. Maybe just for testing.
|
255
|
-
|
256
|
-
def initialize
|
257
|
-
newrelic_file = config_file
|
258
|
-
# Next two are for populating the newrelic.yml via erb binding, necessary
|
259
|
-
# when using the default newrelic.yml file
|
260
|
-
generated_for_user = ''
|
261
|
-
license_key=''
|
262
|
-
if !File.exists?(config_file)
|
263
|
-
yml_file = File.expand_path(File.join(__FILE__,"..","..","..","newrelic.yml"))
|
264
|
-
yaml = ::ERB.new(File.read(yml_file)).result(binding)
|
265
|
-
log! "Cannot find newrelic.yml file at #{config_file}."
|
266
|
-
log! "Be sure to run this from the app root dir."
|
267
|
-
log! "Using #{yml_file} file."
|
268
|
-
log! "Signup at rpm.newrelic.com to get a newrelic.yml file configured for a free Lite account."
|
269
|
-
else
|
270
|
-
yaml = ERB.new(File.read(config_file)).result(binding)
|
271
|
-
end
|
272
|
-
@yaml = YAML.load(yaml)
|
273
|
-
rescue ScriptError, StandardError => e
|
274
|
-
puts e
|
275
|
-
puts e.backtrace.join("\n")
|
276
|
-
raise "Error reading newrelic.yml file: #{e}"
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
data/lib/new_relic/shim_agent.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'new_relic/stats'
|
2
|
-
|
3
|
-
# This agent is loaded by the plug when the plug-in is disabled
|
4
|
-
# It recreates just enough of the API to not break any clients that
|
5
|
-
# invoke the Agent
|
6
|
-
|
7
|
-
|
8
|
-
# from method_tracer.rb
|
9
|
-
|
10
|
-
class Module
|
11
|
-
|
12
|
-
def trace_method_execution (*args)
|
13
|
-
yield
|
14
|
-
end
|
15
|
-
|
16
|
-
def add_method_tracer (*args)
|
17
|
-
end
|
18
|
-
|
19
|
-
def remove_method_tracer(*args)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
# from agent.rb
|
26
|
-
|
27
|
-
module NewRelic
|
28
|
-
module Agent
|
29
|
-
|
30
|
-
class << self
|
31
|
-
@@dummy_stats = NewRelic::MethodTraceStats.new
|
32
|
-
def agent
|
33
|
-
NewRelic::Agent::Agent.instance
|
34
|
-
end
|
35
|
-
|
36
|
-
alias instance agent
|
37
|
-
|
38
|
-
def get_stats(*args)
|
39
|
-
@@dummy_stats
|
40
|
-
end
|
41
|
-
def get_stats_no_scope(*args)
|
42
|
-
@@dummy_stats
|
43
|
-
end
|
44
|
-
|
45
|
-
def manual_start(*args)
|
46
|
-
end
|
47
|
-
|
48
|
-
def set_sql_obfuscator(*args)
|
49
|
-
end
|
50
|
-
|
51
|
-
def disable_sql_recording
|
52
|
-
yield
|
53
|
-
end
|
54
|
-
|
55
|
-
def disable_transaction_tracing
|
56
|
-
yield
|
57
|
-
end
|
58
|
-
|
59
|
-
def add_request_parameters(*args)
|
60
|
-
end
|
61
|
-
def add_custom_parameters(*args)
|
62
|
-
end
|
63
|
-
def should_ignore_error
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class Agent
|
68
|
-
|
69
|
-
def initialize
|
70
|
-
@error_collector = ErrorCollector.new
|
71
|
-
end
|
72
|
-
def self.instance
|
73
|
-
@@agent ||= new
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class ErrorCollector
|
78
|
-
def notice_error(*args)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
module ActionController
|
87
|
-
class Base
|
88
|
-
def newrelic_notice_error(*args); end
|
89
|
-
def self.newrelic_ignore(*args); end
|
90
|
-
def new_relic_trace_controller_action(name); yield; end
|
91
|
-
def newrelic_metric_path; end
|
92
|
-
def perform_action_with_newrelic_trace(path=nil)
|
93
|
-
yield
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end if defined? ActionController::Base
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# A test model object
|
2
|
-
# Be sure and call setup and teardown
|
3
|
-
class NewRelic::Agent::ModelFixture < ActiveRecord::Base
|
4
|
-
self.table_name = 'test_data'
|
5
|
-
def self.setup
|
6
|
-
connection.create_table :test_data, :force => true do |t|
|
7
|
-
t.column :name, :string
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.teardown
|
12
|
-
connection.drop_table :test_data
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
-
require 'new_relic/agent/model_fixture'
|
3
|
-
|
4
|
-
|
5
|
-
class ActiveRecordInstrumentationTests < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
super
|
9
|
-
NewRelic::Agent::ModelFixture.setup
|
10
|
-
@agent = NewRelic::Agent.instance
|
11
|
-
@agent.start :test, :test
|
12
|
-
@agent.transaction_sampler.harvest_slowest_sample
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
@agent.shutdown
|
17
|
-
@agent.stats_engine.harvest_timeslice_data Hash.new, Hash.new
|
18
|
-
NewRelic::Agent::ModelFixture.teardown
|
19
|
-
super
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_finder
|
23
|
-
NewRelic::Agent::ModelFixture.create :id => 0, :name => 'jeff'
|
24
|
-
NewRelic::Agent::ModelFixture.find(:all)
|
25
|
-
s = NewRelic::Agent.get_stats("ActiveRecord/NewRelic::Agent::ModelFixture/find")
|
26
|
-
assert_equal 1, s.call_count
|
27
|
-
NewRelic::Agent::ModelFixture.find_all_by_name "jeff"
|
28
|
-
s = NewRelic::Agent.get_stats("ActiveRecord/NewRelic::Agent::ModelFixture/find")
|
29
|
-
assert_equal 2, s.call_count
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_run_explains
|
33
|
-
NewRelic::Agent::ModelFixture.find(:all)
|
34
|
-
sample = @agent.transaction_sampler.harvest_slowest_sample
|
35
|
-
segment = sample.root_segment.called_segments.first.called_segments.first
|
36
|
-
assert_match /^SELECT \* FROM ["`]test_data["`]$/i, segment.params[:sql].strip
|
37
|
-
NewRelic::TransactionSample::Segment.any_instance.expects(:explain_sql).returns([])
|
38
|
-
sample = sample.prepare_to_send(:obfuscate_sql => true, :explain_enabled => true, :explain_sql => 0.0)
|
39
|
-
segment = sample.root_segment.called_segments.first.called_segments.first
|
40
|
-
end
|
41
|
-
def test_prepare_to_send
|
42
|
-
NewRelic::Agent::ModelFixture.find(:all)
|
43
|
-
sample = @agent.transaction_sampler.harvest_slowest_sample
|
44
|
-
segment = sample.root_segment.called_segments.first.called_segments.first
|
45
|
-
assert_match /^SELECT /, segment.params[:sql]
|
46
|
-
assert segment.duration > 0.0, "Segment duration must be greater than zero."
|
47
|
-
sample = sample.prepare_to_send(:record_sql => :raw, :explain_enabled => true, :explain_sql => 0.0)
|
48
|
-
segment = sample.root_segment.called_segments.first.called_segments.first
|
49
|
-
assert_match /^SELECT /, segment.params[:sql]
|
50
|
-
explanations = segment.params[:explanation]
|
51
|
-
if isMysql? || isPostgres?
|
52
|
-
assert_not_nil explanations, "No explains in segment: #{segment}"
|
53
|
-
assert_equal 1, explanations.size,"No explains in segment: #{segment}"
|
54
|
-
assert_equal 1, explanations.first.size
|
55
|
-
end
|
56
|
-
end
|
57
|
-
def test_transaction
|
58
|
-
|
59
|
-
NewRelic::Agent::ModelFixture.find(:all)
|
60
|
-
sample = @agent.transaction_sampler.harvest_slowest_sample
|
61
|
-
sample = sample.prepare_to_send(:obfuscate_sql => true, :explain_enabled => true, :explain_sql => 0.0)
|
62
|
-
segment = sample.root_segment.called_segments.first.called_segments.first
|
63
|
-
assert_nil segment.params[:sql], "SQL should have been removed."
|
64
|
-
explanations = segment.params[:explanation]
|
65
|
-
if isMysql? || isPostgres?
|
66
|
-
assert_not_nil explanations, "No explains in segment: #{segment}"
|
67
|
-
assert_equal 1, explanations.size,"No explains in segment: #{segment}"
|
68
|
-
assert_equal 1, explanations.first.size
|
69
|
-
end
|
70
|
-
if isPostgres?
|
71
|
-
assert_equal Array, explanations.class
|
72
|
-
assert_equal Array, explanations[0].class
|
73
|
-
assert_equal Array, explanations[0][0].class
|
74
|
-
assert_match /Seq Scan on test_data/, explanations[0][0].join(";")
|
75
|
-
elsif isMysql?
|
76
|
-
assert_equal "1;SIMPLE;test_data;ALL;;;;;1;", explanations.first.first.join(";")
|
77
|
-
end
|
78
|
-
|
79
|
-
s = NewRelic::Agent.get_stats("ActiveRecord/NewRelic::Agent::ModelFixture/find")
|
80
|
-
assert_equal 1, s.call_count
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
def isPostgres?
|
85
|
-
NewRelic::Agent::ModelFixture.configurations[RAILS_ENV]['adapter'] =~ /postgres/
|
86
|
-
end
|
87
|
-
def isMysql?
|
88
|
-
NewRelic::Agent::ModelFixture.connection.class.name =~ /mysql/i
|
89
|
-
end
|
90
|
-
end
|