newrelic_rpm 3.12.1.298 → 3.13.0.299
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +37 -0
- data/GUIDELINES_FOR_CONTRIBUTING.md +1 -1
- data/LICENSE +4 -4
- data/README.md +3 -3
- data/lib/new_relic/agent/agent.rb +27 -0
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +2 -0
- data/lib/new_relic/agent/configuration/default_source.rb +51 -1
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
- data/lib/new_relic/agent/database.rb +12 -2
- data/lib/new_relic/agent/database/obfuscator.rb +4 -3
- data/lib/new_relic/agent/datastores.rb +1 -1
- data/lib/new_relic/agent/datastores/redis.rb +131 -0
- data/lib/new_relic/agent/error_collector.rb +2 -2
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +2 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -0
- data/lib/new_relic/agent/instrumentation/rake.rb +170 -0
- data/lib/new_relic/agent/instrumentation/redis.rb +71 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -0
- data/lib/new_relic/agent/new_relic_service.rb +4 -0
- data/lib/new_relic/agent/sql_sampler.rb +14 -13
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -0
- data/lib/new_relic/agent/transaction.rb +2 -0
- data/lib/new_relic/agent/transaction/attributes.rb +1 -1
- data/lib/new_relic/agent/transaction/trace.rb +2 -1
- data/lib/new_relic/agent/transaction/trace_node.rb +3 -2
- data/lib/new_relic/agent/transaction_sampler.rb +4 -15
- data/lib/new_relic/agent/transaction_state.rb +1 -0
- data/lib/new_relic/agent/vm/rubinius_vm.rb +27 -19
- data/lib/new_relic/language_support.rb +7 -0
- data/lib/new_relic/version.rb +2 -2
- data/lib/tasks/newrelic.rb +9 -0
- data/newrelic_rpm.gemspec +1 -1
- data/test/multiverse/README.md +1 -1
- data/test/multiverse/lib/multiverse/runner.rb +2 -2
- data/test/multiverse/suites/active_record/active_record_test.rb +6 -6
- data/test/multiverse/suites/agent_only/agent_attributes_test.rb +11 -0
- data/test/multiverse/suites/agent_only/script/warnings.rb +15 -0
- data/test/multiverse/suites/agent_only/start_up_test.rb +12 -4
- data/test/multiverse/suites/rake/Envfile +37 -0
- data/test/multiverse/suites/rake/Rakefile +54 -0
- data/test/multiverse/suites/rake/config/newrelic.yml +18 -0
- data/test/multiverse/suites/rake/multitask_test.rb +40 -0
- data/test/multiverse/suites/rake/rake_test.rb +209 -0
- data/test/multiverse/suites/rake/rake_test_helper.rb +66 -0
- data/test/multiverse/suites/rake/unsupported_rake_test.rb +19 -0
- data/test/multiverse/suites/redis/Envfile +14 -0
- data/test/multiverse/suites/redis/config/newrelic.yml +19 -0
- data/test/multiverse/suites/redis/redis_instrumentation_test.rb +212 -0
- data/test/multiverse/suites/redis/redis_unsupported_version_test.rb +20 -0
- data/test/multiverse/suites/resque/resque_marshalling_test.rb +9 -1
- data/test/new_relic/agent/agent_test.rb +78 -1
- data/test/new_relic/agent/configuration/high_security_source_test.rb +9 -0
- data/test/new_relic/agent/database/sql_obfuscation_test.rb +1 -3
- data/test/new_relic/agent/datastores/redis_test.rb +128 -0
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +1 -1
- data/test/new_relic/agent/sql_sampler_test.rb +64 -52
- data/test/new_relic/agent/transaction/trace_node_test.rb +1 -1
- data/test/new_relic/agent/transaction/trace_test.rb +1 -1
- data/test/new_relic/agent/transaction_sampler_test.rb +9 -11
- data/test/new_relic/agent/vm/rubinius_vm_test.rb +1 -1
- data/test/new_relic/fake_collector.rb +18 -1
- data/test/new_relic/multiverse_helpers.rb +6 -0
- data/test/performance/suites/redis.rb +45 -0
- data/ui/views/newrelic/_sql_row.rhtml +1 -1
- data/ui/views/newrelic/explain_sql.rhtml +1 -1
- metadata +21 -5
@@ -79,5 +79,14 @@ module NewRelic::Agent::Configuration
|
|
79
79
|
HighSecuritySource.new(local_settings)
|
80
80
|
end
|
81
81
|
|
82
|
+
def test_forces_redis_argument_recording_off
|
83
|
+
local_settings = {
|
84
|
+
:'transaction_tracer.record_redis_arguments' => true
|
85
|
+
}
|
86
|
+
|
87
|
+
source = HighSecuritySource.new(local_settings)
|
88
|
+
|
89
|
+
assert_equal(false, source[:'transaction_tracer.record_redis_arguments'])
|
90
|
+
end
|
82
91
|
end
|
83
92
|
end
|
@@ -13,9 +13,7 @@ module NewRelic::Agent::Database
|
|
13
13
|
|
14
14
|
def self.create_input_statements(raw_query, dialects)
|
15
15
|
dialects.map do |dialect|
|
16
|
-
NewRelic::Agent::Database::Statement.new(raw_query
|
17
|
-
s.adapter = DIALECT_MAP[dialect]
|
18
|
-
end
|
16
|
+
NewRelic::Agent::Database::Statement.new(raw_query, {:adapter => DIALECT_MAP[dialect]})
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
@@ -0,0 +1,128 @@
|
|
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/redis'
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
7
|
+
|
8
|
+
class NewRelic::Agent::Datastores::RedisTest < Minitest::Test
|
9
|
+
def test_format_command
|
10
|
+
expected = "set \"foo\" \"bar\""
|
11
|
+
|
12
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
13
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, 'foo', 'bar'])
|
14
|
+
assert_equal expected, result
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_format_command_truncates_long_arguments
|
19
|
+
key = "namespace.other_namespace.different_namespace.why.would.you.do.this.key"
|
20
|
+
expected_key = "namespace.other_namespace.dif...ace.why.would.you.do.this.key"
|
21
|
+
|
22
|
+
expected = "set \"#{expected_key}\" \"redoctober\""
|
23
|
+
|
24
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
25
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, key, 'redoctober'])
|
26
|
+
assert_equal expected, result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_format_command_truncates_long_commands
|
31
|
+
key = "key"
|
32
|
+
command = [:set] + Array.new(NewRelic::Agent::Datastores::Redis::MAXIMUM_COMMAND_LENGTH, key)
|
33
|
+
|
34
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
35
|
+
result = NewRelic::Agent::Datastores::Redis.format_command(command)
|
36
|
+
assert result.length <= NewRelic::Agent::Datastores::Redis::MAXIMUM_COMMAND_LENGTH
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_format_command_with_record_arguments_false
|
41
|
+
with_config(:'transaction_tracer.record_redis_arguments' => false) do
|
42
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, 'foo', 'bar'])
|
43
|
+
assert_equal nil, result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_format_command_in_pipeline
|
48
|
+
expected = "set \"foo\" \"bar\""
|
49
|
+
|
50
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
51
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, 'foo', 'bar'])
|
52
|
+
assert_equal expected, result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_append_command_in_pipeline_with_record_arguments_false
|
57
|
+
expected = "set ?"
|
58
|
+
|
59
|
+
with_config(:'transaction_tracer.record_redis_arguments' => false) do
|
60
|
+
result = ""
|
61
|
+
NewRelic::Agent::Datastores::Redis.append_pipeline_command(result, [:set, 'foo', 'bar'])
|
62
|
+
assert_equal expected, result
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_append_command_in_pipeline_with_record_arguments_and_no_args
|
67
|
+
expected = "multi"
|
68
|
+
|
69
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
70
|
+
result = ""
|
71
|
+
NewRelic::Agent::Datastores::Redis.append_pipeline_command(result, [:multi])
|
72
|
+
assert_equal expected, result
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_append_command_in_pipeline_with_record_arguments_false_and_no_args
|
77
|
+
expected = "multi"
|
78
|
+
|
79
|
+
with_config(:'transaction_tracer.record_redis_arguments' => false) do
|
80
|
+
result = ""
|
81
|
+
NewRelic::Agent::Datastores::Redis.append_pipeline_command(result, [:multi])
|
82
|
+
assert_equal expected, result
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_format_pipeline_commands_truncates_long_commands
|
87
|
+
pipeline = NewRelic::Agent::Datastores::Redis::MAXIMUM_COMMAND_LENGTH.times.map do
|
88
|
+
[:set, "0123456789"]
|
89
|
+
end
|
90
|
+
|
91
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
92
|
+
result = NewRelic::Agent::Datastores::Redis.format_pipeline_commands(pipeline)
|
93
|
+
assert NewRelic::Agent::Datastores::Redis::MAXIMUM_COMMAND_LENGTH, result.length
|
94
|
+
assert result.end_with?("012345...")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_format_command_with_non_string_argument
|
99
|
+
expected = "set \"key\" true"
|
100
|
+
|
101
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
102
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, 'key', true])
|
103
|
+
assert_equal expected, result
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
if !NewRelic::LanguageSupport.rubinius? && RUBY_VERSION != "1.8.7"
|
108
|
+
def test_format_command_handles_binary_strings
|
109
|
+
binary_string = (0..255).to_a.pack("c*")
|
110
|
+
expected = 'set "key" <binary data>'
|
111
|
+
|
112
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
113
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, 'key', binary_string])
|
114
|
+
assert_equal expected, result
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_format_command_in_pipeline_handles_binary_strings
|
119
|
+
binary_string = (0..255).to_a.pack("c*")
|
120
|
+
expected = 'set "key" <binary data>'
|
121
|
+
|
122
|
+
with_config(:'transaction_tracer.record_redis_arguments' => true) do
|
123
|
+
result = NewRelic::Agent::Datastores::Redis.format_command([:set, 'key', binary_string])
|
124
|
+
assert_equal expected, result
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -87,7 +87,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Minitest::T
|
|
87
87
|
assert_equal('Datastore/statement/ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find',
|
88
88
|
last_node.metric_name)
|
89
89
|
assert_equal('SELECT * FROM sandwiches',
|
90
|
-
last_node.params[:sql])
|
90
|
+
last_node.params[:sql].sql)
|
91
91
|
end
|
92
92
|
|
93
93
|
def test_creates_slow_sql_node
|
@@ -30,7 +30,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
30
30
|
def populate_container(sampler, n)
|
31
31
|
n.times do |i|
|
32
32
|
sampler.on_start_transaction(@state, nil)
|
33
|
-
sampler.notice_sql("SELECT * FROM test#{i}", "Database/test/select",
|
33
|
+
sampler.notice_sql("SELECT * FROM test#{i}", "Database/test/select", {}, 1, @state)
|
34
34
|
sampler.on_finishing_transaction(@state, 'txn')
|
35
35
|
end
|
36
36
|
end
|
@@ -76,9 +76,9 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
76
76
|
data.set_transaction_info("/c/a", 'guid')
|
77
77
|
data.set_transaction_name("WebTransaction/Controller/c/a")
|
78
78
|
data.sql_data.concat [
|
79
|
-
NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select",
|
80
|
-
NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select",
|
81
|
-
NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select",
|
79
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test"), "Database/test/select", 1.5),
|
80
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test"), "Database/test/select", 1.2),
|
81
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test2"), "Database/test2/select", 1.1)
|
82
82
|
]
|
83
83
|
@sampler.save_slow_sql data
|
84
84
|
|
@@ -86,13 +86,13 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_sql_aggregation
|
89
|
-
|
90
|
-
|
91
|
-
"Database/test/select", {}, 1.2),
|
92
|
-
"tx_name", "uri")
|
89
|
+
query = "select * from test"
|
90
|
+
slow_sql = NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new(query), "Database/test/select", 1.2)
|
93
91
|
|
94
|
-
sql_trace
|
95
|
-
|
92
|
+
sql_trace = NewRelic::Agent::SqlTrace.new(query, slow_sql, "tx_name", "uri")
|
93
|
+
|
94
|
+
sql_trace.aggregate NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new(query), "Database/test/select", 1.5), "slowest_tx_name", "slow_uri"
|
95
|
+
sql_trace.aggregate NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new(query), "Database/test/select", 1.1), "other_tx_name", "uri2"
|
96
96
|
|
97
97
|
assert_equal 3, sql_trace.call_count
|
98
98
|
assert_equal "slowest_tx_name", sql_trace.path
|
@@ -104,9 +104,9 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
104
104
|
data = NewRelic::Agent::TransactionSqlData.new
|
105
105
|
data.set_transaction_info("/c/a", 'guid')
|
106
106
|
data.set_transaction_name("WebTransaction/Controller/c/a")
|
107
|
-
data.sql_data.concat [NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select",
|
108
|
-
NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select",
|
109
|
-
NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select",
|
107
|
+
data.sql_data.concat [NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test"), "Database/test/select", 1.5),
|
108
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test"), "Database/test/select", 1.2),
|
109
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test2"), "Database/test2/select", 1.1)]
|
110
110
|
@sampler.save_slow_sql data
|
111
111
|
|
112
112
|
sql_traces = @sampler.harvest!
|
@@ -118,8 +118,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
118
118
|
data.set_transaction_info("/c/a", 'guid')
|
119
119
|
data.set_transaction_name("WebTransaction/Controller/c/a")
|
120
120
|
15.times do |i|
|
121
|
-
|
122
|
-
|
121
|
+
statement = NewRelic::Agent::Database::Statement.new("select * from test#{(i+97).chr}")
|
122
|
+
data.sql_data << NewRelic::Agent::SlowSql.new(statement, "Database/test#{(i+97).chr}/select", i)
|
123
123
|
end
|
124
124
|
|
125
125
|
@sampler.save_slow_sql data
|
@@ -134,9 +134,9 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
134
134
|
data.set_transaction_info("/c/a", 'guid')
|
135
135
|
data.set_transaction_name("WebTransaction/Controller/c/a")
|
136
136
|
queries = [
|
137
|
-
NewRelic::Agent::SlowSql.new("select * from test where foo in (1, 2) ", "Database/test/select",
|
138
|
-
NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2, 3 ,4, 5,6, 'snausage')", "Database/test/select",
|
139
|
-
NewRelic::Agent::SlowSql.new("select * from test2 where foo in (1,2)", "Database/test2/select",
|
137
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test where foo in (1, 2) "), "Database/test/select", 1.5),
|
138
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test where foo in (1,2, 3 ,4, 5,6, 'snausage')"), "Database/test/select", 1.2),
|
139
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test2 where foo in (1,2)"), "Database/test2/select", 1.1)
|
140
140
|
]
|
141
141
|
data.sql_data.concat(queries)
|
142
142
|
@sampler.save_slow_sql data
|
@@ -157,15 +157,12 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
157
157
|
explainer = NewRelic::Agent::Instrumentation::ActiveRecord::EXPLAINER
|
158
158
|
config = { :adapter => 'mysql' }
|
159
159
|
queries = [
|
160
|
-
NewRelic::Agent::SlowSql.new("select * from test",
|
161
|
-
"Database/test/select",
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
1.
|
166
|
-
NewRelic::Agent::SlowSql.new("select * from test2",
|
167
|
-
"Database/test2/select", config,
|
168
|
-
1.1, nil, explainer)
|
160
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test", config, explainer),
|
161
|
+
"Database/test/select", 1.5),
|
162
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test", config, explainer),
|
163
|
+
"Database/test/select", 1.2),
|
164
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test2", config, explainer),
|
165
|
+
"Database/test2/select", 1.1)
|
169
166
|
]
|
170
167
|
data.sql_data.concat(queries)
|
171
168
|
@sampler.save_slow_sql data
|
@@ -196,8 +193,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
196
193
|
data.set_transaction_info("/c/a", 'guid')
|
197
194
|
data.set_transaction_name("WebTransaction/Controller/c/a")
|
198
195
|
queries = [
|
199
|
-
NewRelic::Agent::SlowSql.new("select * from test",
|
200
|
-
"Database/test/select",
|
196
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test"),
|
197
|
+
"Database/test/select", 1.5)
|
201
198
|
]
|
202
199
|
data.sql_data.concat(queries)
|
203
200
|
@sampler.save_slow_sql data
|
@@ -227,9 +224,10 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
227
224
|
end
|
228
225
|
|
229
226
|
def test_sql_id_fits_in_a_mysql_int_11
|
227
|
+
statement = NewRelic::Agent::Database::Statement.new("select * from test")
|
230
228
|
sql_trace = NewRelic::Agent::SqlTrace.new("select * from test",
|
231
|
-
NewRelic::Agent::SlowSql.new(
|
232
|
-
"Database/test/select",
|
229
|
+
NewRelic::Agent::SlowSql.new(statement,
|
230
|
+
"Database/test/select", 1.2),
|
233
231
|
"tx_name", "uri")
|
234
232
|
|
235
233
|
assert(-2147483648 <= sql_trace.sql_id, "sql_id too small")
|
@@ -241,10 +239,10 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
241
239
|
data = NewRelic::Agent::TransactionSqlData.new
|
242
240
|
data.set_transaction_info("/c/a", 'guid')
|
243
241
|
data.set_transaction_name("WebTransaction/Controller/c/a")
|
244
|
-
data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test where foo = 'bar'",
|
245
|
-
"Database/test/select",
|
246
|
-
NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
|
247
|
-
"Database/test/select",
|
242
|
+
data.sql_data.concat([NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test where foo = 'bar'"),
|
243
|
+
"Database/test/select", 1.5),
|
244
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test where foo in (1,2,3,4,5)"),
|
245
|
+
"Database/test/select", 1.2)])
|
248
246
|
@sampler.save_slow_sql(data)
|
249
247
|
sql_traces = @sampler.harvest!.sort_by(&:total_call_time).reverse
|
250
248
|
|
@@ -262,10 +260,10 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
262
260
|
data = NewRelic::Agent::TransactionSqlData.new
|
263
261
|
data.set_transaction_info("/c/a", 'guid')
|
264
262
|
data.set_transaction_name("WebTransaction/Controller/c/a")
|
265
|
-
data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test where foo = 'bar'",
|
266
|
-
"Database/test/select",
|
267
|
-
NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
|
268
|
-
"Database/test/select",
|
263
|
+
data.sql_data.concat([NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test where foo = 'bar'"),
|
264
|
+
"Database/test/select", 1.5),
|
265
|
+
NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test where foo in (1,2,3,4,5)"),
|
266
|
+
"Database/test/select", 1.2)])
|
269
267
|
@sampler.save_slow_sql(data)
|
270
268
|
sql_traces = @sampler.harvest!.sort_by(&:total_call_time).reverse
|
271
269
|
|
@@ -274,6 +272,19 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
274
272
|
end
|
275
273
|
end
|
276
274
|
|
275
|
+
def test_does_not_over_obfuscate_queries_for_postgres
|
276
|
+
with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
|
277
|
+
sampler = NewRelic::Agent.agent.sql_sampler
|
278
|
+
|
279
|
+
in_transaction do
|
280
|
+
sql = %Q[INSERT INTO "items" ("name", "price") VALUES ('continuum transfunctioner', 100000) RETURNING "id"]
|
281
|
+
sampler.notice_sql sql, "Database/test/insert", {:adapter => "postgres"}, 1.23
|
282
|
+
end
|
283
|
+
sql_traces = sampler.harvest!
|
284
|
+
assert_equal(%Q[INSERT INTO "items" ("name", "price") VALUES (?, ?) RETURNING "id"], sql_traces[0].sql)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
277
288
|
def test_takes_slowest_samples
|
278
289
|
data = NewRelic::Agent::TransactionSqlData.new
|
279
290
|
data.set_transaction_info("/c/a", 'guid')
|
@@ -282,7 +293,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
282
293
|
count = NewRelic::Agent::SqlSampler::MAX_SAMPLES * 2
|
283
294
|
durations = (0...count).to_a.shuffle
|
284
295
|
durations.each do |i|
|
285
|
-
data.sql_data << NewRelic::Agent::SlowSql.new("SELECT * FROM table#{i}", "Database/table#{i}/select",
|
296
|
+
data.sql_data << NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("SELECT * FROM table#{i}"), "Database/table#{i}/select", i)
|
286
297
|
end
|
287
298
|
|
288
299
|
@sampler.save_slow_sql(data)
|
@@ -298,9 +309,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
298
309
|
with_config(:'transaction_tracer.explain_enabled' => false) do
|
299
310
|
data = NewRelic::Agent::TransactionSqlData.new
|
300
311
|
explainer = NewRelic::Agent::Instrumentation::ActiveRecord::EXPLAINER
|
301
|
-
data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test",
|
302
|
-
"Database/test/select",
|
303
|
-
{}, 1.5, nil, explainer)])
|
312
|
+
data.sql_data.concat([NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test", {}, explainer),
|
313
|
+
"Database/test/select", 1.5)])
|
304
314
|
@sampler.save_slow_sql(data)
|
305
315
|
sql_traces = @sampler.harvest!
|
306
316
|
|
@@ -313,9 +323,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
313
323
|
data = NewRelic::Agent::TransactionSqlData.new
|
314
324
|
data.set_transaction_info("/c/a", 'guid')
|
315
325
|
data.set_transaction_name("WebTransaction/Controller/c/a")
|
316
|
-
data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test",
|
317
|
-
"Database/test/select",
|
318
|
-
{}, 1.5)])
|
326
|
+
data.sql_data.concat([NewRelic::Agent::SlowSql.new(NewRelic::Agent::Database::Statement.new("select * from test"),
|
327
|
+
"Database/test/select", 1.5)])
|
319
328
|
@sampler.save_slow_sql(data)
|
320
329
|
sql_traces = @sampler.harvest!
|
321
330
|
|
@@ -336,7 +345,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
336
345
|
end
|
337
346
|
|
338
347
|
def test_to_collector_array_with_bad_values
|
339
|
-
|
348
|
+
statement = NewRelic::Agent::Database::Statement.new("query")
|
349
|
+
slow = NewRelic::Agent::SlowSql.new(statement, "transaction", Rational(12, 1))
|
340
350
|
trace = NewRelic::Agent::SqlTrace.new("query", slow, "path", "uri")
|
341
351
|
trace.call_count = Rational(10, 1)
|
342
352
|
trace.instance_variable_set(:@sql_id, "1234")
|
@@ -357,7 +367,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
357
367
|
|
358
368
|
def test_merge_without_existing_trace
|
359
369
|
query = "select * from test"
|
360
|
-
|
370
|
+
statement = NewRelic::Agent::Database::Statement.new(query, {})
|
371
|
+
slow_sql = NewRelic::Agent::SlowSql.new(statement, "Database/test/select", 1)
|
361
372
|
trace = NewRelic::Agent::SqlTrace.new(query, slow_sql, "txn_name", "uri")
|
362
373
|
|
363
374
|
@sampler.merge!([trace])
|
@@ -366,9 +377,9 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
366
377
|
|
367
378
|
def test_merge_with_existing_trace
|
368
379
|
query = "select * from test"
|
369
|
-
|
370
|
-
slow_sql0 = NewRelic::Agent::SlowSql.new(
|
371
|
-
slow_sql1 = NewRelic::Agent::SlowSql.new(
|
380
|
+
statement = NewRelic::Agent::Database::Statement.new(query, {})
|
381
|
+
slow_sql0 = NewRelic::Agent::SlowSql.new(statement, "Database/test/select", 1)
|
382
|
+
slow_sql1 = NewRelic::Agent::SlowSql.new(statement, "Database/test/select", 2)
|
372
383
|
|
373
384
|
trace0 = NewRelic::Agent::SqlTrace.new(query, slow_sql0, "txn_name", "uri")
|
374
385
|
trace1 = NewRelic::Agent::SqlTrace.new(query, slow_sql1, "txn_name", "uri")
|
@@ -393,7 +404,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
393
404
|
|
394
405
|
count = NewRelic::Agent::SqlSampler::MAX_SAMPLES + 1
|
395
406
|
count.times do |i|
|
396
|
-
|
407
|
+
statement = NewRelic::Agent::Database::Statement.new("SELECT * FROM table#{i}", {})
|
408
|
+
data.sql_data << NewRelic::Agent::SlowSql.new(statement, "Database/table#{i}/select", i)
|
397
409
|
end
|
398
410
|
|
399
411
|
@sampler.save_slow_sql(data)
|
@@ -340,7 +340,7 @@ class NewRelic::Agent::Transaction::TraceNodeTest < Minitest::Test
|
|
340
340
|
def test_obfuscated_sql
|
341
341
|
sql = 'select * from table where id = 1'
|
342
342
|
s = NewRelic::Agent::Transaction::TraceNode.new(Time.now, 'Custom/test/metric')
|
343
|
-
s[:sql] = sql
|
343
|
+
s[:sql] = NewRelic::Agent::Database::Statement.new(sql)
|
344
344
|
assert_equal('select * from table where id = ?', s.obfuscated_sql)
|
345
345
|
end
|
346
346
|
|
@@ -214,7 +214,7 @@ class NewRelic::Agent::Transaction::TraceTest < Minitest::Test
|
|
214
214
|
NewRelic::Agent::Database.stubs(:record_sql_method).returns :raw
|
215
215
|
|
216
216
|
node = @trace.create_node(0.0, 'has_sql')
|
217
|
-
node[:sql] = "select * from pelicans where name = '1337807';"
|
217
|
+
node[:sql] = NewRelic::Agent::Database::Statement.new "select * from pelicans where name = '1337807';"
|
218
218
|
@trace.root_node.add_called_node(node)
|
219
219
|
|
220
220
|
@trace.prepare_sql_for_transmission!
|
@@ -186,7 +186,12 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
|
|
186
186
|
def test_notice_sql_recording_sql
|
187
187
|
@state.record_sql = true
|
188
188
|
builder = @sampler.tl_builder
|
189
|
-
@sampler.expects(:notice_extra_data).with
|
189
|
+
@sampler.expects(:notice_extra_data).with do |sample_builder, message, duration, key|
|
190
|
+
sample_builder == builder &&
|
191
|
+
message.sql == 'some sql' &&
|
192
|
+
duration == 1.0 &&
|
193
|
+
key == :sql
|
194
|
+
end
|
190
195
|
@sampler.notice_sql('some sql', {:config => 'a config'}, 1.0, @state)
|
191
196
|
end
|
192
197
|
|
@@ -574,7 +579,7 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
|
|
574
579
|
|
575
580
|
sql = node[:sql]
|
576
581
|
|
577
|
-
assert sql.length <= 16384
|
582
|
+
assert sql.sql.length <= 16384
|
578
583
|
end
|
579
584
|
|
580
585
|
def test_node_obfuscated
|
@@ -587,7 +592,7 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
|
|
587
592
|
|
588
593
|
node = @sampler.send(:tl_builder).current_node
|
589
594
|
|
590
|
-
assert_equal orig_sql, node[:sql]
|
595
|
+
assert_equal orig_sql, node[:sql].sql
|
591
596
|
assert_equal "SELECT * from Jim where id=?", node.obfuscated_sql
|
592
597
|
@sampler.notice_pop_frame(@state, "foo")
|
593
598
|
end
|
@@ -607,7 +612,7 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
|
|
607
612
|
expected_sql = "SELECT * FROM sandwiches WHERE bread = 'challah'"
|
608
613
|
deepest_node = find_last_transaction_node(@sampler.last_sample)
|
609
614
|
assert_equal([], deepest_node.called_nodes)
|
610
|
-
assert_equal(expected_sql, deepest_node[:sql])
|
615
|
+
assert_equal(expected_sql, deepest_node[:sql].sql)
|
611
616
|
end
|
612
617
|
end
|
613
618
|
|
@@ -642,13 +647,6 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
|
|
642
647
|
end
|
643
648
|
end
|
644
649
|
|
645
|
-
def test_build_database_statement_uses_adapter_from_connection_config
|
646
|
-
config = { :adapter => 'GumbyDB' }
|
647
|
-
sql = "SELECT * FROM \"horses\" WHERE \"name\" = 'pokey'"
|
648
|
-
statement = @sampler.build_database_statement(sql, config, Proc.new {})
|
649
|
-
assert_equal 'GumbyDB', statement.adapter
|
650
|
-
end
|
651
|
-
|
652
650
|
def test_harvest_prepare_samples
|
653
651
|
samples = [mock('TT0'), mock('TT1')]
|
654
652
|
samples[0].expects(:prepare_to_send!)
|