summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-05-29 13:01:19 -0400
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-05-31 14:49:57 -0400
commite2651f3fe20c0f0e00f4d109c9634f4d6cb555e1 (patch)
tree03485ab7524cadb14b1dd717a1e1e147d8d902fa /lib
parenta3ebbebd5a0db2a9340ddd60fc3c1269604f6209 (diff)
downloadgitlab-ce-feature-flags-flipper.tar.gz
Use `Feature` gates on `Gitlab::GitalyClient.feature_enabled?`feature-flags-flipper
Diffstat (limited to 'lib')
-rw-r--r--lib/feature.rb7
-rw-r--r--lib/gitlab/gitaly_client.rb22
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/feature.rb b/lib/feature.rb
index b89e5176a08..2e2b343f82c 100644
--- a/lib/feature.rb
+++ b/lib/feature.rb
@@ -20,6 +20,13 @@ class Feature
flipper.feature(key)
end
+ def persisted?(feature)
+ # Flipper creates on-memory features when asked for a not-yet-created one.
+ # If we want to check if a feature has been actually set, we look for it
+ # on the persisted features list.
+ all.map(&:name).include?(feature.name)
+ end
+
private
def flipper
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb
index 72466700c05..2343446bf22 100644
--- a/lib/gitlab/gitaly_client.rb
+++ b/lib/gitlab/gitaly_client.rb
@@ -2,6 +2,12 @@ require 'gitaly'
module Gitlab
module GitalyClient
+ module MigrationStatus
+ DISABLED = 1
+ OPT_IN = 2
+ OPT_OUT = 3
+ end
+
SERVER_VERSION_FILE = 'GITALY_SERVER_VERSION'.freeze
MUTEX = Mutex.new
@@ -46,8 +52,20 @@ module Gitlab
Gitlab.config.gitaly.enabled
end
- def self.feature_enabled?(feature)
- enabled? && ENV["GITALY_#{feature.upcase}"] == '1'
+ def self.feature_enabled?(feature, status: MigrationStatus::OPT_IN)
+ return false if !enabled? || status == MigrationStatus::DISABLED
+
+ feature = Feature.get("gitaly_#{feature}")
+
+ # If the feature hasn't been set, turn it on if it's opt-out
+ return status == MigrationStatus::OPT_OUT unless Feature.persisted?(feature)
+
+ if feature.percentage_of_time_value > 0
+ # Probabilistically enable this feature
+ return Random.rand() * 100 < feature.percentage_of_time_value
+ end
+
+ feature.enabled?
end
def self.migrate(feature)