newrelic_rpm 3.5.2.17 → 3.5.3.24
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/.travis.yml +3 -1
- data/CHANGELOG +39 -23
- data/GUIDELINES_FOR_CONTRIBUTING.md +23 -2
- data/Rakefile +32 -0
- data/lib/new_relic/agent.rb +1 -0
- data/lib/new_relic/agent/agent.rb +45 -6
- data/lib/new_relic/agent/browser_monitoring.rb +36 -20
- data/lib/new_relic/agent/busy_calculator.rb +12 -4
- data/lib/new_relic/agent/configuration/defaults.rb +6 -1
- data/lib/new_relic/agent/configuration/environment_source.rb +14 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +14 -10
- data/lib/new_relic/agent/new_relic_service.rb +192 -34
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -2
- data/lib/new_relic/agent/pipe_service.rb +5 -1
- data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
- data/lib/new_relic/agent/sql_sampler.rb +29 -10
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +40 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +1 -2
- data/lib/new_relic/agent/thread.rb +27 -0
- data/lib/new_relic/agent/thread_profiler.rb +295 -0
- data/lib/new_relic/agent/worker_loop.rb +29 -15
- data/lib/new_relic/control/frameworks/rails.rb +4 -4
- data/lib/new_relic/control/frameworks/rails3.rb +1 -1
- data/lib/new_relic/helper.rb +3 -0
- data/lib/new_relic/metric_data.rb +10 -2
- data/lib/new_relic/noticed_error.rb +5 -0
- data/lib/new_relic/transaction_sample.rb +23 -13
- data/lib/new_relic/transaction_sample/segment.rb +13 -15
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/tests.rake +5 -11
- data/test/multiverse/.gitignore +10 -0
- data/test/multiverse/README.md +90 -0
- data/test/multiverse/Rakefile +17 -0
- data/test/multiverse/lib/multiverse/color.rb +13 -0
- data/test/multiverse/lib/multiverse/envfile.rb +66 -0
- data/test/multiverse/lib/multiverse/environment.rb +16 -0
- data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
- data/test/multiverse/lib/multiverse/runner.rb +44 -0
- data/test/multiverse/lib/multiverse/suite.rb +162 -0
- data/test/multiverse/script/run_one +3 -0
- data/test/multiverse/script/runner +9 -0
- data/test/multiverse/suites/active_record/Envfile +13 -0
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
- data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
- data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
- data/test/multiverse/suites/agent_only/Envfile +3 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
- data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
- data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
- data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
- data/test/multiverse/suites/datamapper/Envfile +8 -0
- data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
- data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
- data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
- data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
- data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
- data/test/multiverse/suites/no_load/Envfile +2 -0
- data/test/multiverse/suites/no_load/config/newrelic.yml +23 -0
- data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
- data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
- data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
- data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
- data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
- data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
- data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
- data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
- data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
- data/test/multiverse/suites/rails_3_views/Envfile +16 -0
- data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
- data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
- data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
- data/test/multiverse/suites/resque/Envfile +21 -0
- data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
- data/test/multiverse/suites/resque/dump.rdb +0 -0
- data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
- data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
- data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
- data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +422 -0
- data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
- data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +115 -0
- data/test/multiverse/suites/sinatra/Envfile +13 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +76 -0
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
- data/test/multiverse/test/multiverse_test.rb +55 -0
- data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
- data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
- data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
- data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
- data/test/new_relic/agent/agent_test.rb +54 -2
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +35 -5
- data/test/new_relic/agent/browser_monitoring_test.rb +8 -8
- data/test/new_relic/agent/configuration/environment_source_test.rb +16 -0
- data/test/new_relic/agent/method_tracer_test.rb +6 -6
- data/test/new_relic/agent/new_relic_service_test.rb +137 -20
- data/test/new_relic/agent/sql_sampler_test.rb +26 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +1 -1
- data/test/new_relic/agent/stats_engine_test.rb +1 -0
- data/test/new_relic/agent/thread_profiler_test.rb +536 -0
- data/test/new_relic/agent/thread_test.rb +76 -0
- data/test/new_relic/agent/threaded_test.rb +65 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +16 -13
- data/test/new_relic/agent/worker_loop_test.rb +20 -0
- data/test/new_relic/fake_collector.rb +103 -31
- data/test/new_relic/fake_service.rb +7 -1
- data/test/new_relic/metric_data_test.rb +45 -16
- data/test/new_relic/noticed_error_test.rb +14 -0
- data/test/new_relic/transaction_sample/segment_test.rb +23 -4
- data/test/new_relic/transaction_sample_test.rb +39 -0
- data/ui/views/layouts/newrelic_default.rhtml +1 -0
- data/ui/views/newrelic/threads.rhtml +2 -10
- metadata +88 -2
@@ -0,0 +1,75 @@
|
|
1
|
+
# https://newrelic.atlassian.net/browse/RUBY-927
|
2
|
+
|
3
|
+
ENV['NEW_RELIC_DISPATCHER'] = 'test'
|
4
|
+
|
5
|
+
require 'action_controller/railtie'
|
6
|
+
require 'rails/test_unit/railtie'
|
7
|
+
require 'rails/test_help'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
# BEGIN RAILS APP
|
11
|
+
|
12
|
+
class MyApp < Rails::Application
|
13
|
+
# We need a secret token for session, cookies, etc.
|
14
|
+
config.active_support.deprecation = :log
|
15
|
+
config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
|
16
|
+
end
|
17
|
+
MyApp.initialize!
|
18
|
+
|
19
|
+
MyApp.routes.draw do
|
20
|
+
match '/:controller(/:action(/:id))'
|
21
|
+
end
|
22
|
+
|
23
|
+
class ApplicationController < ActionController::Base; end
|
24
|
+
|
25
|
+
class TestController < ApplicationController
|
26
|
+
include Rails.application.routes.url_helpers
|
27
|
+
|
28
|
+
def queued
|
29
|
+
respond_to do |format|
|
30
|
+
format.html { render :text => "<html><head></head><body>Queued</body></html>" }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
# END RAILS APP
|
35
|
+
|
36
|
+
class QueueTimeTest < ActionDispatch::IntegrationTest
|
37
|
+
def setup
|
38
|
+
NewRelic::Agent.config.apply_config({
|
39
|
+
:beacon => "beacon",
|
40
|
+
:browser_key => "key"})
|
41
|
+
|
42
|
+
@agent = NewRelic::Agent::Agent.new
|
43
|
+
NewRelic::Agent::Agent.instance_variable_set(:@instance, @agent)
|
44
|
+
NewRelic::Agent.manual_start
|
45
|
+
|
46
|
+
@agent.finish_setup({})
|
47
|
+
end
|
48
|
+
|
49
|
+
def teardown
|
50
|
+
NewRelic::Agent::Agent.instance.shutdown if NewRelic::Agent::Agent.instance
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_should_track_queue_time_metric
|
54
|
+
get_queued
|
55
|
+
|
56
|
+
stat = @agent.stats_engine.lookup_stats('WebFrontend/QueueTime')
|
57
|
+
assert_equal 1, stat.call_count
|
58
|
+
assert stat.total_call_time > 0, "Should track some queue time"
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_should_see_queue_time_in_rum
|
62
|
+
get_queued
|
63
|
+
assert extract_queue_time_from_response > 0, "Queue time was missing or zero"
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_queued(header="HTTP_X_QUEUE_START")
|
67
|
+
get('/test/queued', nil, \
|
68
|
+
header => "t=#{(Time.now.to_i * 1_000_000) - 1_000}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def extract_queue_time_from_response
|
72
|
+
@response.body =~ /key\",,\".*\",(\d+.*),\d+,new Date/
|
73
|
+
$1.to_i
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
suite_condition("Rails 3 not compatible with 1.8.6") do
|
2
|
+
RUBY_VERSION != '1.8.6'
|
3
|
+
end
|
4
|
+
|
5
|
+
gemfile <<-RB
|
6
|
+
gem 'rails', '~>3.2.0'
|
7
|
+
gem 'haml'
|
8
|
+
RB
|
9
|
+
gemfile <<-RB
|
10
|
+
gem 'rails', '~>3.1.0'
|
11
|
+
gem 'haml'
|
12
|
+
RB
|
13
|
+
gemfile <<-RB
|
14
|
+
gem 'rails', '~>3.0.0'
|
15
|
+
gem 'haml'
|
16
|
+
RB
|
@@ -0,0 +1 @@
|
|
1
|
+
= foo.inspect
|
@@ -0,0 +1 @@
|
|
1
|
+
This is a partial
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'a_partial' %>
|
@@ -0,0 +1,164 @@
|
|
1
|
+
#
|
2
|
+
# This file configures the NewRelic RPM Agent, NewRelic RPM monitors Rails
|
3
|
+
# applications with deep visibility and low overhead. For more information,
|
4
|
+
# visit www.newrelic.com.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# here are the settings that are common to all environments
|
9
|
+
common: &default_settings
|
10
|
+
|
11
|
+
# ============================== LICENSE KEY ===============================
|
12
|
+
# You must specify the licence key associated with your New Relic account.
|
13
|
+
# This key binds your Agent's data to your account in the New Relic RPM service.
|
14
|
+
|
15
|
+
#license_key: 'bootstrap_newrelic_admin_license_key_000'
|
16
|
+
#host: localhost
|
17
|
+
#port: 3000
|
18
|
+
|
19
|
+
license_key: 'bd0e1d52adade840f7ca727d29a86249e89a6f1c'
|
20
|
+
host: localhost
|
21
|
+
|
22
|
+
# Agent Enabled
|
23
|
+
# Use this setting to force the agent to run or not run.
|
24
|
+
# Default is 'auto' which means the agent will install and run only if a
|
25
|
+
# valid dispatcher such as Mongrel is running. This prevents it from running
|
26
|
+
# with Rake or the console. Set to false to completely turn the agent off
|
27
|
+
# regardless of the other settings. Valid values are true, false and auto.
|
28
|
+
# agent_enabled: auto
|
29
|
+
|
30
|
+
# Application Name
|
31
|
+
# Set this to be the name of your application as you'd like it show up in RPM.
|
32
|
+
# RPM will then auto-map instances of your application into a RPM "application"
|
33
|
+
# on your home dashboard page. This setting does not prevent you from manually
|
34
|
+
# defining applications.
|
35
|
+
app_name: Rails 3 view test ap
|
36
|
+
|
37
|
+
# When 'enabled' is turned on, the agent collects performance data by inserting lightweight
|
38
|
+
# tracers on key methods inside the rails framework and asynchronously aggregating
|
39
|
+
# and reporting this performance data to the NewRelic RPM service at newrelic.com.
|
40
|
+
enabled: false
|
41
|
+
|
42
|
+
# The newrelic agent generates its own log file to keep its logging information
|
43
|
+
# separate from that of your application. Specify its log level here.
|
44
|
+
log_level: debug
|
45
|
+
|
46
|
+
# The newrelic agent communicates with the RPM service via http by default.
|
47
|
+
# If you want to communicate via https to increase security, then turn on
|
48
|
+
# SSL by setting this value to true. Note, this will result in increased
|
49
|
+
# CPU overhead to perform the encryption involved in SSL communication, but this
|
50
|
+
# work is done asynchronously to the threads that process your application code, so
|
51
|
+
# it should not impact response times.
|
52
|
+
ssl: false
|
53
|
+
|
54
|
+
# Set your application's Apdex threshold value with the 'apdex_t' setting, in seconds. The
|
55
|
+
# apdex_t value determines the buckets used to compute your overall Apdex score. Requests
|
56
|
+
# that take less than apdex_t seconds to process will be classified as Satisfying transactions;
|
57
|
+
# more than apdex_t seconds as Tolerating transactions; and more than four times the apdex_t
|
58
|
+
# value as Frustrating transactions. For more
|
59
|
+
# about the Apdex standard, see http://support.newrelic.com/faqs/general/apdex
|
60
|
+
apdex_t: 1.0
|
61
|
+
|
62
|
+
|
63
|
+
# Proxy settings for connecting to the RPM server.
|
64
|
+
#
|
65
|
+
# If a proxy is used, the host setting is required. Other settings are optional. Default
|
66
|
+
# port is 8080.
|
67
|
+
#
|
68
|
+
# proxy_host: hostname
|
69
|
+
# proxy_port: 8080
|
70
|
+
# proxy_user:
|
71
|
+
# proxy_pass:
|
72
|
+
|
73
|
+
|
74
|
+
# Tells transaction tracer and error collector (when enabled) whether or not to capture HTTP params.
|
75
|
+
# When true, the RoR filter_parameter_logging mechanism is used so that sensitive parameters are not recorded
|
76
|
+
capture_params: false
|
77
|
+
|
78
|
+
|
79
|
+
# Transaction tracer captures deep information about slow
|
80
|
+
# transactions and sends this to the RPM service once a minute. Included in the
|
81
|
+
# transaction is the exact call sequence of the transactions including any SQL statements
|
82
|
+
# issued.
|
83
|
+
transaction_tracer:
|
84
|
+
|
85
|
+
# Transaction tracer is enabled by default. Set this to false to turn it off. This feature
|
86
|
+
# is only available at the Silver and above product levels.
|
87
|
+
enabled: true
|
88
|
+
|
89
|
+
# Threshold in seconds for when to collect a transaction trace. When the response time of
|
90
|
+
# a controller action exceeds this threshold, a transaction trace will be recorded and sent
|
91
|
+
# to RPM. Valid values are any float value, or (default) "apdex_f", which will use the
|
92
|
+
# threshold for an dissatisfying Apdex controller action - four times the Apdex T value.
|
93
|
+
transaction_threshold: apdex_f
|
94
|
+
|
95
|
+
# When transaction tracer is on, SQL statements can optionally be recorded. The recorder
|
96
|
+
# has three modes, "off" which sends no SQL, "raw" which sends the SQL statement in its
|
97
|
+
# original form, and "obfuscated", which strips out numeric and string literals
|
98
|
+
record_sql: obfuscated
|
99
|
+
|
100
|
+
# Threshold in seconds for when to collect stack trace for a SQL call. In other words,
|
101
|
+
# when SQL statements exceed this threshold, then capture and send to RPM the current
|
102
|
+
# stack trace. This is helpful for pinpointing where long SQL calls originate from
|
103
|
+
stack_trace_threshold: 0.500
|
104
|
+
|
105
|
+
# Error collector captures information about uncaught exceptions and sends them to RPM for
|
106
|
+
# viewing
|
107
|
+
error_collector:
|
108
|
+
|
109
|
+
# Error collector is enabled by default. Set this to false to turn it off. This feature
|
110
|
+
# is only available at the Silver and above product levels
|
111
|
+
enabled: true
|
112
|
+
|
113
|
+
# Tells error collector whether or not to capture a source snippet around the place of the
|
114
|
+
# error when errors are View related.
|
115
|
+
capture_source: true
|
116
|
+
|
117
|
+
# To stop specific errors from reporting to RPM, set this property to comma separated
|
118
|
+
# values
|
119
|
+
#
|
120
|
+
#ignore_errors: ActionController::RoutingError, ...
|
121
|
+
|
122
|
+
# (Advanced) Uncomment this to ensure the cpu and memory samplers won't run. Useful when you
|
123
|
+
# are using the agent to monitor an external resource
|
124
|
+
# disable_samplers: true
|
125
|
+
|
126
|
+
# override default settings based on your application's environment
|
127
|
+
|
128
|
+
# NOTE if your application has other named environments, you should
|
129
|
+
# provide newrelic conifguration settings for these enviromnents here.
|
130
|
+
|
131
|
+
development:
|
132
|
+
<<: *default_settings
|
133
|
+
# turn off communication to RPM service in development mode.
|
134
|
+
# NOTE: for initial evaluation purposes, you may want to temporarily turn
|
135
|
+
# the agent on in development mode.
|
136
|
+
enabled: true
|
137
|
+
|
138
|
+
# When running in Developer Mode, the New Relic Agent will present
|
139
|
+
# performance information on the last 100 transactions you have
|
140
|
+
# executed since starting the mongrel. to view this data, go to
|
141
|
+
# http://localhost:3000/newrelic
|
142
|
+
developer: true
|
143
|
+
|
144
|
+
test:
|
145
|
+
<<: *default_settings
|
146
|
+
# it almost never makes sense to turn on the agent when running unit, functional or
|
147
|
+
# integration tests or the like.
|
148
|
+
enabled: true
|
149
|
+
log_level: debug
|
150
|
+
|
151
|
+
# Turn on the agent in production for 24x7 monitoring. NewRelic testing shows
|
152
|
+
# an average performance impact of < 5 ms per transaction, you you can leave this on
|
153
|
+
# all the time without incurring any user-visible performance degredation.
|
154
|
+
production:
|
155
|
+
<<: *default_settings
|
156
|
+
enabled: true
|
157
|
+
|
158
|
+
# many applications have a staging environment which behaves identically to production.
|
159
|
+
# Support for that environment is provided here. By default, the staging environment has
|
160
|
+
# the agent turned on.
|
161
|
+
staging:
|
162
|
+
<<: *default_settings
|
163
|
+
enabled: true
|
164
|
+
app_name: My Application (Staging)
|
@@ -0,0 +1,245 @@
|
|
1
|
+
require "action_controller/railtie"
|
2
|
+
require "rails/test_unit/railtie"
|
3
|
+
require 'rails/test_help'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
# BEGIN RAILS APP
|
7
|
+
|
8
|
+
ActionController::Base.view_paths = ['app/views']
|
9
|
+
|
10
|
+
class MyApp < Rails::Application
|
11
|
+
# We need a secret token for session, cookies, etc.
|
12
|
+
config.active_support.deprecation = :log
|
13
|
+
config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
|
14
|
+
config.after_initialize do
|
15
|
+
NewRelic::Agent.manual_start
|
16
|
+
end
|
17
|
+
end
|
18
|
+
MyApp.initialize!
|
19
|
+
|
20
|
+
MyApp.routes.draw do
|
21
|
+
match '/:controller(/:action(/:id))'
|
22
|
+
end
|
23
|
+
|
24
|
+
class ApplicationController < ActionController::Base; end
|
25
|
+
|
26
|
+
# a basic active model compliant model we can render
|
27
|
+
class Foo
|
28
|
+
extend ActiveModel::Naming
|
29
|
+
def to_model
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def valid?() true end
|
34
|
+
def new_record?() true end
|
35
|
+
def destroyed?() true end
|
36
|
+
|
37
|
+
def errors
|
38
|
+
obj = Object.new
|
39
|
+
def obj.[](key) [] end
|
40
|
+
def obj.full_messages() [] end
|
41
|
+
obj
|
42
|
+
end
|
43
|
+
end
|
44
|
+
class TestController < ApplicationController
|
45
|
+
include Rails.application.routes.url_helpers
|
46
|
+
def template_render_with_3_partial_renders
|
47
|
+
render 'index'
|
48
|
+
end
|
49
|
+
|
50
|
+
def deep_partial_render
|
51
|
+
render 'deep_partial'
|
52
|
+
end
|
53
|
+
|
54
|
+
def text_render
|
55
|
+
render :text => "Yay"
|
56
|
+
end
|
57
|
+
|
58
|
+
def json_render
|
59
|
+
render :json => {"a" => "b"}
|
60
|
+
end
|
61
|
+
|
62
|
+
def xml_render
|
63
|
+
render :xml => {"a" => "b"}
|
64
|
+
end
|
65
|
+
|
66
|
+
def js_render
|
67
|
+
render :js => 'alert("this is js");'
|
68
|
+
end
|
69
|
+
|
70
|
+
def file_render
|
71
|
+
render :file => File.expand_path(__FILE__), :content_type => 'text/plain', :layout => false
|
72
|
+
end
|
73
|
+
|
74
|
+
def nothing_render
|
75
|
+
render :nothing => true
|
76
|
+
end
|
77
|
+
|
78
|
+
def inline_render
|
79
|
+
render :inline => "<% Time.now %><p><%= Time.now %></p>"
|
80
|
+
end
|
81
|
+
|
82
|
+
def haml_render
|
83
|
+
render 'haml_view'
|
84
|
+
end
|
85
|
+
|
86
|
+
def no_template
|
87
|
+
render []
|
88
|
+
end
|
89
|
+
|
90
|
+
def collection_render
|
91
|
+
render((1..3).map{|x| Foo.new })
|
92
|
+
end
|
93
|
+
|
94
|
+
# proc rendering isn't available in rails 3 but you can do nonsense like this
|
95
|
+
# and assign an enumerable object to the response body.
|
96
|
+
def proc_render
|
97
|
+
streamer = Class.new
|
98
|
+
def each
|
99
|
+
10_000.times do |i|
|
100
|
+
yield "This is line #{i}\n"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
self.response_body = streamer.new
|
104
|
+
end
|
105
|
+
|
106
|
+
def raise_render
|
107
|
+
raise "this is an uncaught RuntimeError"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# END RAILS APP
|
112
|
+
|
113
|
+
|
114
|
+
class TestControllerTest < ActionController::TestCase
|
115
|
+
tests TestController
|
116
|
+
def setup
|
117
|
+
@controller = TestController.new
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# SANITY TESTS - Make sure nothing raises errors,
|
122
|
+
# unless it's supposed to
|
123
|
+
class SanityTest < TestControllerTest
|
124
|
+
|
125
|
+
# assert we can call any of these renders with no errors
|
126
|
+
# (except the one that does raise an error)
|
127
|
+
(TestController.action_methods - ["raise_render"]).each do |method|
|
128
|
+
test "should not raise errors on GET to #{method.inspect}" do
|
129
|
+
get method.dup
|
130
|
+
end
|
131
|
+
|
132
|
+
test "should not raise errors on POST to #{method.inspect}" do
|
133
|
+
post method.dup
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
test "should allow an uncaught exception to propogate" do
|
138
|
+
assert_raise RuntimeError do
|
139
|
+
get :raise_render
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# A controller action that renders 1 template and the same partial 3 times
|
145
|
+
class NormalishRenderTest < TestControllerTest
|
146
|
+
test "should count all the template and partial segments" do
|
147
|
+
get :template_render_with_3_partial_renders
|
148
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
149
|
+
assert_equal 5, sample.count_segments, "should be a node for the controller action, the template, and 3 partials (5)"
|
150
|
+
end
|
151
|
+
|
152
|
+
test "should have 3 segments with the metric name 'View/test/_a_partial.html.erb/Partial'" do
|
153
|
+
get :template_render_with_3_partial_renders
|
154
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
155
|
+
|
156
|
+
partial_segments = sample.root_segment.called_segments.first.called_segments.first.called_segments
|
157
|
+
assert_equal 3, partial_segments.size, "sanity check"
|
158
|
+
|
159
|
+
assert_equal ['View/test/_a_partial.html.erb/Partial'], partial_segments.map(&:metric_name).uniq
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class TextRenderTest < TestControllerTest
|
164
|
+
# it doesn't seem worth it to get consistent behavior here.
|
165
|
+
if Rails::VERSION::MINOR.to_i == 0
|
166
|
+
test "should not instrument rendering of text" do
|
167
|
+
get :text_render
|
168
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
169
|
+
assert_equal [], sample.root_segment.called_segments.first.called_segments
|
170
|
+
end
|
171
|
+
else
|
172
|
+
test "should create a metric for the rendered text" do
|
173
|
+
get :text_render
|
174
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
175
|
+
text_segment = sample.root_segment.called_segments.first.called_segments.first
|
176
|
+
assert_equal 'View/text template/Rendering', text_segment.metric_name
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
class InlineTemplateRenderTest < TestControllerTest
|
182
|
+
test "should create a metric for the rendered inline template" do
|
183
|
+
get :inline_render
|
184
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
185
|
+
text_segment = sample.root_segment.called_segments.first.called_segments.first
|
186
|
+
assert_equal 'View/inline template/Rendering', text_segment.metric_name
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
class HamlRenderTest < TestControllerTest
|
191
|
+
test "should create a metric for the rendered haml template" do
|
192
|
+
get :haml_render
|
193
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
194
|
+
text_segment = sample.root_segment.called_segments.first.called_segments.first
|
195
|
+
assert_equal 'View/test/haml_view.html.haml/Rendering', text_segment.metric_name
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
class MissingTemplateTest < TestControllerTest
|
200
|
+
# Rails 3.0 has different behavior for rendering an empty array. We're okay with this.
|
201
|
+
if Rails::VERSION::MINOR.to_i == 0
|
202
|
+
test "should create an proper metric when the template is unknown" do
|
203
|
+
get :no_template
|
204
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
205
|
+
text_segment = sample.root_segment.called_segments.first.called_segments.first
|
206
|
+
assert_nil text_segment
|
207
|
+
end
|
208
|
+
else
|
209
|
+
test "should create an proper metric when the template is unknown" do
|
210
|
+
get :no_template
|
211
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
212
|
+
text_segment = sample.root_segment.called_segments.first.called_segments.first
|
213
|
+
assert_equal 'View/(unknown)/Partial', text_segment.metric_name
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
class CollectionTemplateTest < TestControllerTest
|
219
|
+
test "should create a proper metric when we render a collection" do
|
220
|
+
get :collection_render
|
221
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
222
|
+
text_segment = sample.root_segment.called_segments.first.called_segments.first
|
223
|
+
assert_equal "View/foos/_foo.html.haml/Partial", text_segment.metric_name
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
class UninstrumentedRendersTest < TestControllerTest
|
228
|
+
[:js_render, :xml_render, :proc_render, :json_render ].each do |action|
|
229
|
+
test "should not instrument rendering of #{action.inspect}" do
|
230
|
+
get action
|
231
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
232
|
+
assert_equal [], sample.root_segment.called_segments.first.called_segments
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class FileRenderTest < TestControllerTest
|
238
|
+
test "should create a metric for rendered file that does not include the filename so it doesn't metric explode" do
|
239
|
+
get :file_render
|
240
|
+
sample = NewRelic::Agent.agent.transaction_sampler.samples.last
|
241
|
+
text_segment = sample.root_segment.called_segments.first.called_segments.first
|
242
|
+
assert_equal 'View/file/Rendering', text_segment.metric_name
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|