Feature flippers.
<img src=“https://travis-ci.org/FetLife/rollout.svg?branch=master” alt=“Build Status” />
As of rollout-2.x, only one key is used per feature for performance reasons. The data format is percentage|user_id,user_id,...|group,_group...
. This has the effect of making concurrent feature modifications unsafe, but in practice, I doubt this will actually be a problem.
This also has the effect of rollout no longer being dependent on redis. Just give it something that responds to set(key,value)
and get(key)
.
If you have been using the 1.x format, you can initialize Rollout with :migrate => true
and it’ll do its best to automatically migrate your old features to the new format. There will be some performance impact, but it should be limited and short-lived since each feature only needs to get migrated once.
If you’d prefer to continue to use the old layout in redis, Rollout::Legacy
is a copy and paste of the old code :-).
gem install rollout
Initialize a rollout object. I assign it to a global var.
require 'redis' $redis = Redis.new $rollout = Rollout.new($redis)
Check whether a feature is active for a particular user:
$rollout.active?(:chat, User.first) # => true/false
Check whether a feature is active globally:
$rollout.active?(:chat)
You can activate features using a number of different mechanisms.
Rollout ships with one group by default: “all”, which does exactly what it sounds like.
You can activate the all group for the chat feature like this:
$rollout.activate_group(:chat, :all)
You might also want to define your own groups. We have one for our caretakers:
$rollout.define_group(:caretakers) do |user| user.caretaker? end
You can activate multiple groups per feature.
Deactivate groups like this:
$rollout.deactivate_group(:chat, :all)
You might want to let a specific user into a beta test or something. If that user isn’t part of an existing group, you can let them in specifically:
$rollout.activate_user(:chat, @user)
Deactivate them like this:
$rollout.deactivate_user(:chat, @user)
If you’re rolling out a new feature, you might want to test the waters by slowly enabling it for a percentage of your users.
$rollout.activate_percentage(:chat, 20)
The algorithm for determining which users get let in is this:
CRC32(user.id) % 100 < percentage
So, for 20%, users 0, 1, 10, 11, 20, 21, etc would be allowed in. Those users would remain in as the percentage increases.
Deactivate all percentages like this:
$rollout.deactivate_percentage(:chat)
_Note that activating a feature for 100% of users will also make it active “globally”. That is when calling Rollout#active? without a user object._
Deactivate everybody at once:
$rollout.deactivate(:chat)
For many of our features, we keep track of error rates using redis, and deactivate them automatically when a threshold is reached to prevent service failures from cascading. See github.com/jamesgolick/degrade for the failure detection code.
Rollout separates its keys from other keys in the data store using the “feature” keyspace.
If you’re using redis, you can namespace keys further to support multiple environments by using the github.com/defunkt/redis-namespace gem.
$ns = Redis::Namespace.new(Rails.env, :redis => $redis) $rollout = Rollout.new($ns) $rollout.activate_group(:chat, :all)
This example would use the “development:feature:chat:groups” key.
In our infrastructure, rollout obviously allows us to progressively enable new features but we also use it to automatically disable features and services that break or fail to prevent them from causing cascading failures and wiping out our entire system.
When a feature reaches “maturity” - in other words, expected to be at 100% rollout all the time - we use check_rollout.rb to setup nagios alerts on the rollouts so that we get paged if one of them gets disabled.
-
Python: github.com/asenchi/proclaim
-
Clojure: github.com/tcrayford/shoutout
-
James Golick - Creator - github.com/jamesgolick
-
Eric Rafaloff - Maintainer - github.com/EricR
Copyright © 2010-InfinityAndBeyond BitLove, Inc. See LICENSE for details.