newrelic_rpm 3.7.0.177 → 3.7.1.180
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +28 -1
- data/lib/new_relic/agent.rb +1 -2
- data/lib/new_relic/agent/agent.rb +28 -10
- data/lib/new_relic/agent/agent_logger.rb +4 -3
- data/lib/new_relic/agent/audit_logger.rb +5 -8
- data/lib/new_relic/agent/configuration/default_source.rb +24 -0
- data/lib/new_relic/agent/cross_app_tracing.rb +21 -15
- data/lib/new_relic/agent/datastores/mongo.rb +25 -0
- data/lib/new_relic/agent/datastores/mongo/metric_generator.rb +25 -0
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +189 -0
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +39 -0
- data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +52 -0
- data/lib/new_relic/agent/harvester.rb +55 -0
- data/lib/new_relic/agent/instrumentation/mongo.rb +139 -0
- data/lib/new_relic/agent/instrumentation/net.rb +6 -11
- data/lib/new_relic/agent/supported_versions.rb +9 -5
- data/lib/new_relic/agent/transaction_sampler.rb +4 -0
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/versions.rake +1 -1
- data/test/agent_helper.rb +4 -0
- data/test/environments/norails/Gemfile +3 -0
- data/test/environments/rails40/Gemfile +5 -1
- data/test/flaky_proxy/Gemfile +3 -0
- data/test/flaky_proxy/README.md +82 -0
- data/test/flaky_proxy/lib/flaky_proxy.rb +22 -0
- data/test/flaky_proxy/lib/flaky_proxy/connection.rb +45 -0
- data/test/flaky_proxy/lib/flaky_proxy/http_message.rb +105 -0
- data/test/flaky_proxy/lib/flaky_proxy/proxy.rb +42 -0
- data/test/flaky_proxy/lib/flaky_proxy/rule.rb +75 -0
- data/test/flaky_proxy/lib/flaky_proxy/rule_set.rb +37 -0
- data/test/flaky_proxy/lib/flaky_proxy/server.rb +22 -0
- data/test/flaky_proxy/script/flaky_proxy +39 -0
- data/test/helpers/exceptions.rb +16 -0
- data/test/helpers/mongo_metric_builder.rb +29 -0
- data/test/multiverse/lib/multiverse/suite.rb +1 -0
- data/test/multiverse/suites/curb/curb_test.rb +0 -1
- data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +4 -3
- data/test/multiverse/suites/excon/excon_test.rb +0 -1
- data/test/multiverse/suites/httpclient/httpclient_test.rb +0 -1
- data/test/multiverse/suites/mongo/Envfile +66 -0
- data/test/multiverse/suites/mongo/config/newrelic.yml +19 -0
- data/test/multiverse/suites/mongo/mongo_instrumentation_test.rb +418 -0
- data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +36 -0
- data/test/multiverse/suites/net_http/net_http_test.rb +2 -4
- data/test/multiverse/suites/rails/Envfile +4 -4
- data/test/multiverse/suites/rails/config/newrelic.yml +1 -1
- data/test/multiverse/suites/rails/error_tracing_test.rb +7 -7
- data/test/multiverse/suites/sidekiq/Envfile +1 -1
- data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +0 -1
- data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +5 -3
- data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +5 -3
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +0 -1
- data/test/new_relic/agent/agent_logger_test.rb +9 -1
- data/test/new_relic/agent/agent_test.rb +66 -1
- data/test/new_relic/agent/agent_test_controller.rb +1 -2
- data/test/new_relic/agent/audit_logger_test.rb +12 -4
- data/test/new_relic/agent/configuration/orphan_configuration_test.rb +11 -2
- data/test/new_relic/agent/cpu_sampler_test.rb +1 -0
- data/test/new_relic/agent/cross_app_tracing_test.rb +60 -0
- data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +43 -0
- data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +301 -0
- data/test/new_relic/agent/datastores/mongo/obfuscator_test.rb +91 -0
- data/test/new_relic/agent/datastores/mongo/statement_formatter_test.rb +71 -0
- data/test/new_relic/agent/harvester_test.rb +85 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +5 -0
- data/test/new_relic/agent/worker_loop_test.rb +3 -5
- data/test/new_relic/http_client_test_cases.rb +65 -81
- data/test/new_relic/noticed_error_test.rb +14 -16
- data/test/performance/lib/performance.rb +1 -0
- data/test/performance/lib/performance/console_reporter.rb +6 -2
- data/test/performance/lib/performance/instrumentor.rb +1 -15
- data/test/performance/lib/performance/platform.rb +35 -0
- data/test/performance/lib/performance/test_case.rb +16 -1
- data/test/performance/suites/marshalling.rb +73 -0
- metadata +48 -19
- metadata.gz.sig +1 -2
@@ -107,6 +107,7 @@ module Multiverse
|
|
107
107
|
return unless is_rbx?
|
108
108
|
|
109
109
|
f.puts "gem 'rubysl', :platforms => [:rbx]" unless gemfile_text =~ /^\s*gem .rubysl./
|
110
|
+
f.puts "gem 'rubysl-json', :platforms => [:rbx]" unless gemfile_text =~ /^\s*gem .rubysl-json./
|
110
111
|
f.puts "gem 'racc', :platforms => [:rbx]" unless gemfile_text =~ /^\s*gem .racc./
|
111
112
|
end
|
112
113
|
|
@@ -4,12 +4,14 @@
|
|
4
4
|
|
5
5
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'sinatra', 'sinatra_test_cases'))
|
6
6
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper'))
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'helpers', 'exceptions'))
|
7
8
|
|
8
9
|
require 'newrelic_rpm'
|
9
10
|
require 'sinatra'
|
10
11
|
|
11
12
|
class DeferredSinatraTestApp < Sinatra::Base
|
12
13
|
include NewRelic::Agent::Instrumentation::Rack
|
14
|
+
include NewRelic::TestHelpers::Exceptions
|
13
15
|
|
14
16
|
configure do
|
15
17
|
# display exceptions so we see what's going on
|
@@ -45,9 +47,8 @@ class DeferredSinatraTestApp < Sinatra::Base
|
|
45
47
|
"I'm not a teapot."
|
46
48
|
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
condition { raise Error }
|
50
|
+
error(NewRelic::TestHelpers::Exceptions::TestError) { halt 200, 'nothing happened' }
|
51
|
+
condition { raise NewRelic::TestHelpers::Exceptions::TestError }
|
51
52
|
get('/error') { }
|
52
53
|
|
53
54
|
condition do
|
@@ -0,0 +1,66 @@
|
|
1
|
+
gemfile <<-RB
|
2
|
+
gem 'mongo', '1.9.2'
|
3
|
+
gem 'bson_ext', :platforms => :ruby
|
4
|
+
RB
|
5
|
+
|
6
|
+
gemfile <<-RB
|
7
|
+
gem 'mongo', '~>1.8.6'
|
8
|
+
gem 'bson_ext', :platforms => :ruby
|
9
|
+
RB
|
10
|
+
|
11
|
+
# Newest unsupported version of the driver!
|
12
|
+
gemfile <<-RB
|
13
|
+
gem 'mongo', '~>1.7.1'
|
14
|
+
gem 'bson_ext', :platforms => :ruby
|
15
|
+
RB
|
16
|
+
|
17
|
+
require 'timeout'
|
18
|
+
require 'socket'
|
19
|
+
|
20
|
+
ENV["MONGO_HOST"] = "localhost" unless ENV["MONGO_HOST"]
|
21
|
+
ENV["MONGO_PORT"] = "27017" unless ENV["MONGO_PORT"]
|
22
|
+
|
23
|
+
def mongo_running?
|
24
|
+
Timeout::timeout(1) do
|
25
|
+
begin
|
26
|
+
TCPSocket.new(ENV["MONGO_HOST"], ENV["MONGO_PORT"].to_i).close
|
27
|
+
true
|
28
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
rescue Timeout::Error
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def wait_for_mongo
|
37
|
+
Timeout::timeout(10) do
|
38
|
+
until mongo_running? do
|
39
|
+
sleep(0.1)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
before_suite do
|
45
|
+
if mongo_running?
|
46
|
+
$started_mongo = false
|
47
|
+
else
|
48
|
+
puts "Starting Mongo for you, will shut down after tests"
|
49
|
+
`mkdir -p tmp`
|
50
|
+
`mongod --port #{ENV["MONGO_PORT"]} --pidfilepath tmp/mongo.pid &`
|
51
|
+
wait_for_mongo
|
52
|
+
|
53
|
+
$started_mongo = true
|
54
|
+
puts "Mongo Mongo Mongo!"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
after_suite do
|
59
|
+
if $started_mongo
|
60
|
+
puts "Shutting down test initiated Mongo."
|
61
|
+
mongo_pid = `cat tmp/mongo.pid`
|
62
|
+
`kill -9 #{mongo_pid}`
|
63
|
+
`rm tmp/mongo.pid`
|
64
|
+
puts "Mongo Mongo Mongo!"
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
development:
|
3
|
+
error_collector:
|
4
|
+
capture_source: true
|
5
|
+
enabled: true
|
6
|
+
apdex_t: 0.5
|
7
|
+
ssl: false
|
8
|
+
monitor_mode: true
|
9
|
+
license_key: bootstrap_newrelic_admin_license_key_000
|
10
|
+
developer_mode: false
|
11
|
+
app_name: test
|
12
|
+
host: 127.0.0.1
|
13
|
+
api_host: 127.0.0.1
|
14
|
+
transaction_tracer:
|
15
|
+
record_sql: obfuscated
|
16
|
+
enabled: true
|
17
|
+
stack_trace_threshold: 0.5
|
18
|
+
transaction_threshold: 1.0
|
19
|
+
capture_params: false
|
@@ -0,0 +1,418 @@
|
|
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 'mongo'
|
6
|
+
require 'newrelic_rpm'
|
7
|
+
require 'new_relic/agent/datastores/mongo'
|
8
|
+
require 'securerandom'
|
9
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
|
10
|
+
|
11
|
+
if NewRelic::Agent::Datastores::Mongo.is_supported_version?
|
12
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'helpers', 'mongo_metric_builder')
|
13
|
+
|
14
|
+
class NewRelic::Agent::Instrumentation::MongoInstrumentationTest < MiniTest::Unit::TestCase
|
15
|
+
include Mongo
|
16
|
+
include ::NewRelic::TestHelpers::MongoMetricBuilder
|
17
|
+
|
18
|
+
def client
|
19
|
+
MongoClient.new(ENV["MONGO_HOST"], ENV["MONGO_PORT"].to_i)
|
20
|
+
end
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@client = client
|
24
|
+
@database_name = 'multiverse'
|
25
|
+
@database = @client.db(@database_name)
|
26
|
+
@collection_name = 'tribbles'
|
27
|
+
@collection = @database.collection(@collection_name)
|
28
|
+
|
29
|
+
@tribble = {'name' => 'soterios johnson'}
|
30
|
+
|
31
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
|
32
|
+
NewRelic::Agent.drop_buffered_data
|
33
|
+
end
|
34
|
+
|
35
|
+
def teardown
|
36
|
+
NewRelic::Agent.drop_buffered_data
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_records_metrics_for_insert
|
40
|
+
@collection.insert(@tribble)
|
41
|
+
|
42
|
+
metrics = build_test_metrics(:insert)
|
43
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
44
|
+
|
45
|
+
assert_metrics_recorded(expected)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_records_metrics_for_find
|
49
|
+
@collection.insert(@tribble)
|
50
|
+
NewRelic::Agent.drop_buffered_data
|
51
|
+
|
52
|
+
@collection.find(@tribble).to_a
|
53
|
+
|
54
|
+
metrics = build_test_metrics(:find)
|
55
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
56
|
+
|
57
|
+
assert_metrics_recorded(expected)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_records_metrics_for_find_one
|
61
|
+
@collection.insert(@tribble)
|
62
|
+
NewRelic::Agent.drop_buffered_data
|
63
|
+
|
64
|
+
@collection.find_one
|
65
|
+
|
66
|
+
metrics = build_test_metrics(:findOne)
|
67
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
68
|
+
|
69
|
+
assert_metrics_recorded(expected)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_records_metrics_for_remove
|
73
|
+
@collection.insert(@tribble)
|
74
|
+
NewRelic::Agent.drop_buffered_data
|
75
|
+
|
76
|
+
@collection.remove(@tribble).to_a
|
77
|
+
|
78
|
+
metrics = build_test_metrics(:remove)
|
79
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
80
|
+
|
81
|
+
assert_metrics_recorded(expected)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_records_metrics_for_save
|
85
|
+
@collection.save(@tribble)
|
86
|
+
|
87
|
+
metrics = build_test_metrics(:save)
|
88
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
89
|
+
|
90
|
+
assert_metrics_recorded(expected)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_save_does_not_record_insert
|
94
|
+
@collection.save(@tribble)
|
95
|
+
|
96
|
+
metrics = build_test_metrics(:save)
|
97
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
98
|
+
|
99
|
+
assert_metrics_not_recorded(['Datastore/operation/MongoDB/insert'])
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_records_metrics_for_update
|
103
|
+
updated = @tribble.dup
|
104
|
+
updated['name'] = 'codemonkey'
|
105
|
+
|
106
|
+
@collection.update(@tribble, updated)
|
107
|
+
|
108
|
+
metrics = build_test_metrics(:update)
|
109
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
110
|
+
|
111
|
+
assert_metrics_recorded(expected)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_records_metrics_for_distinct
|
115
|
+
@collection.distinct('name')
|
116
|
+
|
117
|
+
metrics = build_test_metrics(:distinct)
|
118
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
119
|
+
|
120
|
+
assert_metrics_recorded(expected)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_records_metrics_for_count
|
124
|
+
@collection.count
|
125
|
+
|
126
|
+
metrics = build_test_metrics(:count)
|
127
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
128
|
+
|
129
|
+
assert_metrics_recorded(expected)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_records_metrics_for_group
|
133
|
+
@collection.group({:key => "name",
|
134
|
+
:initial => {:count => 0},
|
135
|
+
:reduce => "function(k,v) { v.count += 1; }" })
|
136
|
+
|
137
|
+
metrics = build_test_metrics(:group)
|
138
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
139
|
+
|
140
|
+
assert_metrics_recorded(expected)
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_records_metrics_for_find_and_modify
|
144
|
+
updated = @tribble.dup
|
145
|
+
updated['name'] = 'codemonkey'
|
146
|
+
@collection.find_and_modify(:query => @tribble, :update => updated)
|
147
|
+
|
148
|
+
metrics = build_test_metrics(:findAndModify)
|
149
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
150
|
+
|
151
|
+
assert_metrics_recorded(expected)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_records_metrics_for_find_and_remove
|
155
|
+
@collection.find_and_modify(:query => @tribble, :remove =>true)
|
156
|
+
|
157
|
+
metrics = build_test_metrics(:findAndRemove)
|
158
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
159
|
+
|
160
|
+
assert_metrics_recorded(expected)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_records_metrics_for_create_index
|
164
|
+
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
165
|
+
|
166
|
+
metrics = build_test_metrics(:createIndex)
|
167
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
168
|
+
|
169
|
+
assert_metrics_recorded(expected)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_records_metrics_for_ensure_index
|
173
|
+
@collection.ensure_index({unique_field_name => Mongo::ASCENDING})
|
174
|
+
|
175
|
+
metrics = build_test_metrics(:ensureIndex)
|
176
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
177
|
+
|
178
|
+
assert_metrics_recorded(expected)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_ensure_index_does_not_record_insert
|
182
|
+
@collection.ensure_index({unique_field_name => Mongo::ASCENDING})
|
183
|
+
|
184
|
+
assert_metrics_not_recorded(['Datastore/operation/MongoDB/insert'])
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_records_metrics_for_drop_index
|
188
|
+
name = @collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
189
|
+
NewRelic::Agent.drop_buffered_data
|
190
|
+
|
191
|
+
@collection.drop_index(name)
|
192
|
+
|
193
|
+
metrics = build_test_metrics(:dropIndex)
|
194
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
195
|
+
|
196
|
+
assert_metrics_recorded(expected)
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_records_metrics_for_drop_indexes
|
200
|
+
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
201
|
+
NewRelic::Agent.drop_buffered_data
|
202
|
+
|
203
|
+
@collection.drop_indexes
|
204
|
+
|
205
|
+
metrics = build_test_metrics(:dropIndexes)
|
206
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
207
|
+
|
208
|
+
assert_metrics_recorded(expected)
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_records_metrics_for_reindex
|
212
|
+
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
213
|
+
NewRelic::Agent.drop_buffered_data
|
214
|
+
|
215
|
+
@database.command({ :reIndex => @collection_name })
|
216
|
+
|
217
|
+
metrics = build_test_metrics(:reIndex)
|
218
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
219
|
+
|
220
|
+
assert_metrics_recorded(expected)
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_rename_collection
|
224
|
+
with_unique_collection do
|
225
|
+
@collection.rename("renamed_#{@collection_name}")
|
226
|
+
|
227
|
+
metrics = build_test_metrics(:renameCollection)
|
228
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
229
|
+
|
230
|
+
assert_metrics_recorded(expected)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_rename_collection_via_db
|
235
|
+
with_unique_collection do
|
236
|
+
@database.rename_collection(@collection_name, "renamed_#{@collection_name}")
|
237
|
+
|
238
|
+
metrics = build_test_metrics(:renameCollection)
|
239
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
240
|
+
|
241
|
+
assert_metrics_recorded(expected)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_drop_collection
|
246
|
+
with_unique_collection do
|
247
|
+
@database.drop_collection(@collection_name)
|
248
|
+
|
249
|
+
metrics = build_test_metrics(:drop)
|
250
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
251
|
+
|
252
|
+
assert_metrics_recorded(expected)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_collstats
|
257
|
+
@collection.stats
|
258
|
+
|
259
|
+
metrics = build_test_metrics(:collstats)
|
260
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
261
|
+
|
262
|
+
assert_metrics_recorded(expected)
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_notices_nosql
|
266
|
+
segment = nil
|
267
|
+
|
268
|
+
in_transaction do
|
269
|
+
@collection.insert(@tribble)
|
270
|
+
segment = find_last_transaction_segment
|
271
|
+
end
|
272
|
+
|
273
|
+
expected = { :database => 'multiverse',
|
274
|
+
:collection => 'tribbles',
|
275
|
+
:operation => :insert}
|
276
|
+
|
277
|
+
result = segment.params[:statement]
|
278
|
+
|
279
|
+
assert_equal expected, result, "Expected result (#{result}) to be #{expected}"
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_noticed_nosql_includes_operation
|
283
|
+
segment = nil
|
284
|
+
|
285
|
+
in_transaction do
|
286
|
+
@collection.insert(@tribble)
|
287
|
+
segment = find_last_transaction_segment
|
288
|
+
end
|
289
|
+
|
290
|
+
expected = :insert
|
291
|
+
|
292
|
+
query = segment.params[:statement]
|
293
|
+
result = query[:operation]
|
294
|
+
|
295
|
+
assert_equal expected, result
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_noticed_nosql_includes_save_operation
|
299
|
+
segment = nil
|
300
|
+
|
301
|
+
in_transaction do
|
302
|
+
@collection.save(@tribble)
|
303
|
+
segment = find_last_transaction_segment
|
304
|
+
end
|
305
|
+
|
306
|
+
expected = :save
|
307
|
+
|
308
|
+
query = segment.params[:statement]
|
309
|
+
result = query[:operation]
|
310
|
+
|
311
|
+
assert_equal expected, result
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_noticed_nosql_includes_ensure_index_operation
|
315
|
+
segment = nil
|
316
|
+
|
317
|
+
in_transaction do
|
318
|
+
@collection.ensure_index({unique_field_name => Mongo::ASCENDING})
|
319
|
+
segment = find_last_transaction_segment
|
320
|
+
end
|
321
|
+
|
322
|
+
expected = :ensureIndex
|
323
|
+
|
324
|
+
query = segment.params[:statement]
|
325
|
+
result = query[:operation]
|
326
|
+
|
327
|
+
assert_equal expected, result
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_noticed_nosql_does_not_contain_documents
|
331
|
+
segment = nil
|
332
|
+
|
333
|
+
in_transaction do
|
334
|
+
@collection.insert({'name' => 'soterios johnson'})
|
335
|
+
segment = find_last_transaction_segment
|
336
|
+
end
|
337
|
+
|
338
|
+
statement = segment.params[:statement]
|
339
|
+
|
340
|
+
refute statement.keys.include?(:documents), "Noticed NoSQL should not include documents: #{statement}"
|
341
|
+
end
|
342
|
+
|
343
|
+
def test_noticed_nosql_does_not_contain_selector_values
|
344
|
+
@collection.insert({'password' => '$ecret'})
|
345
|
+
segment = nil
|
346
|
+
|
347
|
+
in_transaction do
|
348
|
+
@collection.remove({'password' => '$ecret'})
|
349
|
+
segment = find_last_transaction_segment
|
350
|
+
end
|
351
|
+
|
352
|
+
statement = segment.params[:statement]
|
353
|
+
|
354
|
+
assert_equal '?', statement[:selector]['password']
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_web_requests_record_all_web_metric
|
358
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
|
359
|
+
@collection.insert(@tribble)
|
360
|
+
|
361
|
+
metrics = build_test_metrics(:insert)
|
362
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
363
|
+
|
364
|
+
assert_metrics_recorded(expected)
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_web_requests_do_not_record_all_other_metric
|
368
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
|
369
|
+
@collection.insert(@tribble)
|
370
|
+
|
371
|
+
assert_metrics_not_recorded(['Datastore/allOther'])
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_other_requests_record_all_other_metric
|
375
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
|
376
|
+
@collection.insert(@tribble)
|
377
|
+
|
378
|
+
metrics = build_test_metrics(:insert, :other)
|
379
|
+
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
380
|
+
|
381
|
+
assert_metrics_recorded(expected)
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_other_requests_do_not_record_all_web_metric
|
385
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
|
386
|
+
@collection.insert(@tribble)
|
387
|
+
|
388
|
+
assert_metrics_not_recorded(['Datastore/allWeb'])
|
389
|
+
end
|
390
|
+
|
391
|
+
def with_unique_collection
|
392
|
+
original_collection_name = @collection_name
|
393
|
+
original_collection = @collection
|
394
|
+
|
395
|
+
@collection_name = "coll#{SecureRandom.hex(10)}"
|
396
|
+
@collection = @database.collection(@collection_name)
|
397
|
+
|
398
|
+
# Insert to make sure the collection actually exists...
|
399
|
+
@collection.insert({:junk => "data"})
|
400
|
+
NewRelic::Agent.drop_buffered_data
|
401
|
+
|
402
|
+
yield
|
403
|
+
ensure
|
404
|
+
@collection_name = original_collection_name
|
405
|
+
@collection = original_collection
|
406
|
+
end
|
407
|
+
|
408
|
+
def unique_field_name
|
409
|
+
"field#{SecureRandom.hex(10)}"
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
class NewRelic::Agent::Instrumentation::MongoConnectionTest < NewRelic::Agent::Instrumentation::MongoInstrumentationTest
|
414
|
+
def client
|
415
|
+
Mongo::Connection.new(ENV["MONGO_HOST"], ENV["MONGO_PORT"].to_i)
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|