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 ...@@ -16,6 +16,15 @@ module API
end end
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) def gate_targets(params)
Feature::Target.new(params).targets Feature::Target.new(params).targets
end end
...@@ -40,15 +49,22 @@ module API ...@@ -40,15 +49,22 @@ module API
end end
params do params do
requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time' 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 :feature_group, type: String, desc: 'A Feature group name'
optional :user, type: String, desc: 'A GitLab username' optional :user, type: String, desc: 'A GitLab username'
optional :group, type: String, desc: "A GitLab group's path, such as 'gitlab-org'" 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' 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 end
post ':name' do post ':name' do
feature = Feature.get(params[:name]) feature = Feature.get(params[:name])
targets = gate_targets(params) targets = gate_targets(params)
value = gate_value(params) value = gate_value(params)
key = gate_key(params)
case value case value
when true when true
...@@ -64,7 +80,11 @@ module API ...@@ -64,7 +80,11 @@ module API
feature.disable feature.disable
end end
else 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 end
present feature, with: Entities::Feature, current_user: current_user present feature, with: Entities::Feature, current_user: current_user
......
...@@ -198,7 +198,7 @@ describe API::Features do ...@@ -198,7 +198,7 @@ describe API::Features do
end end
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' } post api("/features/#{feature_name}", admin), params: { value: '50' }
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
...@@ -210,6 +210,19 @@ describe API::Features do ...@@ -210,6 +210,19 @@ describe API::Features do
{ 'key' => 'percentage_of_time', 'value' => 50 } { 'key' => 'percentage_of_time', 'value' => 50 }
]) ])
end 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 end
context 'when the feature exists' do context 'when the feature exists' do
...@@ -298,7 +311,7 @@ describe API::Features do ...@@ -298,7 +311,7 @@ describe API::Features do
end end
end end
context 'with a pre-existing percentage value' do context 'with a pre-existing percentage of time value' do
before do before do
feature.enable_percentage_of_time(50) feature.enable_percentage_of_time(50)
end end
...@@ -316,6 +329,25 @@ describe API::Features do ...@@ -316,6 +329,25 @@ describe API::Features do
]) ])
end end
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
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