-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Fontaine
committed
Oct 13, 2020
1 parent
cf595a1
commit b8e6428
Showing
7 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule Unleash.Strategy.FlexibleRollout do | ||
@moduledoc """ | ||
Can depend on `:user_id` or `:session_id` in `t:Unleash.context/0` | ||
Based on the | ||
[`flexibleRollout`](https://unleash.github.io/docs/activation_strategy#flexiblerollout) | ||
strategy. | ||
""" | ||
|
||
use Unleash.Strategy, name: "FlexibleRollout" | ||
alias Unleash.Strategy.Utils | ||
|
||
def enabled?(%{"rollout" => percentage} = params, context) when is_number(percentage) do | ||
sticky_value = | ||
params | ||
|> Map.get("stickiness", "") | ||
|> stickiness(context) | ||
|
||
group = Map.get(params, "groupId", Map.get(params, :feature_toggle, "")) | ||
|
||
if sticky_value do | ||
{percentage > 0 and Utils.normalize(sticky_value, group) <= percentage, | ||
%{ | ||
group: group, | ||
percentage: percentage, | ||
sticky_vaule: sticky_value, | ||
stickiness: Map.get(params, "stickiness") | ||
}} | ||
else | ||
{false, | ||
%{ | ||
group: group, | ||
percentage: percentage, | ||
sticky_value: sticky_value, | ||
stickiness: Map.get(params, "stickiness") | ||
}} | ||
end | ||
end | ||
|
||
def enabled?(%{"rollout" => percentage} = params, context), | ||
do: enabled?(%{params | "rollout" => Utils.parse_int(percentage)}, context) | ||
|
||
defp stickiness("default", ctx), do: Map.get(ctx, :user_id, Map.get(ctx, :session_id, random())) | ||
defp stickiness("userId", ctx), do: ctx[:user_id] | ||
defp stickiness("sessionId", ctx), do: ctx[:session_id] | ||
defp stickiness("random", _ctx), do: random() | ||
defp stickiness("", ctx), do: stickiness("default", ctx) | ||
|
||
defp random, | ||
do: Integer.to_string(round(:rand.uniform() * 100) + 1) | ||
end |
Submodule client-specification
updated
8 files
+2 −1 | README.md | |
+11 −11 | package-lock.json | |
+1 −1 | package.json | |
+2 −0 | schema/context-schema.js | |
+7 −0 | schema/features-schema.js | |
+328 −0 | specifications/09-strategy-constraints.json | |
+167 −0 | specifications/10-flexible-rollout-strategy.json | |
+3 −1 | specifications/index.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters