Skip to content

Commit

Permalink
Merge pull request #15 from jcagarcia/new_features
Browse files Browse the repository at this point in the history
Applying changes for adding features described in #10 #11 #13 #14
  • Loading branch information
jcagarcia authored Oct 28, 2023
2 parents 11d4c3a + 9e1081b commit 2702463
Show file tree
Hide file tree
Showing 22 changed files with 1,158 additions and 579 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All changes to `rollout-redis` will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2023-10-28

### Added
- `#with_old_rollout_gem_compatibility` method for allowing working with Feature Flags that were stored by the old `rollout` gem.
- `rollout:migrate_from_rollout_format` rake task for performing a migration of the feature flags stored by the old `rollout` gem to the new `rollout-redis` format.
- Add a new parameter when performing `#activate` method for providing a specific degrade configuration for the feature flag that is being activated.
- Add a new parameter when performing `rollout:on` rake task for providing a specific degrade configuration for the feature flag that is being activated.
- You can implement now your own `Rollout::Notifications::Channels::Channel` in case the ones offered by the `gem` are not enough.

## [1.0.0] - 2023-10-25

Expand Down
9 changes: 4 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rollout-redis (1.0.0)
rollout-redis (1.1.0)
mail (~> 2.8)
redis (>= 4.0, <= 5)
slack-notifier (~> 2.4)
Expand All @@ -18,7 +18,7 @@ GEM
net-pop
net-smtp
mini_mime (1.1.5)
mock_redis (0.37.0)
mock_redis (0.38.0)
net-imap (0.4.2)
date
net-protocol
Expand All @@ -28,10 +28,10 @@ GEM
timeout
net-smtp (0.4.0)
net-protocol
rake (13.0.6)
rake (13.1.0)
redis (5.0.0)
redis-client (~> 0.7)
redis-client (0.17.1)
redis-client (0.18.0)
connection_pool
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand All @@ -51,7 +51,6 @@ GEM

PLATFORMS
aarch64-linux
arm64-darwin-23

DEPENDENCIES
bundler (>= 2.4)
Expand Down
49 changes: 41 additions & 8 deletions MIGRATING_FROM_ROLLOUT_GEM.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

In this guide you can find the most important changes and differences between the old rollout gem and this gem.

- [Deprecations](#deprecations)
- [New methods](#new-methods-)
- [Important Changes](#important-changes-)
- [Keys format and stored data has been changed](#keys-format-and-stored-data-has-been-changed-)
- [Migrating Feature Flags](#migrating-feature-flags)
- [Make the gem compatible](#make-the-gem-compatible)

## Deprecations

In order to simplify the features of the first versions of the gem, the following capabilities have been removed:
Expand All @@ -13,26 +20,24 @@ In order to simplify the features of the first versions of the gem, the followin

This is the complete list of methods that have been removed: `#groups`, `#delete`, `#set`, `#activate_group`, `#deactivate_group`, `#activate_user`, `#deactivate_user`, `#activate_users`, `#deactivate_users`, `#set_users`, `#define_group`, `#user_in_active_users?`, `#inactive?`, `#deactivate_percentage`, `active_in_group?`, `#get`, `#set_feature_data`, `#clear_feature_data`, `#multi_get`, `#feature_states`, `#active_features`, `#clear!`, `#exists?`, `#with_feature`.

If you consider some of these methods or features 👆 should be added again to the gem, please, open an issue and we will evaluate it.
If you consider some of these 👆 methods or features should be added again to the gem, please, open an discussion and we will evaluate it.

## New methods 🎁

New methods has been added: `#with_cache`, `#with_degrade`, `#with_feature_flag`, `#clean_cache`.
New methods has been added: `#with_cache`, `#with_degrade`, `#with_feature_flag`, `#clean_cache`, `#with_notifications`.

## Important changes 🚨

### Keys format and stored data has been changed 🔑

The old [rollout](https://github.com/fetlife/rollout) gem is storing the features flags using `feature:#{name}` as key format. The stored value for each feature flag is a string with this format: `percentage|users|groups|data`. This an example of a current flag stored in redis:
The old [rollout](https://github.com/fetlife/rollout) gem is storing the features flags using `feature:#{name}` as key format. The stored value for each feature flag is a string with this format: `percentage|users|groups|data`. This an example of a feature flag stored in redis by the **old** `rollout` gem:

```
Key: "feature:my-feature-flag"
Value: "100|||{}"
```

We have decided to store the data of each feature flag in a more understandable way, so as we don't want to collision with your current stored feature flags this new gem is using `feature-rollout-redis:#{name}` as namespace for storing the new feature flag names in redis.

_NOTE_: This mean that any of your current active feature flags will be taken into consideration!!!
We have decided to store the data of each feature flag in a more understandable way so, as we don't want to collision with your current stored feature flags, our new gem is using `feature-rollout-redis:#{name}` as namespace for storing the new feature flag names in redis.

Also, the stored information has been changed and now is a JSON:

Expand All @@ -44,14 +49,42 @@ Also, the stored information has been changed and now is a JSON:
}
```

This mean that any of your current active feature flags will NOT be taken into consideration when asking if `#active?`!!!

If you want to keep working with your current feature flags, you have two options:

#### Migrating feature flags

In order to facilitate the migration, we are offering a method for easily move from the old format to the new one.
If you decide to fully go with the new `rollout-redis` gem structure, we are offering a method for easily move from the old format to the new one.

```ruby
@rollout.migrate_from_rollout_format
```

This method will NOT remove your old stored feature flags. It will just perform a migration.

Take into consideration that as we are removing users and groups capabilities, you will lost that information after performing the migration. If you want to keep that information, we encourage you to build your own method/script for performing the migration.
Also, we are offering a rake task for performing this method in an easy way before start using the new gem.

```shell
bundle exec rake rollout:migrate_from_rollout_format
```

Take into consideration that as we are removing users and groups capabilities, you will lost that information after performing the migration. If you want to keep that information, we encourage you to build your own method/script for performing the migration.

#### Make the gem compatible

However, if you want to keep your old feature flags stored in your Redis, you can configure the `Rollout` instance for checking them. So when using the `#active?` method or the `#with_feature_flag` merhod, if the feature flag does not exist using the new key format, we will check the old format and if exists:

1. We will parse the content to match the new format
2. If enabled, we will automatically store it in the new format to do a gradual migration.
3. We will return if the requested feature flag is active or not.

For doing that, you can use the `#with_old_rollout_gem_compatibility` instance method when creating the rollout instance:

```ruby
@rollout ||= Rollout.new(@storage)
.with_cache
.with_degrade
.with_old_rollout_gem_compatibility(auto_migration: true)
```

58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Topics covered in this README:
- [Sending Notifications](#sending-notifications)
- [Rake tasks](#rake-tasks)
- [Migrating from rollout gem](#migrating-from-rollout-gem-)
- [Compatible payloads and keys](#compatible-payloads-and-keys)
- [Changelog](#changelog)
- [Contributing](#contributing)

Expand Down Expand Up @@ -143,14 +144,26 @@ In the case that you need to clear the cache at any point, you can make use of t

### Auto-deactivating flags

If you want to allow the gem to deactivate your feature flag automatically when a threshold of errors is reached, you can enable the degrade feature using the `with_degrade` method.
If you want to allow the gem to deactivate all the feature flags automatically when a threshold of errors is reached, you can enable the degrade feature using the `with_degrade` method.

```ruby
@rollout ||= Rollout.new(redis)
.with_cache
.with_degrade(min: 100, threshold: 0.1)
```

However, if you just want to activate the degradation of an specific feature flag, you need to provide the following information when activating the feature flag (note that now the percentage is a mandatory parameter if you want to pass the degrade options):

```ruby
@rollout.activate('FEATURE_FLAG_NAME', 100, degrade: { min: 500, threshold: 0.2 })
```

The same configuration 👆 is available when using the rake task for activating the feature flag. Check [Rake tasks](#rake-tasks) section.

```shell
bundle exec rake rollout:on[FEATURE_FLAG_NAME,100,500,0.2]
```

So now, instead of using the `active?` method, you need to wrap your new code under the `with_feature` method.

```ruby
Expand Down Expand Up @@ -220,6 +233,39 @@ email_channel = Rollout::Notifications::Channels::Email.new(
)
```

##### Custom channel

If you want to send the notifications using a different channel not offered by this gem, you can implement your own class with a `publish` method.

```ruby
require 'rollout'

module YourApp
class YourCustomChannel
def initialize()
# provide here whatever you need for configuring your channel
end

def publish(text)
# Implement the way you want to publish the notification
end
end
end
```

After implementing it, you can pass it to the list of configured channels

```ruby
your_channel = YourApp::YourCustomChannel.new(url: 'wadus', param2: 'foo')
@rollout ||= Rollout.new(redis)
.with_cache
.with_degrade(min: 100, threshold: 0.1)
.with_notifications(
status_change: [your_channel],
degrade: [your_channel]
)
```

## Rake tasks

In order to have access to the rollout rakes, you have to load manually the task definitions. For doing so load the rollout rake task:
Expand Down Expand Up @@ -260,10 +306,20 @@ For listing all the stored feature flags, do:
bundle exec rake rollout:list
```

For migrating feature flags stored using the old `rollout` gem format (check [migration guide](https://github.com/jcagarcia/rollout-redis/blob/main/MIGRATING_FROM_ROLLOUT_GEM.md)), do:

```shell
bundle exec rake rollout:migrate_from_rollout_format
```

## Migrating from rollout gem 🚨

If you are currently using the unmaintained [rollout](https://github.com/fetlife/rollout) gem, you should consider checking this [migration guide](https://github.com/jcagarcia/rollout-redis/blob/main/MIGRATING_FROM_ROLLOUT_GEM.md) for start using the new `rollout-redis` gem.

### Compatible payloads and keys

You can use the `.with_old_rollout_gem_compatibility` instance method for making the `rollout-redis` gem work as the the discontinued [rollout](https://github.com/fetlife/rollout) gem in terms of redis storage and format storage. Check the [migration guide](https://github.com/jcagarcia/rollout-redis/blob/main/MIGRATING_FROM_ROLLOUT_GEM.md) for more information.

## Changelog

If you're interested in seeing the changes and bug fixes between each version of `rollout-redis`, read the [Changelog](https://github.com/jcagarcia/rollout-redis/blob/main/CHANGELOG.md).
Expand Down
Loading

0 comments on commit 2702463

Please sign in to comment.