ravanello 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +15 -0
- data/.travis.yml +17 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/ravanello +7 -0
- data/bin/setup +8 -0
- data/dip.yml +47 -0
- data/docker-compose.yml +20 -0
- data/lib/ravanello.rb +20 -0
- data/lib/ravanello/analyze.rb +45 -0
- data/lib/ravanello/analyzer.rb +28 -0
- data/lib/ravanello/cli.rb +25 -0
- data/lib/ravanello/formatter.rb +32 -0
- data/lib/ravanello/redis/cursor.rb +41 -0
- data/lib/ravanello/redis/key.rb +15 -0
- data/lib/ravanello/resolver.rb +50 -0
- data/lib/ravanello/router.rb +12 -0
- data/lib/ravanello/routing/base.rb +34 -0
- data/lib/ravanello/routing/match.rb +28 -0
- data/lib/ravanello/routing/root.rb +20 -0
- data/lib/ravanello/statistics.rb +35 -0
- data/lib/ravanello/version.rb +5 -0
- data/lib/ravanello/yaml.rb +40 -0
- data/ravanello.gemspec +33 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d2b644636451aefc6032e65d19e307985675eca
|
4
|
+
data.tar.gz: 76dffe8e4b8d8c710026534f2647bebe5d0605bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3b9a2d2db2810a631da81244ea9657d3386292aa622a97d558f5dbbe891a323f2fc0d7f4405962f287b4542d63eafa194fe0d52eec8e18ec324d182ee264cfa
|
7
|
+
data.tar.gz: 3d66ba4267857646b1e4df69e79705a03fcd4a32e219e52279825960029b721696ad516a63d503efaa788cc8e5d6fa16dc07eab27f2074e59e79f68fbe8e0e57
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- 'lib/**/*.rb'
|
4
|
+
- 'lib/**/*.rake'
|
5
|
+
- 'spec/**/*.rb'
|
6
|
+
Exclude:
|
7
|
+
- 'bin/**/*'
|
8
|
+
- 'spec/dummy/**/*'
|
9
|
+
- 'tmp/**/*'
|
10
|
+
- 'Rakefile'
|
11
|
+
- 'Gemfile'
|
12
|
+
- '*.gemspec'
|
13
|
+
DisplayCopNames: true
|
14
|
+
StyleGuideCopsOnly: false
|
15
|
+
TargetRubyVersion: 2.4
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.4.1
|
5
|
+
env:
|
6
|
+
- REDIS='redis://localhost/test'
|
7
|
+
services:
|
8
|
+
- redis-server
|
9
|
+
before_install: gem install bundler -v 1.16.0
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: TAnYgBKXalCx2RcfQ02sWN9m1p7vdQ1d/YcHn8A5pLIo3D3BWzcKcgW/UcsbRnS2JHOf/p8yorsxQ7HxJZ2x6dXSdlfgF/IVawpChL0XGQymFbf0H23M7mOWR+AztVEc63T6POBGp6c5hB7Ns2PtskAdxUxLsHqAOwNJ1egeTJ04arLbDvNNs+dtnzV5FcXUgN7Jj2lGw678lHHDUSGrGk/BdIPeGigmnuGS5Zg++3UMBzXE7Pmh3jrhvB/itBB9KIEWzFf5LnxM/okrIYV919+RwFJnrdmOYqfrnGTgxADDXqpnFQgezeKUA52H/5OAKBtBZDIla5VjElfpbMYW8sKZ6nhcPNgWL7Ax5j423MiiB+ZlVpRuECzHfGMG+YP/fZkOlEyKx6A7sW78uKBrEWSTyI30SCLdU+45b5rzY3CqjDCBeb7dSkxoBTO12lL/yO1eQAuxpSMe/OWUNi9eaOuBohd+LQuopyjJQtrIydGsn4xB/+/VGrbpjXoSBp0C/6EwOX4TFBawAP4/GFxIwuk6nfazS2pvTFOzAWNwKgbSU5BNcw6ezCnjO2SB5bdANK136+yhnT1UOi73zT6/uX7PFVQymoCvC/49ZhS7s8OrlOWxA6pfm/4uU9HRXGjjwp+rVr4sVwEb6MZ3NmfWM6IpPbwnw8WCtIM8mHOafa8=
|
14
|
+
gem: ravanello
|
15
|
+
on:
|
16
|
+
tags: true
|
17
|
+
repo: dsalahutdinov/ravanello
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dsalahutdinov@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Salahutdinov Dmitry
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Salahutdinov Dmitry
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Ravanello
|
2
|
+
|
3
|
+
This is the cli tool for analyze redis keys, what is very actual when you have many data in your redis.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Just install gem to your local environment
|
8
|
+
|
9
|
+
$ gem install ravanello
|
10
|
+
|
11
|
+
Or install it yourself as:
|
12
|
+
|
13
|
+
$ gem install ravanello
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```bash
|
18
|
+
FETCH_LIMIT=1000 REDIS_URL='redis://localhost/mydb' ravanello --rules rules.yml
|
19
|
+
```
|
20
|
+
|
21
|
+
You need to pass rules yml file, providing information about proposal keys structure
|
22
|
+
|
23
|
+
```yml
|
24
|
+
rules:
|
25
|
+
resque:
|
26
|
+
- 'delayed'
|
27
|
+
- "resque-retry"
|
28
|
+
- "timestamps"
|
29
|
+
- 'lock'
|
30
|
+
- 'meta'
|
31
|
+
denormalization:
|
32
|
+
- 'users'
|
33
|
+
- 'companies'
|
34
|
+
- 'orders'
|
35
|
+
- 'tenders'
|
36
|
+
- 'processed_batches'
|
37
|
+
- 'managers'
|
38
|
+
companies:
|
39
|
+
- 'dummy'
|
40
|
+
```
|
41
|
+
|
42
|
+
Samples of unclassified keys will be printer after analyze, and you will be able
|
43
|
+
to add them to rules file.
|
44
|
+
|
45
|
+
The FETCH_LIMIT is not required and is used for tests runs monstry (and for grouping key)
|
46
|
+
## Development
|
47
|
+
|
48
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
|
+
|
50
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ravanello. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
59
|
+
|
60
|
+
## Code of Conduct
|
61
|
+
|
62
|
+
Everyone interacting in the Ravanello project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ravanello/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ravanello"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/ravanello
ADDED
data/bin/setup
ADDED
data/dip.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
version: '1'
|
2
|
+
|
3
|
+
environment:
|
4
|
+
RAILS_ENV: test
|
5
|
+
REDIS: 'redis://redis/test'
|
6
|
+
|
7
|
+
compose:
|
8
|
+
files:
|
9
|
+
- docker-compose.yml
|
10
|
+
|
11
|
+
interaction:
|
12
|
+
sh:
|
13
|
+
service: app
|
14
|
+
|
15
|
+
bundle:
|
16
|
+
service: app
|
17
|
+
command: bundle
|
18
|
+
|
19
|
+
rake:
|
20
|
+
service: app
|
21
|
+
command: bundle exec rake
|
22
|
+
|
23
|
+
rubocop:
|
24
|
+
service: app
|
25
|
+
command: bundle exec rake rubocop
|
26
|
+
|
27
|
+
rspec:
|
28
|
+
service: app
|
29
|
+
command: bundle exec rspec
|
30
|
+
|
31
|
+
clean:
|
32
|
+
service: app
|
33
|
+
command: rm -f Gemfile.lock
|
34
|
+
|
35
|
+
console:
|
36
|
+
service: app
|
37
|
+
command: './bin/console'
|
38
|
+
|
39
|
+
ravanello:
|
40
|
+
service: app
|
41
|
+
command: './bin/ravanello'
|
42
|
+
|
43
|
+
|
44
|
+
provision:
|
45
|
+
- docker volume create --name bundle
|
46
|
+
- dip clean
|
47
|
+
- dip bundle install
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
version: '3'
|
2
|
+
|
3
|
+
services:
|
4
|
+
app:
|
5
|
+
image: ruby
|
6
|
+
command: bash
|
7
|
+
working_dir: /app
|
8
|
+
depends_on:
|
9
|
+
- redis
|
10
|
+
volumes:
|
11
|
+
- .:/app
|
12
|
+
- bundle:/usr/local/bundle
|
13
|
+
#network_mode: host
|
14
|
+
|
15
|
+
redis:
|
16
|
+
image: redis
|
17
|
+
|
18
|
+
volumes:
|
19
|
+
bundle:
|
20
|
+
external: true
|
data/lib/ravanello.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ravanello/version'
|
4
|
+
require 'ravanello/redis/key'
|
5
|
+
require 'ravanello/redis/cursor'
|
6
|
+
require 'ravanello/router'
|
7
|
+
require 'ravanello/routing/base'
|
8
|
+
require 'ravanello/routing/root'
|
9
|
+
require 'ravanello/routing/match'
|
10
|
+
require 'ravanello/resolver'
|
11
|
+
require 'ravanello/analyzer'
|
12
|
+
require 'ravanello/formatter'
|
13
|
+
require 'ravanello/statistics'
|
14
|
+
require 'ravanello/yaml'
|
15
|
+
require 'ravanello/cli'
|
16
|
+
|
17
|
+
# Analyzes redis keys classes
|
18
|
+
module Ravanello
|
19
|
+
# Your code goes here...
|
20
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ravanello'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module Ravanello
|
7
|
+
# Redis analyze command
|
8
|
+
class Analyze
|
9
|
+
attr_reader :options
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
router = Yaml.new(File.read(options.fetch('rules'))).call
|
17
|
+
cursor = Redis::Cursor.new(redis, limit: redis_fetch_limit)
|
18
|
+
statistics = Analyzer.new(router, cursor).call
|
19
|
+
print(statistics)
|
20
|
+
print_samples(statistics)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def print(statistics)
|
26
|
+
Ravanello::Formatter.new(statistics).call.each { |line| puts line }
|
27
|
+
end
|
28
|
+
|
29
|
+
def print_samples(statistics)
|
30
|
+
return if statistics.data['*'].nil?
|
31
|
+
puts 'Discard sample keys:'
|
32
|
+
samples = (1..10).map { statistics.data['*'].samples.sample.name }.uniq
|
33
|
+
samples.each { |sample| puts "\t#{sample}" }
|
34
|
+
end
|
35
|
+
|
36
|
+
def redis
|
37
|
+
@redis ||= ::Redis.new(url: ENV['REDIS'])
|
38
|
+
end
|
39
|
+
|
40
|
+
def redis_fetch_limit
|
41
|
+
fetch_limit = ENV['FETCH_LIMIT']
|
42
|
+
fetch_limit.nil? || fetch_limit == '' ? nil : fetch_limit.to_i
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ravanello
|
4
|
+
# Analyzes data by router
|
5
|
+
class Analyzer
|
6
|
+
def initialize(router, data)
|
7
|
+
@data = data
|
8
|
+
@router = router
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
statistics = Ravanello::Statistics.new
|
13
|
+
|
14
|
+
@data.each do |redis_key|
|
15
|
+
end_point = resolver.call(redis_key.name)
|
16
|
+
statistics.append(end_point.to_s, redis_key)
|
17
|
+
end
|
18
|
+
|
19
|
+
statistics
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def resolver
|
25
|
+
@resolver ||= Ravanello::Resolver.new(@router)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ravanello'
|
4
|
+
require 'ravanello/analyze'
|
5
|
+
require 'thor'
|
6
|
+
|
7
|
+
module Ravanello
|
8
|
+
# Dispatches command line commands
|
9
|
+
class Cli < Thor
|
10
|
+
default_task :analyze
|
11
|
+
|
12
|
+
desc 'analyze', 'Run redis analyze'
|
13
|
+
method_option :rules, desc: 'Path to file with grouping keys rules'
|
14
|
+
|
15
|
+
def analyze
|
16
|
+
Analyze.new(options).call
|
17
|
+
end
|
18
|
+
|
19
|
+
map %w[--version -v] => :__print_version
|
20
|
+
desc '--version, -v', 'Print gem version'
|
21
|
+
def __print_version
|
22
|
+
puts VERSION
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Ravanello
|
6
|
+
# Formats analyzed statistics and render it as string arrays
|
7
|
+
class Formatter
|
8
|
+
def initialize(statistics)
|
9
|
+
@statistics = statistics
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
data.map do |path|
|
14
|
+
data_item = @statistics.data[path]
|
15
|
+
format(
|
16
|
+
'%-5s %-5s %s (%s)',
|
17
|
+
data_item.count.to_s,
|
18
|
+
data_item.size.to_s,
|
19
|
+
path.to_s,
|
20
|
+
data_item.samples.sample.name
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def data
|
28
|
+
# @statistics.data.keys.sort_by { |k| @statistics.data[k].size }.reverse
|
29
|
+
@statistics.data.keys.sort_by(&:to_s)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'redis'
|
4
|
+
module Ravanello
|
5
|
+
module Redis
|
6
|
+
# Redis key cursor enumarable type
|
7
|
+
class Cursor
|
8
|
+
SIZE_REGEX = /serializedlength:(\d*)/
|
9
|
+
|
10
|
+
include Enumerable
|
11
|
+
attr_reader :redis
|
12
|
+
|
13
|
+
KEYS_BATCH_SIZE = 2_000
|
14
|
+
|
15
|
+
def initialize(redis, limit: nil)
|
16
|
+
@redis = redis
|
17
|
+
@limit = limit
|
18
|
+
end
|
19
|
+
|
20
|
+
def each
|
21
|
+
counter = 0
|
22
|
+
cursor = 0
|
23
|
+
while cursor != '0'
|
24
|
+
cursor, keys = redis.scan(cursor, count: KEYS_BATCH_SIZE)
|
25
|
+
keys.each do |key|
|
26
|
+
break if !@limit.nil? && counter >= @limit
|
27
|
+
counter += 1
|
28
|
+
yield(Key.new(key, size(key)))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def size(key)
|
36
|
+
debug_data = redis.debug('object', key)
|
37
|
+
SIZE_REGEX.match(debug_data)[1].to_i
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ravanello
|
4
|
+
# Resolves redis key to the endpoint
|
5
|
+
class Resolver
|
6
|
+
attr_reader :router
|
7
|
+
|
8
|
+
def initialize(router, options = {})
|
9
|
+
@router = router
|
10
|
+
@separator = options.fetch(:separator, ':')
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(path)
|
14
|
+
path_parts = path.split(@separator)
|
15
|
+
resolved = NodeResolver.new(router.root, *path_parts).call
|
16
|
+
|
17
|
+
raise Error, "Error resolving #{path}" if resolved.nil?
|
18
|
+
|
19
|
+
resolved
|
20
|
+
end
|
21
|
+
|
22
|
+
# Resolves endpoint by node
|
23
|
+
class NodeResolver
|
24
|
+
attr_reader :node, :path
|
25
|
+
|
26
|
+
def initialize(node, *path)
|
27
|
+
@node = node
|
28
|
+
@path = path
|
29
|
+
end
|
30
|
+
|
31
|
+
def call
|
32
|
+
if node.routable?(path)
|
33
|
+
new_path = node.route(path)
|
34
|
+
return node if new_path.empty?
|
35
|
+
|
36
|
+
node.children.each do |child|
|
37
|
+
resolved = NodeResolver.new(child, *new_path).call
|
38
|
+
return resolved unless resolved.nil?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Represents resolving path error
|
47
|
+
class Error < ::StandardError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ravanello
|
4
|
+
module Routing
|
5
|
+
# Base key routing class
|
6
|
+
class Base
|
7
|
+
attr_reader :children, :parent
|
8
|
+
|
9
|
+
def initialize(parent = nil, &blk)
|
10
|
+
@parent = parent
|
11
|
+
@children = []
|
12
|
+
instance_eval(&blk) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def match(name, &blk)
|
16
|
+
namespace = Ravanello::Routing::Match.new(name.to_s, self, &blk)
|
17
|
+
children.push(namespace)
|
18
|
+
namespace
|
19
|
+
end
|
20
|
+
|
21
|
+
def routable?(*)
|
22
|
+
raise StandardError, 'Not implemented'
|
23
|
+
end
|
24
|
+
|
25
|
+
def route(*)
|
26
|
+
raise StandardError, 'Not implemented'
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
raise StandardError, 'Not implemented'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ravanello
|
4
|
+
module Routing
|
5
|
+
# Represents regex match routing rule
|
6
|
+
class Match < Base
|
7
|
+
attr_reader :regex
|
8
|
+
|
9
|
+
def initialize(regex, parent, &blk)
|
10
|
+
@regex = regex
|
11
|
+
super(parent, &blk)
|
12
|
+
end
|
13
|
+
|
14
|
+
def routable?(path_parts)
|
15
|
+
regex == '*' ? !path_parts.empty? : !path_parts.first.match(regex).nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def route(path_parts)
|
19
|
+
return [] if regex == '*'
|
20
|
+
path_parts[1..path_parts.length - 1]
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
"#{parent}#{regex}#{children.empty? ? '' : ':'}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ravanello
|
4
|
+
module Routing
|
5
|
+
# Root routing tree element
|
6
|
+
class Root < Base
|
7
|
+
def routable?(*)
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def route(path_parts)
|
12
|
+
path_parts
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
''
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ravanello
|
4
|
+
# Contains statistics result for the matched groups
|
5
|
+
class Statistics
|
6
|
+
attr_reader :data
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@data = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def append(path, redis_key)
|
13
|
+
data[path] = Item.new if data[path].nil?
|
14
|
+
|
15
|
+
data[path].inc(redis_key)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Holds information about size and count of matched key group
|
19
|
+
class Item
|
20
|
+
attr_reader :count, :size, :samples
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@count = 0
|
24
|
+
@size = 0
|
25
|
+
@samples = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def inc(redis_key)
|
29
|
+
@count += 1
|
30
|
+
@size += redis_key.size
|
31
|
+
@samples.push(redis_key) if @samples.count < 100
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
module Ravanello
|
5
|
+
# Loads the router from yml file
|
6
|
+
class Yaml
|
7
|
+
def initialize(yaml)
|
8
|
+
@source = YAML.safe_load(yaml)
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
router = Ravanello::Router.new
|
13
|
+
process_group(router.root, @source['rules'])
|
14
|
+
router
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def process_group(parent, yaml)
|
20
|
+
case yaml
|
21
|
+
when Hash
|
22
|
+
process_hash_group(parent, yaml)
|
23
|
+
when Array
|
24
|
+
process_array_group(parent, yaml)
|
25
|
+
end
|
26
|
+
|
27
|
+
parent.match('*')
|
28
|
+
end
|
29
|
+
|
30
|
+
def process_hash_group(parent, yaml)
|
31
|
+
yaml.each do |k, v|
|
32
|
+
process_group(parent.match(k), v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_array_group(parent, yaml)
|
37
|
+
yaml.each { |name| parent.match(name).match('*') }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/ravanello.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ravanello/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ravanello"
|
8
|
+
spec.version = Ravanello::VERSION
|
9
|
+
spec.authors = ["Salahutdinov Dmitry"]
|
10
|
+
spec.email = ["dsalahutdinov@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ravanello gem}
|
13
|
+
spec.description = %q{Ravanello gem}
|
14
|
+
spec.homepage = "https://github.com/dsalahutdinov/ravanello"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = ['ravanello']
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "redis"
|
25
|
+
spec.add_runtime_dependency "thor"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "pry-byebug"
|
31
|
+
spec.add_development_dependency "rubocop", "~> 0.49"
|
32
|
+
spec.add_development_dependency "simplecov"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ravanello
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Salahutdinov Dmitry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-11 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.49'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.49'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Ravanello gem
|
126
|
+
email:
|
127
|
+
- dsalahutdinov@gmail.com
|
128
|
+
executables:
|
129
|
+
- ravanello
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- ".travis.yml"
|
137
|
+
- CODE_OF_CONDUCT.md
|
138
|
+
- Gemfile
|
139
|
+
- LICENSE
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- bin/console
|
144
|
+
- bin/ravanello
|
145
|
+
- bin/setup
|
146
|
+
- dip.yml
|
147
|
+
- docker-compose.yml
|
148
|
+
- lib/ravanello.rb
|
149
|
+
- lib/ravanello/analyze.rb
|
150
|
+
- lib/ravanello/analyzer.rb
|
151
|
+
- lib/ravanello/cli.rb
|
152
|
+
- lib/ravanello/formatter.rb
|
153
|
+
- lib/ravanello/redis/cursor.rb
|
154
|
+
- lib/ravanello/redis/key.rb
|
155
|
+
- lib/ravanello/resolver.rb
|
156
|
+
- lib/ravanello/router.rb
|
157
|
+
- lib/ravanello/routing/base.rb
|
158
|
+
- lib/ravanello/routing/match.rb
|
159
|
+
- lib/ravanello/routing/root.rb
|
160
|
+
- lib/ravanello/statistics.rb
|
161
|
+
- lib/ravanello/version.rb
|
162
|
+
- lib/ravanello/yaml.rb
|
163
|
+
- ravanello.gemspec
|
164
|
+
homepage: https://github.com/dsalahutdinov/ravanello
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubyforge_project:
|
184
|
+
rubygems_version: 2.6.11
|
185
|
+
signing_key:
|
186
|
+
specification_version: 4
|
187
|
+
summary: Ravanello gem
|
188
|
+
test_files: []
|