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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
94680e14
Commit
94680e14
authored
Sep 07, 2017
by
Andrew Newdigate
Committed by
Rémy Coutable
Sep 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gitaly feature toggles are on by default in development environments
parent
6cd0ec11
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
8 deletions
+49
-8
changelogs/unreleased/gitaly-feature-toggles-development-opt-out.yml
...unreleased/gitaly-feature-toggles-development-opt-out.yml
+5
-0
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+28
-8
spec/lib/gitlab/gitaly_client_spec.rb
spec/lib/gitlab/gitaly_client_spec.rb
+16
-0
No files found.
changelogs/unreleased/gitaly-feature-toggles-development-opt-out.yml
0 → 100644
View file @
94680e14
---
title
:
Gitaly feature toggles are on by default in development
merge_request
:
13802
author
:
type
:
other
lib/gitlab/gitaly_client.rb
View file @
94680e14
...
@@ -70,21 +70,41 @@ module Gitlab
...
@@ -70,21 +70,41 @@ module Gitlab
params
[
'gitaly_token'
].
presence
||
Gitlab
.
config
.
gitaly
[
'token'
]
params
[
'gitaly_token'
].
presence
||
Gitlab
.
config
.
gitaly
[
'token'
]
end
end
def
self
.
feature_enabled?
(
feature
,
status:
MigrationStatus
::
OPT_IN
)
# Evaluates whether a feature toggle is on or off
def
self
.
feature_enabled?
(
feature_name
,
status:
MigrationStatus
::
OPT_IN
)
# Disabled features are always off!
return
false
if
status
==
MigrationStatus
::
DISABLED
return
false
if
status
==
MigrationStatus
::
DISABLED
feature
=
Feature
.
get
(
"gitaly_
#{
feature
}
"
)
feature
=
Feature
.
get
(
"gitaly_
#{
feature
_name
}
"
)
# If the feature hasn't been set, turn it on if it's opt-out
# If the feature has been set, always evaluate
return
status
==
MigrationStatus
::
OPT_OUT
unless
Feature
.
persisted?
(
feature
)
if
Feature
.
persisted?
(
feature
)
if
feature
.
percentage_of_time_value
>
0
# Probabilistically enable this feature
return
Random
.
rand
()
*
100
<
feature
.
percentage_of_time_value
end
return
feature
.
enabled?
end
if
feature
.
percentage_of_time_value
>
0
# If the feature has not been set, the default depends
# Probabilistically enable this feature
# on it's status
return
Random
.
rand
()
*
100
<
feature
.
percentage_of_time_value
case
status
when
MigrationStatus
::
OPT_OUT
true
when
MigrationStatus
::
OPT_IN
opt_into_all_features?
else
false
end
end
end
feature
.
enabled?
# opt_into_all_features? returns true when the current environment
# is one in which we opt into features automatically
def
self
.
opt_into_all_features?
Rails
.
env
.
development?
||
ENV
[
"GITALY_FEATURE_DEFAULT_ON"
]
==
"1"
end
end
private_class_method
:opt_into_all_features?
def
self
.
migrate
(
feature
,
status:
MigrationStatus
::
OPT_IN
)
def
self
.
migrate
(
feature
,
status:
MigrationStatus
::
OPT_IN
)
is_enabled
=
feature_enabled?
(
feature
,
status:
status
)
is_enabled
=
feature_enabled?
(
feature
,
status:
status
)
...
...
spec/lib/gitlab/gitaly_client_spec.rb
View file @
94680e14
...
@@ -102,6 +102,22 @@ describe Gitlab::GitalyClient, skip_gitaly_mock: true do
...
@@ -102,6 +102,22 @@ describe Gitlab::GitalyClient, skip_gitaly_mock: true do
expect
(
described_class
.
feature_enabled?
(
feature_name
,
status:
feature_status
)).
to
be
(
false
)
expect
(
described_class
.
feature_enabled?
(
feature_name
,
status:
feature_status
)).
to
be
(
false
)
end
end
end
end
context
"when a feature is not persisted"
do
it
'returns false when opt_into_all_features is off'
do
allow
(
Feature
).
to
receive
(
:persisted?
).
and_return
(
false
)
allow
(
described_class
).
to
receive
(
:opt_into_all_features?
).
and_return
(
false
)
expect
(
described_class
.
feature_enabled?
(
feature_name
,
status:
feature_status
)).
to
be
(
false
)
end
it
'returns true when the override is on'
do
allow
(
Feature
).
to
receive
(
:persisted?
).
and_return
(
false
)
allow
(
described_class
).
to
receive
(
:opt_into_all_features?
).
and_return
(
true
)
expect
(
described_class
.
feature_enabled?
(
feature_name
,
status:
feature_status
)).
to
be
(
true
)
end
end
end
end
context
'when the feature_status is OPT_OUT'
do
context
'when the feature_status is OPT_OUT'
do
...
...
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