newrelic-redis 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.3.0 / 2012-05-17
2
+
3
+ * 2 minor feature:
4
+ * Supports the redis gem version 3.0
5
+ * Can be disabled via some environment flags
6
+
1
7
  === 1.0.0 / 2012-03-09
2
8
 
3
9
  * 1 major enhancement
data/Rakefile CHANGED
@@ -3,6 +3,46 @@
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
+ REDIS_DIR = File.expand_path(File.join("..", "test"), __FILE__)
7
+ REDIS_CNF = File.join(REDIS_DIR, "test.conf")
8
+ REDIS_PID = File.join(REDIS_DIR, "db", "redis.pid")
9
+
10
+ task :default => :run
11
+
12
+ desc "Run tests and manage server start/stop"
13
+ task :run => [:start, :test, :stop]
14
+
15
+ desc "Start the Redis server"
16
+ task :start do
17
+ redis_running = \
18
+ begin
19
+ File.exists?(REDIS_PID) && Process.kill(0, File.read(REDIS_PID).to_i)
20
+ rescue Errno::ESRCH
21
+ FileUtils.rm REDIS_PID
22
+ false
23
+ end
24
+
25
+ unless redis_running
26
+ unless system("which redis-server")
27
+ STDERR.puts "redis-server not in PATH"
28
+ exit 1
29
+ end
30
+
31
+ unless system("redis-server #{REDIS_CNF}")
32
+ STDERR.puts "could not start redis-server"
33
+ exit 1
34
+ end
35
+ end
36
+ end
37
+
38
+ desc "Stop the Redis server"
39
+ task :stop do
40
+ if File.exists?(REDIS_PID)
41
+ Process.kill "INT", File.read(REDIS_PID).to_i
42
+ FileUtils.rm REDIS_PID
43
+ end
44
+ end
45
+
6
46
  Hoe.plugin :bundler
7
47
  Hoe.plugin :gemspec
8
48
  Hoe.plugin :git
@@ -5,6 +5,11 @@ require 'redis'
5
5
  # Originally contributed by Ashley Martens of ngmoco
6
6
  # Rewritten, reorganized, and repackaged by Evan Phoenix
7
7
 
8
+ load_probes =
9
+ !NewRelic::Control.instance['disable_redis'] &&
10
+ ENV['NEWRELIC_ENABLE'].to_s !~ /false|off|no/i
11
+
12
+ # load_probes checked as a post condition
8
13
  ::Redis::Client.class_eval do
9
14
 
10
15
  include NewRelic::Agent::MethodTracer
@@ -44,7 +49,7 @@ require 'redis'
44
49
  # Don't bother supporting them for now.
45
50
  #
46
51
  if public_method_defined? :call_pipelined
47
- def call_pipelined_with_newrelic_trace(commands, options={})
52
+ def call_pipelined_with_newrelic_trace(commands, *rest)
48
53
  if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
49
54
  total_metric = 'Database/Redis/allWeb'
50
55
  else
@@ -66,7 +71,7 @@ require 'redis'
66
71
  start = Time.now
67
72
 
68
73
  begin
69
- call_pipelined_without_newrelic_trace commands, options
74
+ call_pipelined_without_newrelic_trace commands, *rest
70
75
  ensure
71
76
  s = NewRelic::Agent.instance.transaction_sampler
72
77
  s.notice_nosql(commands.inspect, (Time.now - start).to_f) rescue nil
@@ -78,5 +83,5 @@ require 'redis'
78
83
  alias_method :call_pipelined_without_newrelic_trace, :call_pipelined
79
84
  alias_method :call_pipelined, :call_pipelined_with_newrelic_trace
80
85
  end
81
- end
86
+ end if load_probes
82
87
 
@@ -1,3 +1,3 @@
1
1
  class NewRelicRedis
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "newrelic-redis"
5
- s.version = "1.1.0"
5
+ s.version = "1.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Evan Phoenix"]
9
- s.date = "2012-03-09"
9
+ s.date = "2012-05-17"
10
10
  s.description = "Redis instrumentation for Newrelic."
