summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-07-05 21:55:27 +0200
committerRémy Coutable <remy@rymai.me>2017-07-05 21:57:10 +0200
commit2a5abd7ed768e46500dfdd000056d5f03c3b2133 (patch)
tree729a2729f8a4e9112088635eb1e7df9a5cfccc32
parent157c2f95e6ecaca4b2d22d4c9499576599428124 (diff)
downloadgitlab-ce-33929-allow-to-enable-perf-bar-for-a-group.tar.gz
Improve Features API and its docs and add a Changelog item33929-allow-to-enable-perf-bar-for-a-group
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--changelogs/unreleased/33929-allow-to-enable-perf-bar-for-a-group.yml4
-rw-r--r--doc/administration/monitoring/performance/performance_bar.md13
-rw-r--r--doc/api/features.md4
-rw-r--r--doc/development/feature_flags.md3
-rw-r--r--lib/api/features.rb29
-rw-r--r--spec/requests/api/features_spec.rb14
6 files changed, 48 insertions, 19 deletions
diff --git a/changelogs/unreleased/33929-allow-to-enable-perf-bar-for-a-group.yml b/changelogs/unreleased/33929-allow-to-enable-perf-bar-for-a-group.yml
new file mode 100644
index 00000000000..810cc8489b5
--- /dev/null
+++ b/changelogs/unreleased/33929-allow-to-enable-perf-bar-for-a-group.yml
@@ -0,0 +1,4 @@
+---
+title: Allow to enable the performance bar per user or Feature group
+merge_request: 12362
+author:
diff --git a/doc/administration/monitoring/performance/performance_bar.md b/doc/administration/monitoring/performance/performance_bar.md
index ae3da83bde1..409a74d2f91 100644
--- a/doc/administration/monitoring/performance/performance_bar.md
+++ b/doc/administration/monitoring/performance/performance_bar.md
@@ -1,7 +1,8 @@
# Performance Bar
>**Note:**
-Available since GitLab 9.4.
+Available since GitLab 9.4. For installations from source you'll have to
+configure it yourself.
A Performance Bar can be displayed, to dig into the performance of a page. When
activated, it looks as follows:
@@ -22,8 +23,9 @@ It allows you to:
## Enable the Performance Bar
-By default, the Performance Bar is disabled. You can enable it either for a
-given feature group or user.
+By default, the Performance Bar is disabled. You can enable it for a group
+and/or users. Note that it's possible to enable it for a group and for
+individual users at the same time.
1. Edit `/etc/gitlab/gitlab.rb`
1. Find the following line, and set it to the group's **full path** that should
@@ -47,7 +49,10 @@ The `performance_team` feature group maps to the group specified by the
curl --data "feature_group=performance_team" --data "value=true" --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/features/performance_bar
```
-### Enable for a specific user
+### Enable for specific users
+
+It's possible to enable the Performance Bar for specific users in addition to a
+group, or even instead of a group:
```
curl --data "user=my_username" --data "value=true" --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/features/performance_bar
diff --git a/doc/api/features.md b/doc/api/features.md
index 2ceea977d85..6861dbf00a2 100644
--- a/doc/api/features.md
+++ b/doc/api/features.md
@@ -61,8 +61,8 @@ POST /features/:name
| `feature_group` | string | no | A Feature group name |
| `user` | string | no | A GitLab username |
-Note that `feature_group` and `user` are mutually exclusive, with
-`feature_group` taking priority.
+Note that you can enable or disable a feature for both a `feature_group` and a
+`user` with a single API call.
```bash
curl --data "value=30" --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/features/new_library
diff --git a/doc/development/feature_flags.md b/doc/development/feature_flags.md
index cf9636eb6f6..a51adcfbd3f 100644
--- a/doc/development/feature_flags.md
+++ b/doc/development/feature_flags.md
@@ -13,7 +13,8 @@ During runtime you can set the values for the gates via the
Starting from GitLab 9.4 we support feature groups via
[Flipper groups](https://github.com/jnunemaker/flipper/blob/v0.10.2/docs/Gates.md#2-group).
-Feature groups must be defined statically in `lib/feature.rb` (in the `.register_feature_groups` method), but their implementation can obviously be
+Feature groups must be defined statically in `lib/feature.rb` (in the
+`.register_feature_groups` method), but their implementation can obviously be
dynamic (querying the DB etc.). You can see how the `performance_team` feature
group for a concrete example.
diff --git a/lib/api/features.rb b/lib/api/features.rb
index 21745916463..9385c6ca174 100644
--- a/lib/api/features.rb
+++ b/lib/api/features.rb
@@ -14,14 +14,12 @@ module API
end
end
- def gate_target(params)
- if params[:feature_group]
- Feature.group(params[:feature_group])
- elsif params[:user]
- User.find_by_username(params[:user])
- else
- gate_value(params)
- end
+ def gate_targets(params)
+ targets = []
+ targets << Feature.group(params[:feature_group]) if params[:feature_group]
+ targets << User.find_by_username(params[:user]) if params[:user]
+
+ targets
end
end
@@ -42,18 +40,25 @@ module API
requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time'
optional :feature_group, type: String, desc: 'A Feature group name'
optional :user, type: String, desc: 'A GitLab username'
- mutually_exclusive :feature_group, :user
end
post ':name' do
feature = Feature.get(params[:name])
- target = gate_target(params)
+ targets = gate_targets(params)
value = gate_value(params)
case value
when true
- feature.enable(target)
+ if targets.present?
+ targets.each { |target| feature.enable(target) }
+ else
+ feature.enable
+ end
when false
- feature.disable(target)
+ if targets.present?
+ targets.each { |target| feature.disable(target) }
+ else
+ feature.disable
+ end
else
feature.enable_percentage_of_time(value)
end
diff --git a/spec/requests/api/features_spec.rb b/spec/requests/api/features_spec.rb
index 1d8aaeea8f2..7e21006b254 100644
--- a/spec/requests/api/features_spec.rb
+++ b/spec/requests/api/features_spec.rb
@@ -113,6 +113,20 @@ describe API::Features do
{ 'key' => 'actors', 'value' => ["User:#{user.id}"] }
])
end
+
+ it 'creates an enabled feature for the given user and feature group when passed user=username and feature_group=perf_team' do
+ post api("/features/#{feature_name}", admin), value: 'true', user: user.username, feature_group: 'perf_team'
+
+ expect(response).to have_http_status(201)
+ expect(json_response).to eq(
+ 'name' => 'my_feature',
+ 'state' => 'conditional',
+ 'gates' => [
+ { 'key' => 'boolean', 'value' => false },
+ { 'key' => 'groups', 'value' => ['perf_team'] },
+ { 'key' => 'actors', 'value' => ["User:#{user.id}"] }
+ ])
+ end
end
it 'creates a feature with the given percentage if passed an integer' do