newrelic-redis 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28b9cfa808b80ff682a14999a13a5c0c9dac3c18
4
- data.tar.gz: 6c59cfd9cc77752487d36880c5bc149bef109ca0
3
+ metadata.gz: 9f694726dbf03d588753badff81b3e75171cc1af
4
+ data.tar.gz: 9b2ca6a10ee6173dc8408cf559ffaaa1aef88faa
5
5
  SHA512:
6
- metadata.gz: c922be001df8876065c2b7f59160e8a53bfed58a0aa8fcef4700537208815a49daf0fef6c526aec7e2164f7623253eed0ce472ca66a1a5995fe3caa4d2a23dd4
7
- data.tar.gz: 54f332a9d7a0270baa66e608b04b30b2502887462e42afd0c5c0dab0354c7e7d7c5b92663b151f021643f1445778bfdb848fc37efb73984f80f1a0defedc7c75
6
+ metadata.gz: dcdaca1a1d930db69d67150ce617cf04e0686a9dd8467e323cf7b332b78d2cfe30cd0b7474e1e0a0bbac2af9fc10989c8a90b8bfa0953ad636994c007ca8b11a
7
+ data.tar.gz: 59bd9e713de9d368495dc6ec86a91cd72521a890f975e14b99b661570bf27765bfee5259347fd4a3076dcaa15d4cdc882ae08fd99fed50bf9aa4a314ee315e74
@@ -1,7 +1,7 @@
1
1
  .autotest
2
2
  History.txt
3
3
  Manifest.txt
4
- README.txt
4
+ README.md
5
5
  Rakefile
6
6
  lib/newrelic-redis.rb
7
7
  lib/newrelic_redis/instrumentation.rb
@@ -1,38 +1,38 @@
1
- = newrelic-redis
1
+ # newrelic-redis
2
2
 
3
3
  * http://github.com/evanphx/newrelic-redis
4
4
 
5
- == DESCRIPTION:
5
+ ## DESCRIPTION:
6
6
 
7
7
  Redis instrumentation for Newrelic.
8
8
 
9
- == FEATURES/PROBLEMS:
9
+ ## FEATURES/PROBLEMS:
10
10
 
11
11
  * Allows transactions to show time spent inside redis requests
12
12
  * Supports normal and pipelined commands
13
13
 
14
- == SYNOPSIS:
14
+ ## SYNOPSIS:
15
15
 
16
16
  Just add the gem to your project!
17
17
 
18
- == REQUIREMENTS:
18
+ ## REQUIREMENTS:
19
19
 
20
20
  * redis-rb
21
21
 
22
- == INSTALL:
22
+ ## INSTALL:
23
23
 
24
- * gem install newrelic-redis
24
+ $ gem install newrelic-redis
25
25
 
26
- == DEVELOPERS:
26
+ ## DEVELOPERS:
27
27
 
28
28
  After checking out the source, run:
29
29
 
30
- $ rake newb
30
+ $ rake newb
31
31
 
32
32
  This task will install any missing dependencies, run the tests/specs,
33
33
  and generate the RDoc.
34
34
 
35
- == LICENSE:
35
+ ## LICENSE:
36
36
 
37
37
  (The MIT License)
38
38
 
data/Rakefile CHANGED
@@ -51,7 +51,9 @@ HOE = Hoe.spec 'newrelic-redis' do
51
51
  developer 'Evan Phoenix', 'evan@phx.io'
52
52
 
53
53
  dependency "redis", "< 4.0"
54
- dependency "newrelic_rpm", "~> 3.0"
54
+ dependency "newrelic_rpm", "~> 3.11"
55
+
56
+ self.readme_file = "README.md"
55
57
  end
56
58
 
57
59
  file "#{HOE.spec.name}.gemspec" => ['Rakefile'] do |t|
@@ -14,10 +14,12 @@ DependencyDetection.defer do
14
14
  end
15
15
 
16
16
  executes do
17
- NewRelic::Agent.logger.debug 'Installing Redis Instrumentation'
17
+ NewRelic::Agent.logger.info 'Installing Redis Instrumentation'
18
18
  end
19
19
 
20
20
  executes do
21
+ require 'new_relic/agent/datastores'
22
+
21
23
  ::Redis::Client.class_eval do
22
24
  # Support older versions of Redis::Client that used the method
23
25
  # +raw_call_command+.
@@ -25,23 +27,13 @@ DependencyDetection.defer do
25
27
  call_method = ::Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command
26
28
 
27
29
  def call_with_newrelic_trace(*args, &blk)
28
- if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
29
- total_metric = 'Database/Redis/allWeb'
30
- else
31
- total_metric = 'Database/Redis/allOther'
32
- end
33
-
34
30
  method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
35
- metrics = ["Database/Redis/#{method_name.to_s.upcase}", total_metric]
36
-
37
- self.class.trace_execution_scoped(metrics) do
38
- start = Time.now
31
+ callback = proc do |result, metric, elapsed|
32
+ _send_to_new_relic(args, elapsed)
33
+ end
39
34
 
40
- begin
41
- call_without_newrelic_trace(*args, &blk)
42
- ensure
43
- _send_to_new_relic(args, start)
44
- end
35
+ NewRelic::Agent::Datastores.wrap("Redis", method_name, nil, callback) do
36
+ call_without_newrelic_trace(*args, &blk)
45
37
  end
46
38
  end
47
39
 
@@ -53,44 +45,36 @@ DependencyDetection.defer do
53
45
  #
54
46
  if public_method_defined? :call_pipelined
55
47
  def call_pipelined_with_newrelic_trace(commands, *rest)
56
- if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
57
- total_metric = 'Database/Redis/allWeb'
58
- else
59
- total_metric = 'Database/Redis/allOther'
60
- end
61
-
62
- # Report each command as a metric under pipelined, so the user
63
- # can at least see what all the commands were. This prevents
64
- # metric namespace explosion.
65
-
66
- metrics = ["Database/Redis/Pipelined", total_metric]
67
-
68
- commands.each do |c|
48
+ # Report each command as a metric suffixed with _pipelined, so the
49
+ # user can at least see what all the commands were.
50
+ additional = commands.map do |c|
69
51
  name = c.kind_of?(Array) ? c[0] : c
70
- metrics << "Database/Redis/Pipelined/#{name.to_s.upcase}"
52
+ "Datastore/operation/Redis/#{name.to_s.downcase}_pipelined"
71
53
  end
72
54
 
73
- self.class.trace_execution_scoped(metrics) do
74
- start = Time.now
75
-
76
- begin
77
- call_pipelined_without_newrelic_trace commands, *rest
78
- ensure
79
- _send_to_new_relic(commands, start)
55
+ callback = proc do |result, metric, elapsed|
56
+ _send_to_new_relic(commands, elapsed)
57
+ additional.each do |additional_metric|
58
+ NewRelic::Agent::MethodTracer.trace_execution_scoped(additional_metric) do
59
+ # No-op, just getting them as placeholders in the trace tree
60
+ end
80
61
  end
81
62
  end
63
+
64
+ NewRelic::Agent::Datastores.wrap("Redis", "pipelined", nil, callback) do
65
+ call_pipelined_without_newrelic_trace commands, *rest
66
+ end
82
67
  end
83
68
 
84
69
  alias_method :call_pipelined_without_newrelic_trace, :call_pipelined
85
70
  alias_method :call_pipelined, :call_pipelined_with_newrelic_trace
86
71
  end
87
72
 
88
- def _send_to_new_relic(args, start)
73
+ def _send_to_new_relic(args, elapsed)
89
74
  if NewRelic::Control.instance["transaction_tracer.record_sql"] == "obfuscated"
90
75
  args.map! { |arg| [arg.first] + ["?"] * (arg.count - 1) }
91
76
  end
92
- s = NewRelic::Agent.instance.transaction_sampler
93
- s.notice_nosql(args.inspect, (Time.now - start).to_f) rescue nil
77
+ NewRelic::Agent::Datastores.notice_statement(args.inspect, elapsed)
94
78
  end
95
79
  end
96
80
  end
@@ -1,3 +1,3 @@
1
1
  class NewRelicRedis
2
- VERSION = '1.5.0'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -1,42 +1,43 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # stub: newrelic-redis 1.5.0 ruby lib
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "newrelic-redis"
5
- s.version = "1.3.2"
6
+ s.version = "1.5.0"
6
7
 
7
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
8
10
  s.authors = ["Evan Phoenix"]
9
- s.date = "2012-05-18"
11
+ s.date = "2015-03-18"
10
12
  s.description = "Redis instrumentation for Newrelic."
11
13
  s.email = ["evan@phx.io"]
12
14
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
13
- s.files = [".autotest", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/newrelic-redis.rb", "lib/newrelic_redis/instrumentation.rb", "lib/newrelic_redis/version.rb", "newrelic-redis.gemspec", "test/test.conf", "test/test_newrelic_redis.rb", ".gemtest"]
15
+ s.files = [".autotest", ".gemtest", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/newrelic-redis.rb", "lib/newrelic_redis/instrumentation.rb", "lib/newrelic_redis/version.rb", "newrelic-redis.gemspec", "test/test.conf", "test/test_newrelic_redis.rb"]
14
16
  s.homepage = "http://github.com/evanphx/newrelic-redis"
15
- s.rdoc_options = ["--main", "README.txt"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = "newrelic-redis"
18
- s.rubygems_version = "1.8.22"
17
+ s.licenses = ["MIT"]
18
+ s.rdoc_options = ["--main", "README.md"]
19
+ s.rubygems_version = "2.2.2"
19
20
  s.summary = "Redis instrumentation for Newrelic."
20
21
  s.test_files = ["test/test_newrelic_redis.rb"]
21
22
 
22
23
  if s.respond_to? :specification_version then
23
- s.specification_version = 3
24
+ s.specification_version = 4
24
25
 
25
26
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
27
  s.add_runtime_dependency(%q<redis>, ["< 4.0"])
27
- s.add_runtime_dependency(%q<newrelic_rpm>, ["~> 3.0"])
28
- s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
29
- s.add_development_dependency(%q<hoe>, ["~> 2.16"])
28
+ s.add_runtime_dependency(%q<newrelic_rpm>, ["~> 3.11"])
29
+ s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
30
+ s.add_development_dependency(%q<hoe>, ["~> 3.13"])
30
31
  else
31
32
  s.add_dependency(%q<redis>, ["< 4.0"])
32
- s.add_dependency(%q<newrelic_rpm>, ["~> 3.0"])
33
- s.add_dependency(%q<rdoc>, ["~> 3.10"])
34
- s.add_dependency(%q<hoe>, ["~> 2.16"])
33
+ s.add_dependency(%q<newrelic_rpm>, ["~> 3.11"])
34
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
35
+ s.add_dependency(%q<hoe>, ["~> 3.13"])
35
36
  end
36
37
  else
37
38
  s.add_dependency(%q<redis>, ["< 4.0"])
38
- s.add_dependency(%q<newrelic_rpm>, ["~> 3.0"])
39
- s.add_dependency(%q<rdoc>, ["~> 3.10"])
40
- s.add_dependency(%q<hoe>, ["~> 2.16"])
39
+ s.add_dependency(%q<newrelic_rpm>, ["~> 3.11"])
40
+ s.add_dependency(%q<rdoc>, ["~> 4.0"])
41
+ s.add_dependency(%q<hoe>, ["~> 3.13"])
41
42
  end
42
43
  end
@@ -1,61 +1,72 @@
1
1
  require 'test/unit'
2
2
  require 'redis'
3
3
 
4
+ require 'newrelic_rpm'
4
5
  require 'newrelic_redis/instrumentation'
5
6
 
6
- class TestNewRelicRedis < Test::Unit::TestCase
7
- include NewRelic::Agent::Instrumentation::ControllerInstrumentation
7
+ DependencyDetection.detect!
8
+
9
+ NewRelic::Agent.require_test_helper
8
10
 
11
+ class TestNewRelicRedis < Test::Unit::TestCase
9
12
  PORT = 6381
10
13
  OPTIONS = {:port => PORT, :db => 15, :timeout => 0.1}
11
14
 
12
15
  def setup
13
- NewRelic::Agent.manual_start
14
- @engine = NewRelic::Agent.instance.stats_engine
15
- @engine.clear_stats
16
-
17
- @sampler = NewRelic::Agent.instance.transaction_sampler
18
- @sampler.enable
19
- @sampler.reset!
20
- @sampler.start_builder
16
+ NewRelic::Agent.drop_buffered_data
21
17
 
22
18
  @redis = Redis.new OPTIONS
23
19
  @client = @redis.client
24
-
25
- DependencyDetection.detect!
26
20
  end
27
21
 
28
- def teardown
29
- @sampler.clear_builder
22
+ def assert_metrics(*m)
23
+ assert_metrics_recorded(m)
30
24
  end
31
25
 
32
- def assert_metrics(*m)
33
- m.each do |x|
34
- assert @engine.metrics.include?(x), "#{x} not in metrics"
35
- end
26
+ def assert_segment_has_key(segment_name, expected)
27
+ sample = NewRelic::Agent.agent.transaction_sampler.tl_builder.sample
28
+ segment = find_segment_with_name(sample, segment_name)
29
+ assert_equal expected, segment.params[:statement]
36
30
  end
37
31
 
38
32
  def test_call
39
- @redis.hgetall "foo"
40
- assert_metrics "Database/Redis/HGETALL", "Database/Redis/allOther"
33
+ with_config(:'transaction_tracer.record_sql' => 'raw') do
34
+ in_transaction do
35
+ @redis.hgetall "foo"
36
+ assert_segment_has_key "Datastore/operation/Redis/select", "[[:select, 15]]"
37
+ assert_segment_has_key "Datastore/operation/Redis/hgetall", "[[:hgetall, \"foo\"]]"
38
+ end
39
+ end
41
40
 
42
- prm = @sampler.builder.current_segment.params
43
- assert_equal "[[:select, 15]];\n[[:hgetall, \"foo\"]]", prm[:key]
41
+ assert_metrics "Datastore/all",
42
+ "Datastore/allOther",
43
+ "Datastore/Redis/all",
44
+ "Datastore/Redis/allOther",
45
+ "Datastore/operation/Redis/select",
46
+ "Datastore/operation/Redis/hgetall"
44
47
  end
45
48
 
46
49
  def test_call_pipelined
47
- @redis.pipelined do
48
- @redis.hgetall "foo"
49
- @redis.incr "bar"
50
+ with_config(:'transaction_tracer.record_sql' => 'raw') do
51
+ in_transaction do
52
+ @redis.pipelined do
53
+ @redis.hgetall "foo"
54
+ @redis.incr "bar"
55
+ end
56
+
57
+ assert_segment_has_key "Datastore/operation/Redis/select", "[[:select, 15]]"
58
+ assert_segment_has_key "Datastore/operation/Redis/pipelined", "[[:hgetall, \"foo\"], [:incr, \"bar\"]]"
59
+ end
50
60
  end
51
61
 
52
- assert_metrics "Database/Redis/Pipelined",
53
- "Database/Redis/Pipelined/HGETALL",
54
- "Database/Redis/Pipelined/INCR",
55
- "Database/Redis/allOther"
56
-
57
- prm = @sampler.builder.current_segment.params
58
- assert_equal "[[:select, 15]];\n[[:hgetall, \"foo\"], [:incr, \"bar\"]]", prm[:key]
62
+ assert_metrics "Datastore/all",
63
+ "Datastore/allOther",
64
+ "Datastore/Redis/all",
65
+ "Datastore/Redis/allOther",
66
+ "Datastore/operation/Redis/select",
67
+ "Datastore/operation/Redis/pipelined",
68
+ "Datastore/operation/Redis/hgetall_pipelined",
69
+ "Datastore/operation/Redis/incr_pipelined"
59
70
  end
60
71
 
61
72
  def test_call_with_block
@@ -73,18 +84,25 @@ class TestNewRelicRedis < Test::Unit::TestCase
73
84
  end
74
85
 
75
86
  def test_obfuscated
76
- NewRelic::Control.instance["transaction_tracer.record_sql"] = "obfuscated"
77
- @redis.pipelined do
78
- @redis.hgetall "foo"
79
- @redis.incr "bar"
87
+ with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
88
+ in_transaction do
89
+ @redis.pipelined do
90
+ @redis.hgetall "foo"
91
+ @redis.incr "bar"
92
+ end
93
+
94
+ assert_segment_has_key "Datastore/operation/Redis/select", "[[:select, \"?\"]]"
95
+ assert_segment_has_key "Datastore/operation/Redis/pipelined", "[[:hgetall, \"?\"], [:incr, \"?\"]]"
96
+ end
80
97
  end
81
98
 
82
- assert_metrics "Database/Redis/Pipelined",
83
- "Database/Redis/Pipelined/HGETALL",
84
- "Database/Redis/Pipelined/INCR",
85
- "Database/Redis/allOther"
86
-
87
- prm = @sampler.builder.current_segment.params
88
- assert_equal "[[:select, \"?\"]];\n[[:hgetall, \"?\"], [:incr, \"?\"]]", prm[:key]
99
+ assert_metrics "Datastore/all",
100
+ "Datastore/allOther",
101
+ "Datastore/Redis/all",
102
+ "Datastore/Redis/allOther",
103
+ "Datastore/operation/Redis/select",
104
+ "Datastore/operation/Redis/pipelined",
105
+ "Datastore/operation/Redis/hgetall_pipelined",
106
+ "Datastore/operation/Redis/incr_pipelined"
89
107
  end
90
108
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: '3.11'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: '3.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.12'
61
+ version: '3.13'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.12'
68
+ version: '3.13'
69
69
  description: Redis instrumentation for Newrelic.
70
70
  email:
71
71
  - evan@phx.io
@@ -74,13 +74,13 @@ extensions: []
74
74
  extra_rdoc_files:
75
75
  - History.txt
76
76
  - Manifest.txt
77
- - README.txt
77
+ - README.md
78
78
  files:
79
79
  - ".autotest"
80
80
  - ".gemtest"
81
81
  - History.txt
82
82
  - Manifest.txt
83
- - README.txt
83
+ - README.md
84
84
  - Rakefile
85
85
  - lib/newrelic-redis.rb
86
86
  - lib/newrelic_redis/instrumentation.rb
@@ -95,7 +95,7 @@ metadata: {}
95
95
  post_install_message:
96
96
  rdoc_options:
97
97
  - "--main"
98
- - README.txt
98
+ - README.md
99
99
  require_paths:
100
100
  - lib
101
101
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -114,5 +114,4 @@ rubygems_version: 2.2.2
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Redis instrumentation for Newrelic.
117
- test_files:
118
- - test/test_newrelic_redis.rb
117
+ test_files: []