11
11
  s.email = ["evan@phx.io"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rdoc_options = ["--main", "README.txt"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "newrelic-redis"
18
- s.rubygems_version = "1.8.17"
18
+ s.rubygems_version = "1.8.22"
19
19
  s.summary = "Redis instrumentation for Newrelic."
20
20
  s.test_files = ["test/test_newrelic_redis.rb"]
21
21
 
@@ -6,20 +6,8 @@ require 'newrelic_redis/instrumentation'
6
6
  class TestNewRelicRedis < Test::Unit::TestCase
7
7
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
8
8
 
9
- module StubProcess
10
- def establish_connection
11
- end
12
-
13
- def read(*args)
14
- end
15
-
16
- def process(*args)
17
- @process_args = args
18
- end
19
-
20
- attr_reader :process_args
21
-
22
- end
9
+ PORT = 6381
10
+ OPTIONS = {:port => PORT, :db => 15, :timeout => 0.1}
23
11
 
24
12
  def setup
25
13
  NewRelic::Agent.manual_start
@@ -31,11 +19,8 @@ class TestNewRelicRedis < Test::Unit::TestCase
31
19
  @sampler.reset!
32
20
  @sampler.start_builder
33
21
 
34
- @redis = Redis.new :path => "/tmp/redis"
22
+ @redis = Redis.new OPTIONS
35
23
  @client = @redis.client
36
- class << @client
37
- include StubProcess
38
- end
39
24
  end
40
25
 
41
26
  def teardown
@@ -43,31 +28,31 @@ class TestNewRelicRedis < Test::Unit::TestCase
43
28
  end
44
29
 
45
30
  def assert_metrics(*m)
46
- assert_equal m.sort, @engine.metrics.sort
31
+ m.each do |x|
32
+ assert @engine.metrics.include?(x), "#{x} not in metrics"
33
+ end
47
34
  end
48
35
 
49
36
  def test_call
50
37
  @redis.hgetall "foo"
51
- assert_equal [[[:hgetall, "foo"]]], @client.process_args
52
38
  assert_metrics "Database/Redis/HGETALL", "Database/Redis/allOther"
53
39
 
54
40
  prm = @sampler.builder.current_segment.params
55
- assert_equal "[[:hgetall, \"foo\"]]", prm[:key]
41
+ assert_equal "[[:select, 15]];\n[[:hgetall, \"foo\"]]", prm[:key]
56
42
  end
57
43
 
58
44
  def test_call_pipelined
59
45
  @redis.pipelined do
60
46
  @redis.hgetall "foo"
61
- @redis.inc "bar"
47
+ @redis.incr "bar"
62
48
  end
63
49
 
64
- assert_equal [[[:hgetall, "foo"], [:inc, "bar"]]], @client.process_args
65
50
  assert_metrics "Database/Redis/Pipelined",
66
51
  "Database/Redis/Pipelined/HGETALL",
67
- "Database/Redis/Pipelined/INC",
52
+ "Database/Redis/Pipelined/INCR",
68
53
  "Database/Redis/allOther"
69
54
 
70
55
  prm = @sampler.builder.current_segment.params
71
- assert_equal "[[:hgetall, \"foo\"], [:inc, \"bar\"]]", prm[:key]
56
+ assert_equal "[[:select, 15]];\n[[:hgetall, \"foo\"], [:incr, \"bar\"]]", prm[:key]
72
57
  end
73
58
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic-redis
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 1.2.0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Evan Phoenix
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-20 00:00:00 Z
18
+ date: 2012-05-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: redis
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements: []
131
131
 
132
132
  rubyforge_project: newrelic-redis
133
- rubygems_version: 1.8.18
133
+ rubygems_version: 1.8.22
134
134
  signing_key:
135
135
  specification_version: 3
136
136
  summary: Redis instrumentation for Newrelic.