diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-06-18 15:25:26 +0300 |
---|---|---|
committer | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2019-06-19 22:15:12 +0300 |
commit | bf96dac83f25e7be72c8c8cc94f0afaed271bd66 (patch) | |
tree | bcfba46751c04c7a56173637aeb3a73ae269f299 /lib | |
parent | 29c0bd7e2b0c46e94eb8c455c2c8212768c65a9d (diff) |
Merge branch 'zj-feature-flag-default-on-catfile-cache' into 'master'
Feature flag default on catfile cache
Closes gitaly#1712
See merge request gitlab-org/gitlab-ce!29556
(cherry picked from commit 14d46afd9b3ee7482fa8be7bc6782b19e960ce45)
968674e4 Move Gitaly feature flag logic to Feature::Gitaly
4dfaaf40 Turn on Cat-File cache by default
Diffstat (limited to 'lib')
-rw-r--r-- | lib/feature/gitaly.rb | 31 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 22 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/storage_settings.rb | 2 |
3 files changed, 35 insertions, 20 deletions
diff --git a/lib/feature/gitaly.rb b/lib/feature/gitaly.rb new file mode 100644 index 00000000000..d7a8f8a0b9e --- /dev/null +++ b/lib/feature/gitaly.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'set' + +class Feature + class Gitaly + # Server feature flags should use '_' to separate words. + # CATFILE_CACHE sets an incorrect example + CATFILE_CACHE = 'catfile-cache'.freeze + + SERVER_FEATURE_FLAGS = [CATFILE_CACHE].freeze + DEFAULT_ON_FLAGS = Set.new([CATFILE_CACHE]).freeze + + class << self + def enabled?(feature_flag) + return false unless Feature::FlipperFeature.table_exists? + + default_on = DEFAULT_ON_FLAGS.include?(feature_flag) + Feature.enabled?("gitaly_#{feature_flag}", default_enabled: default_on) + rescue ActiveRecord::NoDatabaseError + false + end + + def server_feature_flags + SERVER_FEATURE_FLAGS.map do |f| + ["gitaly-feature-#{f.tr('_', '-')}", enabled?(f).to_s] + end.to_h + end + end + end +end diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index e683d4e5bbe..47976389af6 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -31,10 +31,6 @@ module Gitlab MAXIMUM_GITALY_CALLS = 30 CLIENT_NAME = (Sidekiq.server? ? 'gitlab-sidekiq' : 'gitlab-web').freeze - SERVER_FEATURE_CATFILE_CACHE = 'catfile-cache'.freeze - # Server feature flags should use '_' to separate words. - SERVER_FEATURE_FLAGS = [SERVER_FEATURE_CATFILE_CACHE].freeze - MUTEX = Mutex.new define_histogram :gitaly_controller_action_duration_seconds do @@ -223,9 +219,9 @@ module Gitlab metadata['call_site'] = feature.to_s if feature metadata['gitaly-servers'] = address_metadata(remote_storage) if remote_storage metadata['x-gitlab-correlation-id'] = Labkit::Correlation::CorrelationId.current_id if Labkit::Correlation::CorrelationId.current_id - metadata['gitaly-session-id'] = session_id if feature_enabled?(SERVER_FEATURE_CATFILE_CACHE) + metadata['gitaly-session-id'] = session_id if Feature::Gitaly.enabled?(Feature::Gitaly::CATFILE_CACHE) - metadata.merge!(server_feature_flags) + metadata.merge!(Feature::Gitaly.server_feature_flags) result = { metadata: metadata } @@ -244,12 +240,6 @@ module Gitlab Gitlab::SafeRequestStore[:gitaly_session_id] ||= SecureRandom.uuid end - def self.server_feature_flags - SERVER_FEATURE_FLAGS.map do |f| - ["gitaly-feature-#{f.tr('_', '-')}", feature_enabled?(f).to_s] - end.to_h - end - def self.token(storage) params = Gitlab.config.repositories.storages[storage] raise "storage not found: #{storage.inspect}" if params.nil? @@ -257,12 +247,6 @@ module Gitlab params['gitaly_token'].presence || Gitlab.config.gitaly['token'] end - def self.feature_enabled?(feature_name) - Feature::FlipperFeature.table_exists? && Feature.enabled?("gitaly_#{feature_name}") - rescue ActiveRecord::NoDatabaseError - false - end - # Ensures that Gitaly is not being abuse through n+1 misuse etc def self.enforce_gitaly_request_limits(call_site) # Only count limits in request-response environments (not sidekiq for example) @@ -295,7 +279,7 @@ module Gitlab # check if the limit is being exceeded while testing in those environments # In that case we can use a feature flag to indicate that we do want to # enforce request limits. - return true if feature_enabled?('enforce_requests_limits') + return true if Feature::Gitaly.enabled?('enforce_requests_limits') !(Rails.env.production? || ENV["GITALY_DISABLE_REQUEST_LIMITS"]) end diff --git a/lib/gitlab/gitaly_client/storage_settings.rb b/lib/gitlab/gitaly_client/storage_settings.rb index 78ef6bfc0ec..7d1206e551b 100644 --- a/lib/gitlab/gitaly_client/storage_settings.rb +++ b/lib/gitlab/gitaly_client/storage_settings.rb @@ -34,7 +34,7 @@ module Gitlab def self.disk_access_denied? return false if rugged_enabled? - !temporarily_allowed?(ALLOW_KEY) && GitalyClient.feature_enabled?(DISK_ACCESS_DENIED_FLAG) + !temporarily_allowed?(ALLOW_KEY) && Feature::Gitaly.enabled?(DISK_ACCESS_DENIED_FLAG) rescue false # Err on the side of caution, don't break gitlab for people end |