slow_ride 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/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/README.md +96 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/slow_ride/version.rb +5 -0
- data/lib/slow_ride.rb +93 -0
- data/slow_ride.gemspec +37 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98df04ad0ae62d3f69aafc2908fbf5a83fdbe0365fa5236d335578a09daeb802
|
4
|
+
data.tar.gz: c62f23723655b807fe1d55862334eecf84ec327ab0a720d1597543f5669bdb78
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30f03d20f31902b63300c21bda56bd03fd4db4978051af08054ca8e7295bc982847a577cdbc69ca6583578aa619d48ccb8bfdd0ba4731adf5448aa683a36608f
|
7
|
+
data.tar.gz: b15981518c4e9522d44b1f51f5c4891329c159dbb9985c5e2307960ea5d063c4c11cae07d8e74b9687b4b95ec3d012a471c2677a96f8b35b47c35f5806803845
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jgaskins@hey.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# SlowRide
|
2
|
+
|
3
|
+
When you've enabled a feature flag (for example, with [Flipper](https://github.com/jnunemaker/flipper) or [LaunchDarkly](https://launchdarkly.com)), what often follows is that a human being has to pay attention to error rates or, at the very least, respond to alerts about an increase in those error rates.
|
4
|
+
|
5
|
+
With SlowRide, you can take it easy.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'slow_ride'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install slow_ride
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
SlowRide was designed around the idea of pluggable backends. Right now, however, Redis is the only backend offered.
|
26
|
+
|
27
|
+
### Redis
|
28
|
+
|
29
|
+
SlowRide can use Redis to store the check and failure counts. To use it, load the SlowRide and Redis gems and define how you connect to Redis:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require "redis"
|
33
|
+
require "slow_ride"
|
34
|
+
|
35
|
+
# The `redis` gem uses ENV["REDIS_URL"] by default, so if you use that env var
|
36
|
+
# you can simply use `Redis.new` for your Redis block.
|
37
|
+
SlowRide.enable_redis { Redis.new }
|
38
|
+
```
|
39
|
+
|
40
|
+
Define your feature by giving it a name, a failure threshold, a minimum number of checks (defaults to 1000), and a way to disable the feature flag.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# If we reach 20% failures, shut off the feature.
|
44
|
+
MY_FEATURE = SlowRide::Redis.new("my-feature", failure_threshold: 0.2) do
|
45
|
+
Flipper.disable "my-feature"
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
You can also notify your team that the feature flag has been disabled:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
MY_FEATURE = SlowRide::Redis.new(:my_feature, failure_threshold: 0.2) do
|
53
|
+
Flipper.disable :my_feature
|
54
|
+
Slack.notify "#slow-ride", "Feature `my-feature` has exceeded 20% failures and has been disabled"
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
Then, in your feature-flag code paths, you call `MY_FEATURE.check { ... }`:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
if Flipper.enabled? :my_feature
|
62
|
+
MY_FEATURE.check { new_hotness! }
|
63
|
+
else
|
64
|
+
old_and_busted!
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
_Please do not use this gem as a replacement for error reporting!_ I mean, you can do whatever you like and I can't stop you, but I'll be sad if you use it this way. The intent is that the block twiddles whatever bits it needs to in order to ensure the feature isn't checked anymore at all — such as by disabling a feature flag.
|
69
|
+
|
70
|
+
You can also pass a couple other options:
|
71
|
+
|
72
|
+
- `minimum_checks:` — the number of checks required to be run before SlowRide invokes the feature's block
|
73
|
+
- `max_duration:` — the number of seconds to store the feature data in Redis
|
74
|
+
|
75
|
+
#### Cleanup
|
76
|
+
|
77
|
+
Redis-backed features will automatically clean up after themselves.
|
78
|
+
|
79
|
+
- When a failure threshold is reached, the data is automatically deleted from Redis.
|
80
|
+
- If a failure threshold is never reached before removing the feature flag from your code, the data will expire from Redis after a default duration of one week.
|
81
|
+
|
82
|
+
You can override the max storage duration for any reason by passing `max_duration:` to the feature definition. The default is one week and assumes that feature checks will happen far more often than that. This way, you don't need to delete anything manually when you remove a feature flag from your codebase.
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
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.
|
87
|
+
|
88
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jgaskins/slow_ride. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/jgaskins/slow_ride/blob/main/CODE_OF_CONDUCT.md).
|
93
|
+
|
94
|
+
## Code of Conduct
|
95
|
+
|
96
|
+
Everyone interacting in the SlowRide project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jgaskins/slow_ride/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "slow_ride"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/slow_ride.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "connection_pool"
|
4
|
+
|
5
|
+
require_relative "slow_ride/version"
|
6
|
+
|
7
|
+
module SlowRide
|
8
|
+
Error = Class.new(StandardError)
|
9
|
+
RedisNotConfigured = Class.new(Error)
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def enable_redis(max_connections: 25, &block)
|
13
|
+
@redis_pool = ConnectionPool.new(size: max_connections, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def redis(&block)
|
17
|
+
if @redis_pool
|
18
|
+
@redis_pool.with(&block)
|
19
|
+
else
|
20
|
+
raise RedisNotConfigured, "Must configure Redis with `SlowRide.enable_redis { Redis.new(...) }`"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Adapter
|
26
|
+
def initialize(failure_threshold:, minimum_checks: 1_000, &failure_handler)
|
27
|
+
@failure_threshold = failure_threshold
|
28
|
+
@minimum_checks = minimum_checks
|
29
|
+
@failure_handler = failure_handler
|
30
|
+
end
|
31
|
+
|
32
|
+
def check
|
33
|
+
checked_count = checked
|
34
|
+
|
35
|
+
begin
|
36
|
+
yield
|
37
|
+
rescue => ex
|
38
|
+
failed_count = failed
|
39
|
+
|
40
|
+
if checked_count >= @minimum_checks && failed_count.to_f / checked_count >= @failure_threshold
|
41
|
+
@failure_handler.call failed_count, checked_count
|
42
|
+
failure_threshold_exceeded failed: failed_count, checked: checked_count
|
43
|
+
end
|
44
|
+
raise ex
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def failure_threshold_exceeded(failed:, checked:)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Redis < Adapter
|
53
|
+
# The default expiration for a given key. We set it to a week and refresh
|
54
|
+
# the expiration each time a check is made.
|
55
|
+
#
|
56
|
+
# IT'S BEEN ...
|
57
|
+
ONE_WEEK = 60 * # seconds
|
58
|
+
60 * # minutes
|
59
|
+
24 * # hours
|
60
|
+
7 # days
|
61
|
+
|
62
|
+
def initialize(name, failure_threshold:, minimum_checks: 1_000, max_duration: ONE_WEEK, &failure_handler)
|
63
|
+
super failure_threshold: failure_threshold, minimum_checks: minimum_checks, &failure_handler
|
64
|
+
@name = name
|
65
|
+
@max_duration = max_duration
|
66
|
+
@checked_key = "slow-ride:#{name}:checked"
|
67
|
+
@failed_key = "slow-ride:#{name}:failed"
|
68
|
+
end
|
69
|
+
|
70
|
+
def checked
|
71
|
+
SlowRide.redis do |redis|
|
72
|
+
redis.pipelined do |redis|
|
73
|
+
redis.incr @checked_key
|
74
|
+
redis.expire @checked_key, @max_duration
|
75
|
+
redis.expire @failed_key, @max_duration
|
76
|
+
end
|
77
|
+
end.first
|
78
|
+
end
|
79
|
+
|
80
|
+
def failed
|
81
|
+
SlowRide.redis { |redis| redis.incr @failed_key }
|
82
|
+
end
|
83
|
+
|
84
|
+
def failure_threshold_exceeded(failed:, checked:)
|
85
|
+
SlowRide.redis do |redis|
|
86
|
+
redis.pipelined do |redis|
|
87
|
+
redis.del @checked_key
|
88
|
+
redis.del @failed_key
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/slow_ride.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/slow_ride/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "slow_ride"
|
7
|
+
spec.version = SlowRide::VERSION
|
8
|
+
spec.authors = ["Jamie Gaskins"]
|
9
|
+
spec.email = ["jgaskins@hey.com"]
|
10
|
+
|
11
|
+
spec.summary = "Check features"
|
12
|
+
spec.description = "check features"
|
13
|
+
spec.homepage = "https://github.com/jgaskins/slow_ride"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
spec.add_dependency "connection_pool"
|
33
|
+
spec.add_development_dependency "redis"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slow_ride
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Gaskins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: connection_pool
|
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: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: check features
|
42
|
+
email:
|
43
|
+
- jgaskins@hey.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- CHANGELOG.md
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- Gemfile
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/slow_ride.rb
|
57
|
+
- lib/slow_ride/version.rb
|
58
|
+
- slow_ride.gemspec
|
59
|
+
homepage: https://github.com/jgaskins/slow_ride
|
60
|
+
licenses: []
|
61
|
+
metadata:
|
62
|
+
homepage_uri: https://github.com/jgaskins/slow_ride
|
63
|
+
source_code_uri: https://github.com/jgaskins/slow_ride
|
64
|
+
changelog_uri: https://github.com/jgaskins/slow_ride
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.6.0
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.2.22
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Check features
|
84
|
+
test_files: []
|