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.
Files changed (77) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +28 -1
  3. data/lib/new_relic/agent.rb +1 -2
  4. data/lib/new_relic/agent/agent.rb +28 -10
  5. data/lib/new_relic/agent/agent_logger.rb +4 -3
  6. data/lib/new_relic/agent/audit_logger.rb +5 -8
  7. data/lib/new_relic/agent/configuration/default_source.rb +24 -0
  8. data/lib/new_relic/agent/cross_app_tracing.rb +21 -15
  9. data/lib/new_relic/agent/datastores/mongo.rb +25 -0
  10. data/lib/new_relic/agent/datastores/mongo/metric_generator.rb +25 -0
  11. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +189 -0
  12. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +39 -0
  13. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +52 -0
  14. data/lib/new_relic/agent/harvester.rb +55 -0
  15. data/lib/new_relic/agent/instrumentation/mongo.rb +139 -0
  16. data/lib/new_relic/agent/instrumentation/net.rb +6 -11
  17. data/lib/new_relic/agent/supported_versions.rb +9 -5
  18. data/lib/new_relic/agent/transaction_sampler.rb +4 -0
  19. data/lib/new_relic/version.rb +1 -1
  20. data/lib/tasks/versions.rake +1 -1
  21. data/test/agent_helper.rb +4 -0
  22. data/test/environments/norails/Gemfile +3 -0
  23. data/test/environments/rails40/Gemfile +5 -1
  24. data/test/flaky_proxy/Gemfile +3 -0
  25. data/test/flaky_proxy/README.md +82 -0
  26. data/test/flaky_proxy/lib/flaky_proxy.rb +22 -0
  27. data/test/flaky_proxy/lib/flaky_proxy/connection.rb +45 -0
  28. data/test/flaky_proxy/lib/flaky_proxy/http_message.rb +105 -0
  29. data/test/flaky_proxy/lib/flaky_proxy/proxy.rb +42 -0
  30. data/test/flaky_proxy/lib/flaky_proxy/rule.rb +75 -0
  31. data/test/flaky_proxy/lib/flaky_proxy/rule_set.rb +37 -0
  32. data/test/flaky_proxy/lib/flaky_proxy/server.rb +22 -0
  33. data/test/flaky_proxy/script/flaky_proxy +39 -0
  34. data/test/helpers/exceptions.rb +16 -0
  35. data/test/helpers/mongo_metric_builder.rb +29 -0
  36. data/test/multiverse/lib/multiverse/suite.rb +1 -0
  37. data/test/multiverse/suites/curb/curb_test.rb +0 -1
  38. data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +4 -3
  39. data/test/multiverse/suites/excon/excon_test.rb +0 -1
  40. data/test/multiverse/suites/httpclient/httpclient_test.rb +0 -1
  41. data/test/multiverse/suites/mongo/Envfile +66 -0
  42. data/test/multiverse/suites/mongo/config/newrelic.yml +19 -0
  43. data/test/multiverse/suites/mongo/mongo_instrumentation_test.rb +418 -0
  44. data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +36 -0
  45. data/test/multiverse/suites/net_http/net_http_test.rb +2 -4
  46. data/test/multiverse/suites/rails/Envfile +4 -4
  47. data/test/multiverse/suites/rails/config/newrelic.yml +1 -1
  48. data/test/multiverse/suites/rails/error_tracing_test.rb +7 -7
  49. data/test/multiverse/suites/sidekiq/Envfile +1 -1
  50. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +0 -1
  51. data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +5 -3
  52. data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +5 -3
  53. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +0 -1
  54. data/test/new_relic/agent/agent_logger_test.rb +9 -1
  55. data/test/new_relic/agent/agent_test.rb +66 -1
  56. data/test/new_relic/agent/agent_test_controller.rb +1 -2
  57. data/test/new_relic/agent/audit_logger_test.rb +12 -4
  58. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +11 -2
  59. data/test/new_relic/agent/cpu_sampler_test.rb +1 -0
  60. data/test/new_relic/agent/cross_app_tracing_test.rb +60 -0
  61. data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +43 -0
  62. data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +301 -0
  63. data/test/new_relic/agent/datastores/mongo/obfuscator_test.rb +91 -0
  64. data/test/new_relic/agent/datastores/mongo/statement_formatter_test.rb +71 -0
  65. data/test/new_relic/agent/harvester_test.rb +85 -0
  66. data/test/new_relic/agent/transaction_sampler_test.rb +5 -0
  67. data/test/new_relic/agent/worker_loop_test.rb +3 -5
  68. data/test/new_relic/http_client_test_cases.rb +65 -81
  69. data/test/new_relic/noticed_error_test.rb +14 -16
  70. data/test/performance/lib/performance.rb +1 -0
  71. data/test/performance/lib/performance/console_reporter.rb +6 -2
  72. data/test/performance/lib/performance/instrumentor.rb +1 -15
  73. data/test/performance/lib/performance/platform.rb +35 -0
  74. data/test/performance/lib/performance/test_case.rb +16 -1
  75. data/test/performance/suites/marshalling.rb +73 -0
  76. metadata +48 -19
  77. metadata.gz.sig +1 -2
@@ -0,0 +1,43 @@
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.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
6
+ require 'new_relic/agent/datastores/mongo/metric_generator'
7
+
8
+ class NewRelic::Agent::Datastores::Mongo::MetricGeneratorTest < Test::Unit::TestCase
9
+ include ::NewRelic::TestHelpers::MongoMetricBuilder
10
+
11
+ def setup
12
+ @payload = { :collection => 'tribbles' }
13
+ end
14
+
15
+ def test_generate_metrics_for_includes_all_web_for_web_requests
16
+ NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
17
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_metrics_for(:insert, @payload)
18
+
19
+ assert_includes metrics, 'Datastore/allWeb'
20
+ end
21
+
22
+ def test_generate_metrics_for_does_not_include_all_other_for_web_requests
23
+ NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
24
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_metrics_for(:insert, @payload)
25
+
26
+ refute metrics.include? 'Datastore/allOther'
27
+ end
28
+
29
+ def test_generate_metrics_for_includes_all_other_for_other_requests
30
+ NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
31
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_metrics_for(:insert, @payload)
32
+
33
+ assert_includes metrics, 'Datastore/allOther'
34
+ end
35
+
36
+ def test_generate_metrics_for_does_not_include_all_web_for_other_requests
37
+ NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
38
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_metrics_for(:insert, @payload)
39
+
40
+ refute metrics.include? 'Datastore/allWeb'
41
+ end
42
+
43
+ end
@@ -0,0 +1,301 @@
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 'new_relic/agent/datastores/mongo/metric_translator'
6
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
7
+
8
+ class NewRelic::Agent::Datastores::Mongo::MetricTranslatorTest < Test::Unit::TestCase
9
+ include ::NewRelic::TestHelpers::MongoMetricBuilder
10
+
11
+ def setup
12
+ @database_name = 'multiverse'
13
+ @collection_name = 'tribbles'
14
+ end
15
+
16
+ def test_metrics_for_insert
17
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:insert, { :collection => @collection_name })
18
+ expected = build_test_metrics(:insert)
19
+
20
+ assert_equal expected, metrics
21
+ end
22
+
23
+ def test_build_metrics_includes_web
24
+ expected = 'Datastore/allWeb'
25
+ metrics = build_test_metrics('test')
26
+
27
+ assert metrics.include? expected
28
+ end
29
+
30
+ def test_build_metrics_includes_other
31
+ expected = 'Datastore/allOther'
32
+ metrics = build_test_metrics('test', :other)
33
+
34
+ assert metrics.include? expected
35
+ end
36
+
37
+ def test_metrics_for_find
38
+ payload = { :database => @database_name,
39
+ :collection => @collection_name,
40
+ :selector => { "name" => "soterios johnson" } }
41
+
42
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
43
+ expected = build_test_metrics(:find)
44
+
45
+ assert_equal expected, metrics
46
+ end
47
+
48
+ def test_metrics_for_find_one
49
+ payload = { :database => @database_name,
50
+ :collection => @collection_name,
51
+ :selector => {},
52
+ :limit => -1 }
53
+
54
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
55
+ expected = build_test_metrics(:findOne)
56
+
57
+ assert_equal expected, metrics
58
+ end
59
+
60
+ def test_metrics_for_remove
61
+ payload = { :database => @database_name,
62
+ :collection => @collection_name,
63
+ :selector => { "name" => "soterios johnson" } }
64
+
65
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:remove, payload)
66
+ expected = build_test_metrics(:remove)
67
+
68
+ assert_equal expected, metrics
69
+ end
70
+
71
+ def test_metrics_for_update
72
+ payload = { :database => @database_name,
73
+ :collection => @collection_name,
74
+ :selector => { "name" => "soterios johnson" },
75
+ :document => { "name" => "codemonkey" } }
76
+
77
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:update, payload)
78
+ expected = build_test_metrics(:update)
79
+
80
+ assert_equal expected, metrics
81
+ end
82
+
83
+ def test_metrics_for_distinct
84
+ payload = { :database => @database_name,
85
+ :collection => "$cmd",
86
+ :limit => -1,
87
+ :selector => { :distinct => @collection_name,
88
+ :key => "name",
89
+ :query => nil } }
90
+
91
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:distinct, payload)
92
+ expected = build_test_metrics(:distinct)
93
+
94
+ assert_equal expected, metrics
95
+ end
96
+
97
+ def test_metrics_for_count
98
+ payload = { :database => @database_name,
99
+ :collection => "$cmd",
100
+ :limit => -1,
101
+ :selector => { "count" => @collection_name,
102
+ "query" => {},
103
+ "fields" => nil } }
104
+
105
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
106
+ expected = build_test_metrics(:count)
107
+
108
+ assert_equal expected, metrics
109
+ end
110
+
111
+ def test_metrics_for_group
112
+ payload = { :database => @database_name,
113
+ :collection => "$cmd",
114
+ :limit => -1,
115
+ :selector => { "group" => { "ns" => @collection_name,
116
+ "$reduce" => stub("BSON::Code"),
117
+ "cond" => {},
118
+ "initial" => {:count=>0},
119
+ "key" => {"name"=>1}}}}
120
+
121
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
122
+ expected = build_test_metrics(:group)
123
+
124
+ assert_equal expected, metrics
125
+ end
126
+
127
+ def test_metrics_for_aggregate
128
+ payload = { :database => @database_name,
129
+ :collection => "$cmd",
130
+ :limit => -1,
131
+ :selector => { "aggregate" => @collection_name,
132
+ "pipeline" => [{"$group" => {:_id => "$says", :total => {"$sum" => 1}}}]}}
133
+
134
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
135
+ expected = build_test_metrics(:aggregate)
136
+
137
+ assert_equal expected, metrics
138
+ end
139
+
140
+ def test_metrics_for_mapreduce
141
+ payload = { :database => @database_name,
142
+ :collection => "$cmd",
143
+ :limit => -1,
144
+ :selector => { "mapreduce" => @collection_name,
145
+ "map" => stub("BSON::Code"),
146
+ "reduce" => stub("BSON::Code"),
147
+ :out => "results"}}
148
+
149
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
150
+ expected = build_test_metrics(:mapreduce)
151
+
152
+ assert_equal expected, metrics
153
+ end
154
+
155
+
156
+ def test_metrics_for_find_and_modify
157
+ payload = { :database => @database_name,
158
+ :collection => "$cmd",
159
+ :limit => -1,
160
+ :selector => { :findandmodify => @collection_name,
161
+ :query => { "name" => "soterios johnson" },
162
+ :update => {"name" => "codemonkey" } } }
163
+
164
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
165
+ expected = build_test_metrics(:findAndModify)
166
+
167
+ assert_equal expected, metrics
168
+ end
169
+
170
+ def test_metrics_for_find_and_remove
171
+ payload = { :database => @database_name,
172
+ :collection => "$cmd",
173
+ :limit => -1,
174
+ :selector => { :findandmodify => @collection_name,
175
+ :query => { "name" => "soterios johnson" },
176
+ :remove => true } }
177
+
178
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
179
+ expected = build_test_metrics(:findAndRemove)
180
+
181
+ assert_equal expected, metrics
182
+ end
183
+
184
+ def test_metrics_for_create_index
185
+ payload = { :database => @database_name,
186
+ :collection => "system.indexes",
187
+ :documents => [ { :name => "name_1",
188
+ :ns => "#{@database_name}.#{@collection_name}",
189
+ :key => { "name" => 1 } } ] }
190
+
191
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:insert, payload)
192
+ expected = build_test_metrics(:createIndex)
193
+
194
+ assert_equal expected, metrics
195
+ end
196
+
197
+ def test_metrics_for_drop_indexes
198
+ payload = { :database => @database_name,
199
+ :collection => "$cmd",
200
+ :limit => -1,
201
+ :selector => { :deleteIndexes => @collection_name,
202
+ :index => "*" } }
203
+
204
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
205
+ expected = build_test_metrics(:dropIndexes)
206
+
207
+ assert_equal expected, metrics
208
+ end
209
+
210
+ def test_metrics_for_drop_index
211
+ payload = { :database => @database_name,
212
+ :collection => "$cmd",
213
+ :limit => -1,
214
+ :selector => { :deleteIndexes => @collection_name,
215
+ :index => "name_1" } }
216
+
217
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
218
+ expected = build_test_metrics(:dropIndex)
219
+
220
+ assert_equal expected, metrics
221
+ end
222
+
223
+ def test_metrics_for_reindex
224
+ payload = { :database => @database_name,
225
+ :collection => "$cmd",
226
+ :limit => -1,
227
+ :selector => { :reIndex=> @collection_name } }
228
+
229
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
230
+ expected = build_test_metrics(:reIndex)
231
+
232
+ assert_equal expected, metrics
233
+ end
234
+
235
+ def test_metrics_for_drop_collection
236
+ payload = { :database => @database_name,
237
+ :collection =>"$cmd",
238
+ :limit => -1,
239
+ :selector => { :drop => @collection_name } }
240
+
241
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
242
+ expected = build_test_metrics(:drop)
243
+
244
+ assert_equal expected, metrics
245
+ end
246
+
247
+ def test_metrics_for_rename_collection
248
+ payload = { :database => @database_name,
249
+ :collection => "$cmd",
250
+ :limit => -1,
251
+ :selector => { :renameCollection => "#{@database_name}.#{@collection_name}",
252
+ :to=>"#{@database_name}.renamed_#{@collection_name}" } }
253
+
254
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
255
+ expected = build_test_metrics(:renameCollection)
256
+
257
+ assert_equal expected, metrics
258
+ end
259
+
260
+ def test_metrics_for_ismaster
261
+ payload = { :database => @database_name,
262
+ :collection => "$cmd",
263
+ :limit => -1,
264
+ :selector => { :ismaster => 1 } }
265
+
266
+ @collection_name = "1"
267
+
268
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
269
+ expected = build_test_metrics(:ismaster)
270
+
271
+ assert_equal expected, metrics
272
+ end
273
+
274
+ def test_metrics_for_collstats
275
+ payload = { :database => @database_name,
276
+ :collection =>"$cmd",
277
+ :limit => -1,
278
+ :selector => { :collstats => @collection_name } }
279
+
280
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
281
+ expected = build_test_metrics(:collstats)
282
+
283
+ assert_equal expected, metrics
284
+ end
285
+
286
+ def test_metrics_for_unknown_command
287
+ payload = { :database => @database_name,
288
+ :collection => "$cmd",
289
+ :limit => -1,
290
+ :selector => { :mongomongomongo => @collection_name } }
291
+
292
+ @collection_name = "UnknownCollection"
293
+
294
+ metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
295
+ expected = build_test_metrics(:UnknownCommand)
296
+
297
+ assert_equal expected, metrics
298
+ assert_metrics_recorded(["Supportability/Mongo/UnknownCommand"])
299
+ end
300
+
301
+ end
@@ -0,0 +1,91 @@
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 'new_relic/agent/datastores/mongo/obfuscator'
6
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
7
+
8
+ module NewRelic
9
+ module Agent
10
+ module Datastores
11
+ module Mongo
12
+ class ObfuscatorTest < Test::Unit::TestCase
13
+ def test_obfuscator_removes_values_from_statement
14
+ selector = {
15
+ 'name' => 'soterios johnson',
16
+ :operation => :find,
17
+ :_id => "BSON::ObjectId('?')"
18
+ }
19
+
20
+ expected = {
21
+ 'name' => '?',
22
+ :operation => :find,
23
+ :_id => '?'
24
+ }
25
+
26
+ obfuscated = Obfuscator.obfuscate_statement(selector)
27
+ assert_equal expected, obfuscated
28
+ end
29
+
30
+ def test_obfuscate_selector_values_skips_whitelisted_keys
31
+ selector = {
32
+ :benign => 'bland data',
33
+ :operation => :find,
34
+ :_id => "BSON::ObjectId('?')"
35
+ }
36
+
37
+ expected = {
38
+ :benign => 'bland data',
39
+ :operation => :find,
40
+ :_id => '?'
41
+ }
42
+
43
+ obfuscated = Obfuscator.obfuscate_statement(selector, [:benign, :operation])
44
+ assert_equal expected, obfuscated
45
+ end
46
+
47
+ def test_obfuscate_nested_hashes
48
+ selector = {
49
+ "group" => {
50
+ "ns" => "tribbles",
51
+ "$reduce" => stub("BSON::Code"),
52
+ "cond" => {},
53
+ "initial" => { :count => 0 },
54
+ "key" => { "name" => 1 }
55
+ }
56
+ }
57
+
58
+ expected = {
59
+ "group" => {
60
+ "ns" => "?",
61
+ "$reduce" => "?",
62
+ "cond" => {},
63
+ "initial" => { :count => "?" },
64
+ "key" => { "name" => "?" }
65
+ }
66
+ }
67
+
68
+ obfuscated = Obfuscator.obfuscate_statement(selector)
69
+ assert_equal expected, obfuscated
70
+ end
71
+
72
+ def test_obfuscate_nested_arrays
73
+ selector = {
74
+ "aggregate" => "mongeese",
75
+ "pipeline" => [{"$group"=>{:_id=>"$says", :total=>{"$sum"=>1}}}]
76
+ }
77
+
78
+ expected = {
79
+ "aggregate" => "?",
80
+ "pipeline" => [{"$group"=>{:_id=>"?", :total=>{"$sum"=>"?"}}}]
81
+ }
82
+
83
+ obfuscated = Obfuscator.obfuscate_statement(selector)
84
+ assert_equal expected, obfuscated
85
+ end
86
+
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,71 @@
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.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
6
+ require 'new_relic/agent/datastores/mongo/statement_formatter'
7
+
8
+ module NewRelic
9
+ module Agent
10
+ module Datastores
11
+ module Mongo
12
+ class StatementFormatterTest < Test::Unit::TestCase
13
+ DOC_STATEMENT = { :database => "multiverse",
14
+ :collection => "tribbles",
15
+ :operation => :insert,
16
+ :fields => ["field_name"],
17
+ :skip => 1,
18
+ :limit => -1,
19
+ :order => :ascending,
20
+
21
+ :ignored => "we're whitelisted!",
22
+ :documents => [ { "name" => "soterios johnson",
23
+ :_id => "BSON::ObjectId()" } ] }.freeze
24
+
25
+
26
+ SELECTOR_STATEMENT = { :database => 'multiverse',
27
+ :collection => 'tribbles',
28
+ :selector => { 'name' => 'soterios johnson',
29
+ :operation => :find,
30
+ :_id => "BSON::ObjectId('?')" } }.freeze
31
+
32
+ def test_doesnt_modify_incoming_statement
33
+ formatted = StatementFormatter.format(DOC_STATEMENT)
34
+ assert_not_same DOC_STATEMENT, formatted
35
+ end
36
+
37
+ def test_statement_formatter_removes_unwhitelisted_keys
38
+ formatted = StatementFormatter.format(DOC_STATEMENT)
39
+ assert_equal_unordered(formatted.keys, StatementFormatter::PLAINTEXT_KEYS)
40
+ end
41
+
42
+ def test_can_disable_statement_capturing_queries
43
+ with_config(:'mongo.capture_queries' => false) do
44
+ formatted = StatementFormatter.format(DOC_STATEMENT)
45
+ assert_nil formatted
46
+ end
47
+ end
48
+
49
+ def test_statement_formatter_obfuscates_by_default
50
+ expected = { :database => 'multiverse',
51
+ :collection => 'tribbles',
52
+ :selector => { 'name' => '?',
53
+ :operation => :find,
54
+ :_id => '?' } }
55
+
56
+ result = StatementFormatter.format(SELECTOR_STATEMENT)
57
+ assert_equal expected, result
58
+ end
59
+
60
+ def test_statement_formatter_raw_selectors
61
+ with_config(:'mongo.obfuscate_queries' => false) do
62
+ result = StatementFormatter.format(SELECTOR_STATEMENT)
63
+ assert_equal SELECTOR_STATEMENT, result
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end