Commit 91312dab authored by Alper Akgun's avatar Alper Akgun

Add percentage of actors feature flag rollout

Currently only percentage of times rollout is possible on the feature
flag API. With that change we shall be able to use the chatops to set
percentage of actors rollout for any feature flag
parent b898ff1d
---
title: Add percentage of actors feature flag rollout
merge_request: 29698
author:
type: added
......@@ -16,6 +16,15 @@ module API
end
end
def gate_key(params)
case params[:key]
when 'percentage_of_actors'
:percentage_of_actors
else
:percentage_of_time
end
end
def gate_targets(params)
Feature::Target.new(params).targets
end
......@@ -40,15 +49,22 @@ module API
end
params do
requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time'
optional :key, type: String, desc: '`percentage_of_actors` or the default `percentage_of_time`'
optional :feature_group, type: String, desc: 'A Feature group name'
optional :user, type: String, desc: 'A GitLab username'
optional :group, type: String, desc: "A GitLab group's path, such as 'gitlab-org'"
optional :project, type: String, desc: 'A projects path, like gitlab-org/gitlab-ce'
mutually_exclusive :key, :feature_group
mutually_exclusive :key, :user
mutually_exclusive :key, :group
mutually_exclusive :key, :project
end
post ':name' do
feature = Feature.get(params[:name])
targets = gate_targets(params)
value = gate_value(params)
key = gate_key(params)
case value
when true
......@@ -64,7 +80,11 @@ module API
feature.disable
end
else
feature.enable_percentage_of_time(value)
if key == :percentage_of_actors
feature.enable_percentage_of_actors(value)
else
feature.enable_percentage_of_time(value)
end
end
present feature, with: Entities::Feature, current_user: current_user
......
......@@ -198,7 +198,7 @@ describe API::Features do
end
end
it 'creates a feature with the given percentage if passed an integer' do
it 'creates a feature with the given percentage of time if passed an integer' do
post api("/features/#{feature_name}", admin), params: { value: '50' }
expect(response).to have_gitlab_http_status(:created)
......@@ -210,6 +210,19 @@ describe API::Features do
{ 'key' => 'percentage_of_time', 'value' => 50 }
])
end
it 'creates a feature with the given percentage of actors if passed an integer' do
post api("/features/#{feature_name}", admin), params: { value: '50', key: 'percentage_of_actors' }
expect(response).to have_gitlab_http_status(:created)
expect(json_response).to eq(
'name' => 'my_feature',
'state' => 'conditional',
'gates' => [
{ 'key' => 'boolean', 'value' => false },
{ 'key' => 'percentage_of_actors', 'value' => 50 }
])
end
end
context 'when the feature exists' do
......@@ -298,7 +311,7 @@ describe API::Features do
end
end
context 'with a pre-existing percentage value' do
context 'with a pre-existing percentage of time value' do
before do
feature.enable_percentage_of_time(50)
end
......@@ -316,6 +329,25 @@ describe API::Features do
])
end
end
context 'with a pre-existing percentage of actors value' do
before do
feature.enable_percentage_of_actors(42)
end
it 'updates the percentage of actors if passed an integer' do
post api("/features/#{feature_name}", admin), params: { value: '74', key: 'percentage_of_actors' }
expect(response).to have_gitlab_http_status(:created)
expect(json_response).to eq(
'name' => 'my_feature',
'state' => 'conditional',
'gates' => [
{ 'key' => 'boolean', 'value' => false },
{ 'key' => 'percentage_of_actors', 'value' => 74 }
])
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment