Commit bf02b947 authored by Markus Koller's avatar Markus Koller

Merge branch 'fix-feature-api-logging' into 'master'

Fix feature flag logging is not working on API

See merge request gitlab-org/gitlab!50025
parents d17bab44 81416b6f
---
title: Fix feature flag logging is not working on API
merge_request: 50025
author:
type: fixed
...@@ -75,7 +75,6 @@ module API ...@@ -75,7 +75,6 @@ module API
post ':name' do post ':name' do
validate_feature_flag_name!(params[:name]) unless params[:force] validate_feature_flag_name!(params[:name]) unless params[:force]
feature = Feature.get(params[:name]) # rubocop:disable Gitlab/AvoidFeatureGet
targets = gate_targets(params) targets = gate_targets(params)
value = gate_value(params) value = gate_value(params)
key = gate_key(params) key = gate_key(params)
...@@ -83,25 +82,26 @@ module API ...@@ -83,25 +82,26 @@ module API
case value case value
when true when true
if gate_specified?(params) if gate_specified?(params)
targets.each { |target| feature.enable(target) } targets.each { |target| Feature.enable(params[:name], target) }
else else
feature.enable Feature.enable(params[:name])
end end
when false when false
if gate_specified?(params) if gate_specified?(params)
targets.each { |target| feature.disable(target) } targets.each { |target| Feature.disable(params[:name], target) }
else else
feature.disable Feature.disable(params[:name])
end end
else else
if key == :percentage_of_actors if key == :percentage_of_actors
feature.enable_percentage_of_actors(value) Feature.enable_percentage_of_actors(params[:name], value)
else else
feature.enable_percentage_of_time(value) Feature.enable_percentage_of_time(params[:name], value)
end end
end end
present feature, with: Entities::Feature, current_user: current_user present Feature.get(params[:name]), # rubocop:disable Gitlab/AvoidFeatureGet
with: Entities::Feature, current_user: current_user
end end
desc 'Remove the gate value for the given feature' desc 'Remove the gate value for the given feature'
......
...@@ -117,6 +117,12 @@ RSpec.describe API::Features, stub_feature_flags: false do ...@@ -117,6 +117,12 @@ RSpec.describe API::Features, stub_feature_flags: false do
) )
end end
it 'logs the event' do
expect(Feature.logger).to receive(:info).once
post api("/features/#{feature_name}", admin), params: { value: 'true' }
end
it 'creates an enabled feature for the given Flipper group when passed feature_group=perf_team' do it 'creates an enabled feature for the given Flipper group when passed feature_group=perf_team' do
post api("/features/#{feature_name}", admin), params: { value: 'true', feature_group: 'perf_team' } post api("/features/#{feature_name}", admin), params: { value: 'true', feature_group: 'perf_team' }
...@@ -444,6 +450,12 @@ RSpec.describe API::Features, stub_feature_flags: false do ...@@ -444,6 +450,12 @@ RSpec.describe API::Features, stub_feature_flags: false do
expect(response).to have_gitlab_http_status(:no_content) expect(response).to have_gitlab_http_status(:no_content)
end end
it 'logs the event' do
expect(Feature.logger).to receive(:info).once
delete api("/features/#{feature_name}", admin)
end
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