newrelic_rpm 3.6.2.96 → 3.6.3.103.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG +33 -1
- data/README.md +7 -7
- data/lib/new_relic/agent/agent.rb +51 -22
- data/lib/new_relic/agent/agent_logger.rb +22 -11
- data/lib/new_relic/agent/configuration/defaults.rb +6 -1
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -6
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +8 -48
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +9 -1
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +4 -3
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -4
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +10 -8
- data/lib/new_relic/agent/instrumentation/padrino.rb +32 -0
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +52 -0
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +56 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +113 -48
- data/lib/new_relic/agent/new_relic_service.rb +6 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +13 -8
- data/lib/new_relic/agent/request_sampler.rb +205 -0
- data/lib/new_relic/agent/sampler.rb +0 -1
- data/lib/new_relic/agent/stats_engine/samplers.rb +0 -1
- data/lib/new_relic/agent/stats_engine/transactions.rb +12 -16
- data/lib/new_relic/agent/transaction.rb +27 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +47 -6
- data/lib/new_relic/agent/transaction_sampler.rb +0 -5
- data/lib/new_relic/agent.rb +17 -0
- data/lib/new_relic/build.rb +2 -2
- data/lib/new_relic/coerce.rb +3 -1
- data/lib/new_relic/rack/agent_hooks.rb +17 -3
- data/lib/new_relic/rack/browser_monitoring.rb +8 -3
- data/lib/new_relic/rack/error_collector.rb +2 -0
- data/lib/new_relic/transaction_sample/segment.rb +0 -23
- data/lib/new_relic/transaction_sample.rb +0 -9
- data/lib/new_relic/version.rb +1 -1
- data/test/agent_helper.rb +204 -0
- data/test/config/newrelic.yml +0 -1
- data/test/config/test_control.rb +3 -1
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +8 -5
- data/test/multiverse/suites/agent_only/logging_test.rb +1 -1
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +7 -8
- data/test/multiverse/suites/datamapper/Envfile +7 -0
- data/test/multiverse/suites/datamapper/datamapper_test.rb +105 -0
- data/test/multiverse/suites/padrino/Envfile +16 -0
- data/test/multiverse/suites/padrino/config/newrelic.yml +24 -0
- data/test/multiverse/suites/padrino/padrino_test.rb +54 -0
- data/test/multiverse/suites/rails/Envfile +5 -5
- data/test/multiverse/suites/rails/app.rb +1 -0
- data/test/multiverse/suites/rails/request_statistics_test.rb +118 -0
- data/test/multiverse/suites/sinatra/Envfile +8 -2
- data/test/multiverse/suites/sinatra/ignoring_test.rb +185 -0
- data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +92 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +0 -3
- data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +89 -0
- data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +120 -0
- data/test/new_relic/agent/agent_logger_test.rb +149 -56
- data/test/new_relic/agent/agent_test.rb +23 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +8 -1
- data/test/new_relic/agent/autostart_test.rb +10 -6
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +36 -31
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +7 -0
- data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +20 -4
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +20 -9
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +23 -19
- data/test/new_relic/agent/instrumentation/sequel_test.rb +118 -79
- data/test/new_relic/agent/instrumentation/sinatra/transaction_namer_test.rb +55 -0
- data/test/new_relic/agent/instrumentation/sinatra_test.rb +60 -11
- data/test/new_relic/agent/method_tracer_test.rb +7 -4
- data/test/new_relic/agent/new_relic_service_test.rb +6 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +6 -2
- data/test/new_relic/agent/request_sampler_test.rb +159 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +1 -5
- data/test/new_relic/agent/stats_engine_test.rb +14 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +43 -6
- data/test/new_relic/agent/transaction_sampler_test.rb +31 -1
- data/test/new_relic/agent/transaction_test.rb +29 -0
- data/test/new_relic/agent_test.rb +7 -0
- data/test/new_relic/coerce_test.rb +13 -0
- data/test/new_relic/fake_collector.rb +31 -1
- data/test/new_relic/metric_spec_test.rb +14 -10
- data/test/new_relic/rack/agent_hooks_test.rb +9 -2
- data/test/new_relic/rack/browser_monitoring_test.rb +16 -7
- data/test/new_relic/rack/developer_mode_test.rb +7 -0
- data/test/new_relic/rack/error_collector_test.rb +10 -6
- data/test/new_relic/transaction_sample/segment_test.rb +0 -61
- data/test/new_relic/transaction_sample_subtest_test.rb +0 -19
- data/test/script/ci.sh +14 -0
- data/test/test_helper.rb +79 -203
- data.tar.gz.sig +0 -0
- metadata +50 -18
- metadata.gz.sig +0 -0
- data/test/multiverse/suites/datamapper/encoding_test.rb +0 -40
- data/test/multiverse/suites/sinatra/sinatra_test.rb +0 -143
@@ -16,8 +16,9 @@ class ThreadProfilingTest < Test::Unit::TestCase
|
|
16
16
|
$collector.run
|
17
17
|
|
18
18
|
NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
|
19
|
-
NewRelic::Agent.manual_start(:'thread_profiler.enabled' => true)
|
19
|
+
NewRelic::Agent.manual_start(:'thread_profiler.enabled' => true, :force_send => true)
|
20
20
|
NewRelic::Agent.instance.service.request_timeout = 0.5
|
21
|
+
NewRelic::Agent.instance.service.agent_id = 666
|
21
22
|
|
22
23
|
@agent = NewRelic::Agent.instance
|
23
24
|
@thread_profiler = @agent.thread_profiler
|
@@ -67,9 +68,8 @@ class ThreadProfilingTest < Test::Unit::TestCase
|
|
67
68
|
let_it_finish
|
68
69
|
|
69
70
|
profile_data = $collector.calls_for('profile_data')[0]
|
70
|
-
assert_equal('666', profile_data.run_id)
|
71
|
-
|
72
|
-
assert profile_data.poll_count > 25, "Expected poll_count > 25, but was #{profile_data.poll_count}"
|
71
|
+
assert_equal('666', profile_data.run_id, "Missing run_id, profile_data was #{profile_data.inspect}")
|
72
|
+
assert(profile_data.poll_count > 10, "Expected poll_count > 10, but was #{profile_data.poll_count}")
|
73
73
|
|
74
74
|
assert_saw_traces(profile_data, "OTHER")
|
75
75
|
assert_saw_traces(profile_data, "AGENT")
|
@@ -86,9 +86,8 @@ class ThreadProfilingTest < Test::Unit::TestCase
|
|
86
86
|
let_it_finish
|
87
87
|
|
88
88
|
profile_data = $collector.calls_for('profile_data')[0]
|
89
|
-
assert_equal('666', profile_data.run_id)
|
90
|
-
|
91
|
-
assert profile_data.poll_count < 10, "Expected poll_count < 10, but was #{profile_data.poll_count}"
|
89
|
+
assert_equal('666', profile_data.run_id, "Missing run_id, profile_data was #{profile_data.inspect}")
|
90
|
+
assert(profile_data.poll_count < 50, "Expected poll_count < 50, but was #{profile_data.poll_count}")
|
92
91
|
end
|
93
92
|
|
94
93
|
# Runs a thread we expect to span entire test and be killed at the end
|
@@ -106,7 +105,7 @@ class ThreadProfilingTest < Test::Unit::TestCase
|
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
109
|
-
|
108
|
+
@agent.send(:transmit_data, true)
|
110
109
|
end
|
111
110
|
|
112
111
|
def assert_saw_traces(profile_data, type)
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require 'data_mapper'
|
6
|
+
require 'newrelic_rpm'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
|
10
|
+
|
11
|
+
DataMapper::Logger.new("/dev/null", :debug)
|
12
|
+
DataMapper.setup(:default, 'sqlite::memory:')
|
13
|
+
class Post
|
14
|
+
include DataMapper::Resource
|
15
|
+
property :id, Serial # An auto-increment integer key
|
16
|
+
property :title, String # A varchar type string, for short strings
|
17
|
+
property :body, Text # A text block, for longer string data.
|
18
|
+
end
|
19
|
+
DataMapper.auto_migrate!
|
20
|
+
DataMapper.finalize
|
21
|
+
|
22
|
+
class DummyConnection
|
23
|
+
module DummyLogging
|
24
|
+
def log(*args); end
|
25
|
+
end
|
26
|
+
|
27
|
+
include DummyLogging
|
28
|
+
include NewRelic::Agent::Instrumentation::DataMapperInstrumentation
|
29
|
+
end
|
30
|
+
|
31
|
+
class DataMapperTest < Test::Unit::TestCase
|
32
|
+
def setup
|
33
|
+
NewRelic::Agent.instance.reset_stats
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_basic_metrics
|
37
|
+
post = Post.create(:title => "Dummy post", :body => "whatever, man")
|
38
|
+
post = Post.get(post.id)
|
39
|
+
post.update(:title => 'other title')
|
40
|
+
post.destroy
|
41
|
+
assert_metrics_recorded(
|
42
|
+
'ActiveRecord/Post/save' => { :call_count => 2 },
|
43
|
+
'ActiveRecord/Post/get' => { :call_count => 1 },
|
44
|
+
'ActiveRecord/Post/update' => { :call_count => 1 },
|
45
|
+
'ActiveRecord/Post/destroy' => { :call_count => 1 }
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_rollup_metrics_for_create
|
50
|
+
post = Post.create(:title => 'foo', :body => 'bar')
|
51
|
+
post.save
|
52
|
+
assert_metrics_recorded(['ActiveRecord/save'])
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_rollup_metrics_for_update
|
56
|
+
post = Post.create(:title => 'foo', :body => 'bar')
|
57
|
+
post.body = 'baz'
|
58
|
+
post.save
|
59
|
+
assert_metrics_recorded('ActiveRecord/save' => { :call_count => 2 })
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_rollup_metrics_for_destroy
|
63
|
+
post = Post.create(:title => 'foo', :body => 'bar')
|
64
|
+
post.save
|
65
|
+
post.destroy
|
66
|
+
assert_metrics_recorded(['ActiveRecord/destroy'])
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_rollup_metrics_should_include_all_if_in_web_transaction
|
70
|
+
in_web_transaction do
|
71
|
+
Post.create(:title => 'foo', :body => 'bar').save
|
72
|
+
end
|
73
|
+
assert_metrics_recorded([
|
74
|
+
'ActiveRecord/save',
|
75
|
+
'ActiveRecord/all'
|
76
|
+
])
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_rollup_metrics_should_omit_all_if_not_in_web_transaction
|
80
|
+
in_transaction do
|
81
|
+
Post.create(:title => 'foo', :body => 'bar').save
|
82
|
+
end
|
83
|
+
assert_metrics_recorded(['ActiveRecord/save'])
|
84
|
+
assert_metrics_not_recorded(['ActiveRecord/all'])
|
85
|
+
end
|
86
|
+
|
87
|
+
# https://support.newrelic.com/tickets/2101
|
88
|
+
# https://github.com/newrelic/rpm/pull/42
|
89
|
+
# https://github.com/newrelic/rpm/pull/45
|
90
|
+
def test_should_not_bomb_out_if_a_query_is_in_an_invalid_encoding
|
91
|
+
db = DummyConnection.new
|
92
|
+
q = "select ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000"
|
93
|
+
q.force_encoding 'UTF-8' if RUBY_VERSION >= '1.9'
|
94
|
+
|
95
|
+
msg = mock
|
96
|
+
msg.stubs(:duration).returns(1)
|
97
|
+
msg.stubs(:query).returns(q)
|
98
|
+
|
99
|
+
assert_equal false, msg.query.valid_encoding? if RUBY_VERSION >= '1.9'
|
100
|
+
assert_nothing_raised do
|
101
|
+
db.send(:log, msg)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
suite_condition("Sinatra not compatible with 1.8.6") do
|
2
|
+
RUBY_VERSION != '1.8.6'
|
3
|
+
end
|
4
|
+
|
5
|
+
gemfile <<-RB
|
6
|
+
# Gemspec from rubygems on this version gets illformed warnings on 1.8.7
|
7
|
+
gem 'http_router', '0.11.0', :git => 'git://github.com/joshbuddy/http_router.git'
|
8
|
+
|
9
|
+
gem 'padrino', '~> 0.11.0'
|
10
|
+
gem 'rack-test', :require => 'rack/test'
|
11
|
+
RB
|
12
|
+
|
13
|
+
gemfile <<-RB
|
14
|
+
gem 'padrino', '~> 0.10.0'
|
15
|
+
gem 'rack-test', :require => 'rack/test'
|
16
|
+
RB
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
development:
|
3
|
+
error_collector:
|
4
|
+
capture_source: true
|
5
|
+
enabled: true
|
6
|
+
apdex_t: 0.5
|
7
|
+
ssl: false
|
8
|
+
agent_enabled: true
|
9
|
+
monitor_mode: true
|
10
|
+
license_key: bootstrap_newrelic_admin_license_key_000
|
11
|
+
developer_mode: false
|
12
|
+
app_name: test
|
13
|
+
sync_startup: true
|
14
|
+
host: 127.0.0.1
|
15
|
+
api_host: 127.0.0.1
|
16
|
+
port: <%= 30_000 + ($$ % 10_000) %>
|
17
|
+
transaction_tracer:
|
18
|
+
record_sql: obfuscated
|
19
|
+
enabled: true
|
20
|
+
stack_trace_threshold: 0.5
|
21
|
+
transaction_threshold: 1.0
|
22
|
+
capture_params: false
|
23
|
+
log_level: debug
|
24
|
+
disable_serialization: false
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper.rb')
|
6
|
+
|
7
|
+
# Shhhh
|
8
|
+
Padrino::Logger::Config[:development][:stream] = :null
|
9
|
+
|
10
|
+
class PadrinoTestApp < Padrino::Application
|
11
|
+
|
12
|
+
register Padrino::Rendering
|
13
|
+
register Padrino::Helpers
|
14
|
+
|
15
|
+
get '/user/login' do
|
16
|
+
"please log in"
|
17
|
+
end
|
18
|
+
|
19
|
+
get /\/regex.*/ do
|
20
|
+
"with extra regex's please!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class PadrinoRoutesTest < Test::Unit::TestCase
|
25
|
+
include Rack::Test::Methods
|
26
|
+
|
27
|
+
def app
|
28
|
+
PadrinoTestApp
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup
|
32
|
+
::NewRelic::Agent.manual_start
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_basic_route
|
36
|
+
get '/user/login'
|
37
|
+
assert_equal 200, last_response.status
|
38
|
+
assert_equal 'please log in', last_response.body
|
39
|
+
|
40
|
+
assert_metrics_recorded([
|
41
|
+
"Controller/Sinatra/PadrinoTestApp/GET user/login",
|
42
|
+
"Apdex/Sinatra/PadrinoTestApp/GET user/login"])
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_regex_route
|
46
|
+
get '/regexes'
|
47
|
+
assert_equal 200, last_response.status
|
48
|
+
assert_equal "with extra regex's please!", last_response.body
|
49
|
+
|
50
|
+
assert_metrics_recorded([
|
51
|
+
"Controller/Sinatra/PadrinoTestApp/GET regex.*",
|
52
|
+
"Apdex/Sinatra/PadrinoTestApp/GET regex.*"])
|
53
|
+
end
|
54
|
+
end
|
@@ -4,22 +4,22 @@ end
|
|
4
4
|
|
5
5
|
if RUBY_VERSION >= '1.9.3'
|
6
6
|
gemfile <<-RB
|
7
|
-
gem 'rails', '~>4.0.0.
|
8
|
-
gem 'haml'
|
7
|
+
gem 'rails', '~>4.0.0.rc1'
|
8
|
+
gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
|
9
9
|
RB
|
10
10
|
end
|
11
11
|
|
12
12
|
gemfile <<-RB
|
13
13
|
gem 'rails', '~>3.2.0'
|
14
|
-
gem 'haml'
|
14
|
+
gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
|
15
15
|
RB
|
16
16
|
|
17
17
|
gemfile <<-RB
|
18
18
|
gem 'rails', '~>3.1.0'
|
19
|
-
gem 'haml'
|
19
|
+
gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
|
20
20
|
RB
|
21
21
|
|
22
22
|
gemfile <<-RB
|
23
23
|
gem 'rails', '~>3.0.0'
|
24
|
-
gem 'haml'
|
24
|
+
gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
|
25
25
|
RB
|
@@ -30,6 +30,7 @@ if !defined?(MyApp)
|
|
30
30
|
# We need a secret token for session, cookies, etc.
|
31
31
|
config.active_support.deprecation = :log
|
32
32
|
config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
|
33
|
+
config.eager_load = false
|
33
34
|
initializer "install_error_middleware" do
|
34
35
|
config.middleware.use ErrorMiddleware
|
35
36
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
# https://newrelic.atlassian.net/browse/RUBY-1096
|
6
|
+
|
7
|
+
require 'rails/test_help'
|
8
|
+
require './app'
|
9
|
+
|
10
|
+
class RequestStatsController < ApplicationController
|
11
|
+
include Rails.application.routes.url_helpers
|
12
|
+
|
13
|
+
def stats_action
|
14
|
+
sleep 0.01
|
15
|
+
render :text => 'some stuff'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class RequestStatsTest < ActionController::TestCase
|
20
|
+
tests RequestStatsController
|
21
|
+
extend Multiverse::Color
|
22
|
+
|
23
|
+
def setup
|
24
|
+
$collector ||= NewRelic::FakeCollector.new
|
25
|
+
$collector.reset
|
26
|
+
setup_collector
|
27
|
+
$collector.run
|
28
|
+
|
29
|
+
NewRelic::Agent.reset_config
|
30
|
+
NewRelic::Agent.instance_variable_set(:@agent, nil)
|
31
|
+
NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
|
32
|
+
NewRelic::Agent.manual_start
|
33
|
+
NewRelic::Agent::TransactionInfo.reset
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
NewRelic::Agent::Agent.instance.shutdown if NewRelic::Agent::Agent.instance
|
38
|
+
NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#
|
43
|
+
# Tests
|
44
|
+
#
|
45
|
+
|
46
|
+
def test_is_disabled_by_default
|
47
|
+
200.times { get :stats_action }
|
48
|
+
|
49
|
+
NewRelic::Agent.agent.send(:harvest_and_send_analytic_event_data)
|
50
|
+
|
51
|
+
assert_nil $collector.agent_data.find {|post| post.action == 'analytic_event_data' }
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_request_times_should_be_reported_if_enabled
|
55
|
+
with_config( :'request_sampler.enabled' => true ) do
|
56
|
+
200.times { get :stats_action }
|
57
|
+
|
58
|
+
NewRelic::Agent.agent.send(:harvest_and_send_analytic_event_data)
|
59
|
+
|
60
|
+
post = $collector.agent_data.find {|post| post.action == 'analytic_event_data' }
|
61
|
+
|
62
|
+
assert_not_nil( post )
|
63
|
+
assert_kind_of Array, post.body
|
64
|
+
assert_kind_of Array, post.body.first
|
65
|
+
|
66
|
+
sample = post.body.first.first
|
67
|
+
assert_kind_of Hash, sample
|
68
|
+
|
69
|
+
assert_equal 'Controller/request_stats/stats_action', sample['name']
|
70
|
+
assert_encoding 'utf-8', sample['name']
|
71
|
+
assert_equal 'Transaction', sample['type']
|
72
|
+
assert_kind_of Float, sample['duration']
|
73
|
+
assert_valid_time sample['timestamp']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
#
|
80
|
+
# Helpers
|
81
|
+
#
|
82
|
+
|
83
|
+
def setup_collector
|
84
|
+
$collector.mock['connect'] = [200, {'return_value' => {"agent_run_id" => 666 }}]
|
85
|
+
end
|
86
|
+
|
87
|
+
def assert_encoding( encname, string )
|
88
|
+
return unless string.respond_to?( :encoding )
|
89
|
+
expected_encoding = Encoding.find( encname ) or raise "no such encoding #{encname.dump}"
|
90
|
+
msg = "Expected encoding of %p to be %p, but it was %p" %
|
91
|
+
[ string, expected_encoding, string.encoding ]
|
92
|
+
assert_equal( expected_encoding, string.encoding, msg )
|
93
|
+
end
|
94
|
+
|
95
|
+
def assert_valid_time( object )
|
96
|
+
return if object.is_a?( Time )
|
97
|
+
assert_kind_of Time, Time.parse(object.to_s) rescue object
|
98
|
+
end
|
99
|
+
|
100
|
+
# :TODO: Remove this if/when test_helper is available from multiverse tests
|
101
|
+
def with_config(config_hash, opts={})
|
102
|
+
opts = { :level => 0, :do_not_cast => false }.merge(opts)
|
103
|
+
if opts[:do_not_cast]
|
104
|
+
config = config_hash
|
105
|
+
else
|
106
|
+
config = NewRelic::Agent::Configuration::DottedHash.new(config_hash)
|
107
|
+
end
|
108
|
+
NewRelic::Agent.config.apply_config(config, opts[:level])
|
109
|
+
begin
|
110
|
+
yield
|
111
|
+
ensure
|
112
|
+
NewRelic::Agent.config.remove_config(config)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
118
|
+
|
@@ -3,13 +3,19 @@ suite_condition("Sinatra not compatible with 1.8.6") do
|
|
3
3
|
end
|
4
4
|
|
5
5
|
gemfile <<-RB
|
6
|
-
gem 'sinatra', '1.
|
6
|
+
gem 'sinatra', '~> 1.4.0'
|
7
7
|
gem 'rack-test', :require => 'rack/test'
|
8
8
|
gem 'mocha'
|
9
9
|
RB
|
10
10
|
|
11
11
|
gemfile <<-RB
|
12
|
-
gem 'sinatra', '1.
|
12
|
+
gem 'sinatra', '~> 1.3.0'
|
13
|
+
gem 'rack-test', :require => 'rack/test'
|
14
|
+
gem 'mocha'
|
15
|
+
RB
|
16
|
+
|
17
|
+
gemfile <<-RB
|
18
|
+
gem 'sinatra', '~> 1.2.0'
|
13
19
|
gem 'rack-test', :require => 'rack/test'
|
14
20
|
gem 'mocha'
|
15
21
|
RB
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
class SinatraIgnoreTestApp < Sinatra::Base
|
6
|
+
get '/record' do request.path_info end
|
7
|
+
|
8
|
+
newrelic_ignore '/ignore'
|
9
|
+
get '/ignore' do request.path_info end
|
10
|
+
|
11
|
+
newrelic_ignore '/splat*'
|
12
|
+
get '/splattered' do request.path_info end
|
13
|
+
|
14
|
+
newrelic_ignore '/named/:id'
|
15
|
+
get '/named/:id' do request.path_info end
|
16
|
+
|
17
|
+
newrelic_ignore '/v1', '/v2'
|
18
|
+
get '/v1' do request.path_info end
|
19
|
+
get '/v2' do request.path_info end
|
20
|
+
get '/v3' do request.path_info end
|
21
|
+
|
22
|
+
newrelic_ignore(/\/.+regex.*/)
|
23
|
+
get '/skip_regex' do request.path_info end
|
24
|
+
get '/regex_seen' do request.path_info end
|
25
|
+
|
26
|
+
newrelic_ignore '/ignored_erroring'
|
27
|
+
get '/ignored_erroring' do raise 'boom'; end
|
28
|
+
|
29
|
+
newrelic_ignore_apdex '/no_apdex'
|
30
|
+
get '/no_apdex' do request.path_info end
|
31
|
+
|
32
|
+
newrelic_ignore_enduser '/no_enduser'
|
33
|
+
get '/no_enduser' do request.path_info end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class SinatraTestCase < Test::Unit::TestCase
|
38
|
+
include Rack::Test::Methods
|
39
|
+
include ::NewRelic::Agent::Instrumentation::Sinatra
|
40
|
+
|
41
|
+
def setup
|
42
|
+
NewRelic::Agent.manual_start
|
43
|
+
NewRelic::Agent.instance.stats_engine.reset_stats
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_and_assert_ok(path)
|
47
|
+
get(path)
|
48
|
+
assert_equal 200, last_response.status
|
49
|
+
assert_equal path, last_response.body
|
50
|
+
end
|
51
|
+
|
52
|
+
# Keep Test::Unit happy by specifying at least one test method here
|
53
|
+
# Real tests are defined in subclasses.
|
54
|
+
def test_nothing; end
|
55
|
+
end
|
56
|
+
|
57
|
+
class SinatraIgnoreTest < SinatraTestCase
|
58
|
+
def app
|
59
|
+
SinatraIgnoreTestApp
|
60
|
+
end
|
61
|
+
|
62
|
+
def app_name
|
63
|
+
app.to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_and_assert_ok(path)
|
67
|
+
get(path)
|
68
|
+
assert_equal 200, last_response.status
|
69
|
+
assert_equal path, last_response.body
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_seen_route
|
73
|
+
get_and_assert_ok '/record'
|
74
|
+
assert_metrics_recorded([
|
75
|
+
"Controller/Sinatra/#{app_name}/GET record",
|
76
|
+
"Apdex/Sinatra/#{app_name}/GET record"])
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_ignores_exact_match
|
80
|
+
get_and_assert_ok '/ignore'
|
81
|
+
assert_metrics_not_recorded([
|
82
|
+
"Controller/Sinatra/#{app_name}/GET ignore",
|
83
|
+
"Apdex/Sinatra/#{app_name}/GET ignore"])
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_ignores_by_splats
|
87
|
+
get_and_assert_ok '/splattered'
|
88
|
+
assert_metrics_not_recorded([
|
89
|
+
"Controller/Sinatra/#{app_name}/GET splattered",
|
90
|
+
"Apdex/Sinatra/#{app_name}/GET splattered"])
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_ignores_can_be_declared_in_batches
|
94
|
+
get_and_assert_ok '/v1'
|
95
|
+
get_and_assert_ok '/v2'
|
96
|
+
get_and_assert_ok '/v3'
|
97
|
+
|
98
|
+
assert_metrics_not_recorded([
|
99
|
+
"Controller/Sinatra/#{app_name}/GET v1",
|
100
|
+
"Controller/Sinatra/#{app_name}/GET v2",
|
101
|
+
"Apdex/Sinatra/#{app_name}/GET v1",
|
102
|
+
"Apdex/Sinatra/#{app_name}/GET v2"])
|
103
|
+
|
104
|
+
assert_metrics_recorded([
|
105
|
+
"Controller/Sinatra/#{app_name}/GET v3",
|
106
|
+
"Apdex/Sinatra/#{app_name}/GET v3"])
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_seen_with_regex
|
110
|
+
get_and_assert_ok '/regex_seen'
|
111
|
+
assert_metrics_recorded([
|
112
|
+
"Controller/Sinatra/#{app_name}/GET regex_seen",
|
113
|
+
"Apdex/Sinatra/#{app_name}/GET regex_seen"])
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_ignores_by_regex
|
117
|
+
get_and_assert_ok '/skip_regex'
|
118
|
+
assert_metrics_not_recorded([
|
119
|
+
"Controller/Sinatra/#{app_name}/GET skip_regex",
|
120
|
+
"Apdex/Sinatra/#{app_name}/GET skip_regex"])
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_ignore_apdex
|
124
|
+
get_and_assert_ok '/no_apdex'
|
125
|
+
assert_metrics_recorded(["Controller/Sinatra/#{app_name}/GET no_apdex"])
|
126
|
+
assert_metrics_not_recorded(["Apdex/Sinatra/#{app_name}/GET no_apdex"])
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_ignore_enduser
|
130
|
+
get_and_assert_ok '/no_enduser'
|
131
|
+
|
132
|
+
assert NewRelic::Agent::TransactionInfo.get.ignore_end_user?
|
133
|
+
assert_metrics_recorded([
|
134
|
+
"Controller/Sinatra/#{app_name}/GET no_enduser",
|
135
|
+
"Apdex/Sinatra/#{app_name}/GET no_enduser"])
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_ignore_errors_in_ignored_transactions
|
139
|
+
get '/ignored_erroring'
|
140
|
+
assert_metrics_not_recorded(["Errors/all"])
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# Blanket ignore for whole app if newrelic_ignore called without parameters
|
145
|
+
class SinatraIgnoreItAllApp < Sinatra::Base
|
146
|
+
newrelic_ignore
|
147
|
+
|
148
|
+
get '/' do request.path_info end
|
149
|
+
end
|
150
|
+
|
151
|
+
class SinatraIgnoreItAllTest < SinatraTestCase
|
152
|
+
def app
|
153
|
+
SinatraIgnoreItAllApp
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_ignores_everything
|
157
|
+
get_and_assert_ok '/'
|
158
|
+
assert_metrics_recorded_exclusive([])
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
# Blanket ignore for whole app if calls made without parameters
|
164
|
+
class SinatraIgnoreApdexAndEndUserApp < Sinatra::Base
|
165
|
+
newrelic_ignore_apdex
|
166
|
+
newrelic_ignore_enduser
|
167
|
+
|
168
|
+
get '/' do request.path_info end
|
169
|
+
end
|
170
|
+
|
171
|
+
class SinatraIgnoreApdexAndEndUserTest < SinatraTestCase
|
172
|
+
def app
|
173
|
+
SinatraIgnoreApdexAndEndUserApp
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_ignores_apdex
|
177
|
+
get_and_assert_ok '/'
|
178
|
+
assert_metrics_not_recorded(["Apdex/Sinatra/#{app.to_s}/GET "])
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_ignores_enduser
|
182
|
+
get_and_assert_ok '/'
|
183
|
+
assert NewRelic::Agent::TransactionInfo.get.ignore_end_user?
|
184
|
+
end
|
185
|
+
end
|