redis-rails-instrumentation 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rubocop.yml +28 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/lib/redis-rails-instrumentation.rb +1 -0
- data/lib/redis/rails/instrumentation.rb +33 -0
- data/lib/redis/rails/instrumentation/logging.rb +15 -0
- data/lib/redis/rails/instrumentation/version.rb +7 -0
- data/redis-rails-instrumentation.gemspec +28 -0
- data/spec/redis/rails/instrumentation_spec.rb +55 -0
- data/spec/spec_helper.rb +28 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7433588470767e405e31709a7097bcd0c7292fc0
|
4
|
+
data.tar.gz: bbc5150918bec83f6811f5d4f4d5b1f0089f96df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e1971b2b6612aa338375c4062e9e7007c690d0b65c0a5704572d712333d5b96c91da21d7f1074bcdb7aee717ca31aff1e2d0874456f3e7b5afc7e0e8ab79c86
|
7
|
+
data.tar.gz: d30fbd89664d94ef8757e3f159c431cbd8c53a209a601b9c4ebde9963418e97c4eea8279f5765b28a3c88d7322f38614a64a2820abb5ccd943e4c1463e1be679
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- redis-rails-instrumentation.gemspec
|
4
|
+
- lib/redis/rails/instrumentation/version.rb
|
5
|
+
- "vendor/**/*"
|
6
|
+
- "gemfiles/vendor/**/*"
|
7
|
+
|
8
|
+
Lint/HandleExceptions:
|
9
|
+
Exclude:
|
10
|
+
- 'spec/**/*'
|
11
|
+
|
12
|
+
Style/Documentation:
|
13
|
+
Exclude:
|
14
|
+
- 'spec/**/*'
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/ConstantName:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/FileName:
|
23
|
+
Exclude:
|
24
|
+
- 'lib/redis-rails-instrumentation.rb'
|
25
|
+
|
26
|
+
Style/LineLength:
|
27
|
+
Exclude:
|
28
|
+
- 'redis-rails-instrumentation.gemspec'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ville Lautanala
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Redis Rails Instrumentation [](https://travis-ci.org/lautis/redis-rails-instrumentation)
|
2
|
+
|
3
|
+
Railtie to include Redis commands in Rails logging.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'redis-rails-instrumentation'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install redis-rails-instrumentation
|
20
|
+
|
21
|
+
After you've started your Rails application, your Rails logs should include
|
22
|
+
Redis commands.
|
23
|
+
|
24
|
+
If you have debug logging enabled, individual commands are printed out:
|
25
|
+
|
26
|
+
Redis (1.12ms) [ GET test ]
|
27
|
+
|
28
|
+
A total runtime is also included per each request:
|
29
|
+
|
30
|
+
Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.4ms | Redis: 1.12ms)
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/[my-github-username]/redis-rails-instrumentation/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'redis/rails/instrumentation'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'redis/rails/instrumentation/logging'
|
3
|
+
require 'redis/rails/instrumentation/version'
|
4
|
+
require 'active_support'
|
5
|
+
require 'sweet_notifications'
|
6
|
+
|
7
|
+
class Redis
|
8
|
+
module Rails
|
9
|
+
module Instrumentation
|
10
|
+
Railtie, LogSubscriber = SweetNotifications.subscribe :redis,
|
11
|
+
label: 'Redis' do
|
12
|
+
color ActiveSupport::LogSubscriber::RED
|
13
|
+
|
14
|
+
event :command do |event|
|
15
|
+
next unless logger.debug?
|
16
|
+
cmds = event.payload[:commands]
|
17
|
+
|
18
|
+
output = cmds.map do |name, *args|
|
19
|
+
if args.present?
|
20
|
+
"[ #{name.to_s.upcase} #{args.join(' ')} ]"
|
21
|
+
else
|
22
|
+
"[ #{name.to_s.upcase} ]"
|
23
|
+
end
|
24
|
+
end.join(' ')
|
25
|
+
|
26
|
+
debug message(event, 'Redis', output)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Redis::Client.send(:prepend, Redis::Rails::Instrumentation::Logging)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Redis
|
2
|
+
module Rails
|
3
|
+
module Instrumentation
|
4
|
+
# Logging monkeypatch for Redis to emit ActiveSupport::Notification events
|
5
|
+
module Logging
|
6
|
+
def logging(commands, &block)
|
7
|
+
ActiveSupport::Notifications.instrument('command.redis',
|
8
|
+
commands: commands) do
|
9
|
+
return super(commands, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'redis/rails/instrumentation/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'redis-rails-instrumentation'
|
8
|
+
spec.version = Redis::Rails::Instrumentation::VERSION
|
9
|
+
spec.authors = ['Ville Lautanala']
|
10
|
+
spec.email = ['lautis@gmail.com']
|
11
|
+
spec.summary = 'Railtie to include Redis commands in Rails logging.'
|
12
|
+
spec.description = 'Log Redis commands and their total runtime in Rails request log.'
|
13
|
+
spec.homepage = 'https://github.com/lautis/redis-rails-instrumentation'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'redis', '~> 3.0'
|
22
|
+
spec.add_dependency 'activesupport', '>= 3.0'
|
23
|
+
spec.add_dependency 'sweet_notifications', '~> 0.2'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.required_ruby_version = '>= 2.0.0'
|
28
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
class Redis
|
5
|
+
module Rails
|
6
|
+
describe Instrumentation do
|
7
|
+
let(:redis) { Redis.new }
|
8
|
+
let(:railtie) { Instrumentation::Railtie }
|
9
|
+
|
10
|
+
after do
|
11
|
+
if railtie.instance.send(:instance_variable_defined?, :@ran)
|
12
|
+
railtie.instance.send(:remove_instance_variable, :@ran)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'initializes a Railtie' do
|
17
|
+
expect(railtie.superclass).to eq(::Rails::Railtie)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'logs runtimes' do
|
21
|
+
Instrumentation::Railtie.run_initializers
|
22
|
+
redis.get('test')
|
23
|
+
expect(Instrumentation::LogSubscriber.runtime).to be > 0
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'logs pipelined commands to a single line' do
|
27
|
+
@logger.level = Logger::DEBUG
|
28
|
+
Instrumentation::Railtie.run_initializers
|
29
|
+
redis.pipelined do
|
30
|
+
redis.get('test1')
|
31
|
+
redis.get('test2')
|
32
|
+
end
|
33
|
+
expect(@logger.logged(:debug)[0])
|
34
|
+
.to match(/Redis \(\d+\.\d+ms\) \[ GET test1 \] \[ GET test2 \]/)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'logs commands to logger' do
|
38
|
+
@logger.level = Logger::DEBUG
|
39
|
+
Instrumentation::Railtie.run_initializers
|
40
|
+
redis.get('test')
|
41
|
+
expect(@logger.logged(:debug)[0])
|
42
|
+
.to match(/Redis \(\d+\.\d+ms\) \[ GET test \]/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'omits debug logging in production' do
|
46
|
+
@logger.level = Logger::ERROR
|
47
|
+
Instrumentation::Railtie.run_initializers
|
48
|
+
redis.get('test')
|
49
|
+
expect(@logger.logged(:debug)).to be_empty
|
50
|
+
expect(@logger.logged(:info)).to be_empty
|
51
|
+
expect(@logger.logged(:error)).to be_empty
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/log_subscriber/test_helper'
|
2
|
+
require 'redis-rails-instrumentation'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.include ActiveSupport::LogSubscriber::TestHelper
|
6
|
+
config.profile_examples = 10
|
7
|
+
config.order = :random
|
8
|
+
Kernel.srand config.seed
|
9
|
+
|
10
|
+
config.expect_with :rspec do |expectations|
|
11
|
+
expectations.syntax = :expect
|
12
|
+
end
|
13
|
+
|
14
|
+
config.mock_with :rspec do |mocks|
|
15
|
+
mocks.syntax = :expect
|
16
|
+
mocks.verify_partial_doubles = true
|
17
|
+
end
|
18
|
+
|
19
|
+
config.before do
|
20
|
+
setup # Setup LogSubscriber::TestHelper
|
21
|
+
allow(Redis::Rails::Instrumentation::LogSubscriber).to receive(:logger)
|
22
|
+
.and_return(ActiveSupport::LogSubscriber::TestHelper::MockLogger.new)
|
23
|
+
end
|
24
|
+
|
25
|
+
config.after do
|
26
|
+
teardown # Tear down LogSubscriber::TestHelper
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis-rails-instrumentation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ville Lautanala
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sweet_notifications
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Log Redis commands and their total runtime in Rails request log.
|
98
|
+
email:
|
99
|
+
- lautis@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/redis-rails-instrumentation.rb
|
112
|
+
- lib/redis/rails/instrumentation.rb
|
113
|
+
- lib/redis/rails/instrumentation/logging.rb
|
114
|
+
- lib/redis/rails/instrumentation/version.rb
|
115
|
+
- redis-rails-instrumentation.gemspec
|
116
|
+
- spec/redis/rails/instrumentation_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
homepage: https://github.com/lautis/redis-rails-instrumentation
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 2.0.0
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.4.5
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Railtie to include Redis commands in Rails logging.
|
142
|
+
test_files:
|
143
|
+
- spec/redis/rails/instrumentation_spec.rb
|
144
|
+
- spec/spec_helper.rb
|