FunWithFlags

Build StatusHex.pmhexdocs.pm

FunWithFlags, the Elixir feature flag library.

This library is still a work in progress and is not ready to use

This readme refers to the master branch. For the latest version released on Hex, please check the readme published with the docs.

Goals

This library is meant to be an OTP application that provides an Elixir API to toggle and query feature flags and an (authenticated) web UI for administrators.

It should store feature flag information in Redis for persistence and syncronize different nodes, but it should also maintain a local cache in an ETS table for fast lookup. When flags are added or toggled, nodes should be notified (via Redis PubSub or polling) and update their local ETS representation.

Different kind of feature flags should be supported:

The planned functionality of this library is heavily inspired by the flipper Ruby gem, although with a focus on:

Just as Elixir and Phoenix are meant to scale better than Ruby on Rails with high levels of traffic and concurrency, FunWithFlags should aim to be more scalable than Flipper.

Status and Roadmap

Done

Next / Problems

Configuration

The library can be configured in host applications through Mix and the config.exs file. This example shows the default values:

config :fun_with_flags, :cache,
  enabled: true,
  ttl: 900 # in seconds

# the Redis options will be forwarded to Redix
config :fun_with_flags, :redis,
  host: 'localhost',
  port: 6379,
  database: 0

Usage

Still a work in progress, expect breaking changes.

FunWithFlags.enabled?(:cool_new_feature)
false

{:ok, true} = FunWithFlags.enable(:cool_new_feature)

FunWithFlags.enabled?(:cool_new_feature)
true

{:ok, false} = FunWithFlags.disable(:cool_new_feature)

FunWithFlags.enabled?(:cool_new_feature)
false

Installation

The package can be installed by adding fun_with_flags to your list of dependencies in mix.exs:

def deps do
  [{:fun_with_flags, "~> 0.0.6"}]
end

Test

This library depends on Redis and you'll need it installed on your system in order to run the tests. A test run will create a few keys in the Redis db number 5 and then remove them, but it's safer to start Redis in a directory where there is no dump.rdb file you care about to avoid issues.

Start Redis with:

$ redis-server

Then:

$ mix test.all

The test.all task will run the default mix test task with MIX_ENV=test, and then will switch to a custom MIX_ENV=test_no_cache environment where the ETS cache is disabled and re-run the integration tests.