rci 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b5b0bba2f64ae1dae849f1470d5a624d64018e0c
4
+ data.tar.gz: 9534accb397c16d45d6d454ef6da0d1e512585a3
5
+ SHA512:
6
+ metadata.gz: 2b575bf25ef8bfb2695c187d2ebd2f9eae242bf99d6f5797b0815a2709f1eead3463f508d60273791757acf30e52cc1dd0f0385b164b1740ac8e4e1d583f97c6
7
+ data.tar.gz: d924009fe7f171a855658861945f07dc1da821b732044b5ccc5db701b7d01d4196590a2f3e8f8eafd05ec2f5f7337cb34629b807cbbd23ef00e8334d5c2ac56f
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,27 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all
4
+ people who contribute through reporting issues, posting feature requests,
5
+ updating documentation, submitting pull requests or patches, and other
6
+ activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, age, or religion.
12
+
13
+ Examples of unacceptable behavior by participants include the use of sexual
14
+ language or imagery, derogatory comments or personal attacks, trolling,
15
+ public or private harassment, insults, or other unprofessional conduct.
16
+
17
+ Project maintainers have the right and responsibility to remove, edit, or
18
+ reject comments, commits, code, wiki edits, issues, and other contributions
19
+ that are not aligned to this Code of Conduct. Project maintainers who do not
20
+ follow the Code of Conduct may be removed from the project team.
21
+
22
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
23
+ reported by opening an issue or contacting one or more of the project
24
+ maintainers.
25
+
26
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org),
27
+ version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rci.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tyler Pickett
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # RCI
2
+
3
+ (R)edis (C)lient (I)nstrumenter
4
+
5
+ Adds ActiveSpport::Notifications to calls made against redis using the official redis clients
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rci'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rci
22
+
23
+ ## Usage
24
+
25
+ Since the instrumentation depends on being able to query the server for the commands
26
+ it supports you'll need to initialize everything with one of two methods:
27
+
28
+ ```
29
+ redis = Redis.new
30
+
31
+ # Attach to every Redis client in the system (most apps will do this)
32
+ RCI.setup(redis)
33
+
34
+ # Attach to only a specific Redis client
35
+ RCI.attach_instrumentation_to(redis)
36
+ ```
37
+
38
+ Both of these methods will call out to the Redis server to get a list of commands before
39
+ attaching the instrumentation.
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/rci/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ require "rci/version"
2
+ require 'rci/instrumentation'
3
+ require 'rci/commands'
4
+
5
+ module RCI
6
+ def self.setup(redis)
7
+ discover_commands(redis)
8
+ attach_instrumentation!
9
+ end
10
+
11
+ def self.attach_instrumentation_to(redis)
12
+ discover_commands(redis)
13
+ redis.client.singleton_class.send(:prepend, RCI::Instrumentation)
14
+ end
15
+
16
+ private
17
+
18
+ def self.attach_instrumentation!
19
+ Redis::Client.send(:prepend, RCI::Instrumentation)
20
+ end
21
+
22
+ def self.discover_commands(redis)
23
+ Commands.discover!(redis)
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ require 'set'
2
+
3
+ module RCI
4
+ module Commands
5
+ class << self
6
+ attr_reader :commands, :read_commands, :read_command_names
7
+ end
8
+
9
+ @read_commands = []
10
+ @read_command_names = Set.new
11
+
12
+ # As of Redis 3.0 there isn't any indication from the COMMAND return
13
+ # info as to which commands accept a subcommand so we're tracking them here
14
+ COMMANDS_WITH_SUBCOMMANDS = %i{client cluster command debug script}.to_set.freeze
15
+ Command = Struct.new(:name, :arity, :flags, :first_key_position, :last_key_position, :step_count)
16
+
17
+ def self.command_type(command_array)
18
+ @read_command_names.include?(command_array.first) ? :read : :write
19
+ end
20
+
21
+ def self.discover!(client)
22
+ return @commands if @commands
23
+ @commands = client.command.map{ |command_description|
24
+ command_name = command_description.shift.to_sym
25
+ Command.new(command_name, *command_description)
26
+ }
27
+ @read_commands = @commands.select { |command| command.flags.include?('readonly') }
28
+ @read_command_names = @read_commands.map(&:name).to_set
29
+ @commands
30
+ end
31
+
32
+ def self.extract_command(command_array)
33
+ command = command_array[0]
34
+ info = {command: command}
35
+ if COMMANDS_WITH_SUBCOMMANDS.include?(command)
36
+ subcommand = command_array[1]
37
+ info[:subcommand] = subcommand unless subcommand.nil?
38
+ end
39
+ info
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ require 'redis'
2
+ require 'active_support/notifications'
3
+
4
+ module RCI
5
+ module Instrumentation
6
+ def call(command, &block)
7
+ payload = extract_notification_payload_from(command)
8
+ ActiveSupport::Notifications.instrument("#{ Commands.command_type(command) }.redis", payload) do
9
+ super
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def extract_notification_payload_from(command_array)
16
+ Commands.extract_command(command_array)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module RCI
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rci/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rci'
8
+ spec.version = RCI::VERSION
9
+ spec.authors = ['Tyler Pickett']
10
+ spec.email = ['t.pickett66@gmail.com']
11
+
12
+ spec.summary = %q{Redis Client Instrumenter}
13
+ spec.description = %q{A little gem to wrap around calls to the official Ruby Redis clients and emmit ActiveSupport Notifications}
14
+ spec.homepage = 'https://github.com/tpickett66/rci'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+ spec.required_ruby_version = '>= 2.0'
22
+
23
+ spec.add_dependency 'activesupport', '>= 3.0', '< 5.0'
24
+ spec.add_dependency 'redis', '>= 2.0'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.9'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.3'
29
+ spec.add_development_dependency 'pry'
30
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Pickett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: redis
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.9'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.9'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.3'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.3'
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: A little gem to wrap around calls to the official Ruby Redis clients
104
+ and emmit ActiveSupport Notifications
105
+ email:
106
+ - t.pickett66@gmail.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - ".gitignore"
112
+ - ".rspec"
113
+ - ".travis.yml"
114
+ - CODE_OF_CONDUCT.md
115
+ - Gemfile
116
+ - LICENSE.txt
117
+ - README.md
118
+ - Rakefile
119
+ - lib/rci.rb
120
+ - lib/rci/commands.rb
121
+ - lib/rci/instrumentation.rb
122
+ - lib/rci/version.rb
123
+ - rci.gemspec
124
+ homepage: https://github.com/tpickett66/rci
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '2.0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.4.5
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Redis Client Instrumenter
148
+ test_files: []
149
+ has_rdoc: