Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c0715b38
Commit
c0715b38
authored
Mar 09, 2020
by
Jason Goodman
Committed by
Shinya Maeda
Mar 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return new version feature flags to unleash clients
Support both legacy and new feature flags
parent
0a1a71fb
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
516 additions
and
87 deletions
+516
-87
ee/app/models/operations/feature_flag.rb
ee/app/models/operations/feature_flag.rb
+8
-0
ee/app/models/operations/feature_flags/scope.rb
ee/app/models/operations/feature_flags/scope.rb
+13
-0
ee/app/models/operations/feature_flags/strategy.rb
ee/app/models/operations/feature_flags/strategy.rb
+1
-0
ee/lib/api/unleash.rb
ee/lib/api/unleash.rb
+6
-1
ee/lib/ee/api/entities/unleash_feature.rb
ee/lib/ee/api/entities/unleash_feature.rb
+1
-1
ee/lib/ee/api/entities/unleash_strategy.rb
ee/lib/ee/api/entities/unleash_strategy.rb
+24
-0
ee/spec/factories/operations/feature_flags/scope.rb
ee/spec/factories/operations/feature_flags/scope.rb
+8
-0
ee/spec/factories/operations/feature_flags/strategy.rb
ee/spec/factories/operations/feature_flags/strategy.rb
+9
-0
ee/spec/models/operations/feature_flag_spec.rb
ee/spec/models/operations/feature_flag_spec.rb
+41
-0
ee/spec/requests/api/unleash_spec.rb
ee/spec/requests/api/unleash_spec.rb
+405
-85
No files found.
ee/app/models/operations/feature_flag.rb
View file @
c0715b38
...
...
@@ -50,6 +50,14 @@ module Operations
def
preload_relations
preload
(
:scopes
)
end
def
for_unleash_client
(
project
,
environment
)
includes
(
strategies: :scopes
)
.
where
(
project:
project
)
.
merge
(
Operations
::
FeatureFlags
::
Scope
.
on_environment
(
environment
))
.
reorder
(
:id
)
.
references
(
:operations_scopes
)
end
end
private
...
...
ee/app/models/operations/feature_flags/scope.rb
0 → 100644
View file @
c0715b38
# frozen_string_literal: true
module
Operations
module
FeatureFlags
class
Scope
<
ApplicationRecord
prepend
HasEnvironmentScope
self
.
table_name
=
'operations_scopes'
belongs_to
:strategy
,
class_name:
'Operations::FeatureFlags::Strategy'
end
end
end
ee/app/models/operations/feature_flags/strategy.rb
View file @
c0715b38
...
...
@@ -16,6 +16,7 @@ module Operations
self
.
table_name
=
'operations_strategies'
belongs_to
:feature_flag
has_many
:scopes
,
class_name:
'Operations::FeatureFlags::Scope'
validates
:name
,
inclusion:
{
...
...
ee/lib/api/unleash.rb
View file @
c0715b38
...
...
@@ -72,7 +72,12 @@ module API
def
feature_flags
return
[]
unless
unleash_app_name
.
present?
Operations
::
FeatureFlagScope
.
for_unleash_client
(
project
,
unleash_app_name
)
if
Feature
.
enabled?
(
:feature_flags_new_version
,
project
)
Operations
::
FeatureFlagScope
.
for_unleash_client
(
project
,
unleash_app_name
)
+
Operations
::
FeatureFlag
.
for_unleash_client
(
project
,
unleash_app_name
)
else
Operations
::
FeatureFlagScope
.
for_unleash_client
(
project
,
unleash_app_name
)
end
end
end
end
...
...
ee/lib/ee/api/entities/unleash_feature.rb
View file @
c0715b38
...
...
@@ -7,7 +7,7 @@ module EE
expose
:name
expose
:description
,
unless:
->
(
feature
)
{
feature
.
description
.
nil?
}
expose
:active
,
as: :enabled
expose
:strategies
expose
:strategies
,
using:
UnleashStrategy
end
end
end
...
...
ee/lib/ee/api/entities/unleash_strategy.rb
0 → 100644
View file @
c0715b38
# frozen_string_literal: true
module
EE
module
API
module
Entities
class
UnleashStrategy
<
Grape
::
Entity
expose
:name
do
|
strategy
|
if
strategy
.
respond_to?
(
:name
)
strategy
.
name
else
strategy
[
'name'
]
end
end
expose
:parameters
do
|
strategy
|
if
strategy
.
respond_to?
(
:parameters
)
strategy
.
parameters
else
strategy
[
'parameters'
]
end
end
end
end
end
end
ee/spec/factories/operations/feature_flags/scope.rb
0 → 100644
View file @
c0715b38
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:operations_scope
,
class:
'Operations::FeatureFlags::Scope'
do
association
:strategy
,
factory: :operations_strategy
sequence
(
:environment_scope
)
{
|
n
|
"review/patch-
#{
n
}
"
}
end
end
ee/spec/factories/operations/feature_flags/strategy.rb
0 → 100644
View file @
c0715b38
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:operations_strategy
,
class:
'Operations::FeatureFlags::Strategy'
do
association
:feature_flag
,
factory: :operations_feature_flag
name
{
"default"
}
parameters
{
{}
}
end
end
ee/spec/models/operations/feature_flag_spec.rb
View file @
c0715b38
...
...
@@ -213,4 +213,45 @@ describe Operations::FeatureFlag do
end
end
end
describe
'.for_unleash_client'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let!
(
:feature_flag
)
do
create
(
:operations_feature_flag
,
project:
project
,
name:
'feature1'
,
active:
true
,
version:
2
)
end
let!
(
:strategy
)
do
create
(
:operations_strategy
,
feature_flag:
feature_flag
,
name:
'default'
,
parameters:
{})
end
it
'matches wild cards in the scope'
do
create
(
:operations_scope
,
strategy:
strategy
,
environment_scope:
'review/*'
)
flags
=
described_class
.
for_unleash_client
(
project
,
'review/feature-branch'
)
expect
(
flags
).
to
eq
([
feature_flag
])
end
it
'matches wild cards case sensitively'
do
create
(
:operations_scope
,
strategy:
strategy
,
environment_scope:
'Staging/*'
)
flags
=
described_class
.
for_unleash_client
(
project
,
'staging/feature'
)
expect
(
flags
).
to
eq
([])
end
it
'returns feature flags ordered by id'
do
create
(
:operations_scope
,
strategy:
strategy
,
environment_scope:
'production'
)
feature_flag_b
=
create
(
:operations_feature_flag
,
project:
project
,
name:
'feature2'
,
active:
true
,
version:
2
)
strategy_b
=
create
(
:operations_strategy
,
feature_flag:
feature_flag_b
,
name:
'default'
,
parameters:
{})
create
(
:operations_scope
,
strategy:
strategy_b
,
environment_scope:
'*'
)
flags
=
described_class
.
for_unleash_client
(
project
,
'production'
)
expect
(
flags
.
map
(
&
:id
)).
to
eq
([
feature_flag
.
id
,
feature_flag_b
.
id
])
end
end
end
ee/spec/requests/api/unleash_spec.rb
View file @
c0715b38
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment