Commit 14d46afd authored by Douwe Maan's avatar Douwe Maan

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
parents 6d68a3a2 4dfaaf40
# 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
...@@ -31,10 +31,6 @@ module Gitlab ...@@ -31,10 +31,6 @@ module Gitlab
MAXIMUM_GITALY_CALLS = 30 MAXIMUM_GITALY_CALLS = 30
CLIENT_NAME = (Sidekiq.server? ? 'gitlab-sidekiq' : 'gitlab-web').freeze 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 MUTEX = Mutex.new
define_histogram :gitaly_controller_action_duration_seconds do define_histogram :gitaly_controller_action_duration_seconds do
...@@ -223,9 +219,9 @@ module Gitlab ...@@ -223,9 +219,9 @@ module Gitlab
metadata['call_site'] = feature.to_s if feature metadata['call_site'] = feature.to_s if feature
metadata['gitaly-servers'] = address_metadata(remote_storage) if remote_storage 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['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 } result = { metadata: metadata }
...@@ -244,12 +240,6 @@ module Gitlab ...@@ -244,12 +240,6 @@ module Gitlab
Gitlab::SafeRequestStore[:gitaly_session_id] ||= SecureRandom.uuid Gitlab::SafeRequestStore[:gitaly_session_id] ||= SecureRandom.uuid
end 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) def self.token(storage)
params = Gitlab.config.repositories.storages[storage] params = Gitlab.config.repositories.storages[storage]
raise "storage not found: #{storage.inspect}" if params.nil? raise "storage not found: #{storage.inspect}" if params.nil?
...@@ -257,12 +247,6 @@ module Gitlab ...@@ -257,12 +247,6 @@ 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_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 # Ensures that Gitaly is not being abuse through n+1 misuse etc
def self.enforce_gitaly_request_limits(call_site) def self.enforce_gitaly_request_limits(call_site)
# Only count limits in request-response environments (not sidekiq for example) # Only count limits in request-response environments (not sidekiq for example)
...@@ -295,7 +279,7 @@ module Gitlab ...@@ -295,7 +279,7 @@ module Gitlab
# check if the limit is being exceeded while testing in those environments # 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 # In that case we can use a feature flag to indicate that we do want to
# enforce request limits. # 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"]) !(Rails.env.production? || ENV["GITALY_DISABLE_REQUEST_LIMITS"])
end end
......
...@@ -34,7 +34,7 @@ module Gitlab ...@@ -34,7 +34,7 @@ module Gitlab
def self.disk_access_denied? def self.disk_access_denied?
return false if rugged_enabled? 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 rescue
false # Err on the side of caution, don't break gitlab for people false # Err on the side of caution, don't break gitlab for people
end end
......
require 'spec_helper'
describe Feature::Gitaly do
let(:feature_flag) { "mep_mep" }
before do
stub_const("#{described_class}::SERVER_FEATURE_FLAGS", [feature_flag])
end
describe ".enabled?" do
context 'when the gate is closed' do
before do
stub_feature_flags(gitaly_mep_mep: false)
end
it 'returns false' do
expect(described_class.enabled?(feature_flag)).to be(false)
end
end
context 'when the flag defaults to on' do
it 'returns true' do
expect(described_class.enabled?(feature_flag)).to be(true)
end
end
end
describe ".server_feature_flags" do
context 'when one flag is disabled' do
before do
stub_feature_flags(gitaly_mep_mep: false)
end
subject { described_class.server_feature_flags }
it { is_expected.to be_a(Hash) }
it { is_expected.to eq("gitaly-feature-mep-mep" => "false") }
end
end
end
...@@ -28,12 +28,16 @@ describe Gitlab::GitalyClient::StorageSettings do ...@@ -28,12 +28,16 @@ describe Gitlab::GitalyClient::StorageSettings do
end end
describe '.disk_access_denied?' do describe '.disk_access_denied?' do
it 'return false when Rugged is enabled', :enable_rugged do context 'when Rugged is enabled', :enable_rugged do
it 'returns false' do
expect(described_class.disk_access_denied?).to be_falsey expect(described_class.disk_access_denied?).to be_falsey
end end
end
context 'when Rugged is disabled' do
it 'returns true' do it 'returns true' do
expect(described_class.disk_access_denied?).to be_truthy expect(described_class.disk_access_denied?).to be_truthy
end end
end end
end
end end
...@@ -330,20 +330,6 @@ describe Gitlab::GitalyClient do ...@@ -330,20 +330,6 @@ describe Gitlab::GitalyClient do
end end
end end
describe 'feature_enabled?' do
let(:feature_name) { 'my_feature' }
let(:real_feature_name) { "gitaly_#{feature_name}" }
before do
allow(Feature).to receive(:enabled?).and_return(false)
end
it 'returns false' do
expect(Feature).to receive(:enabled?).with(real_feature_name)
expect(described_class.feature_enabled?(feature_name)).to be(false)
end
end
describe 'timeouts' do describe 'timeouts' do
context 'with default values' do context 'with default values' do
before do before do
......
...@@ -10,7 +10,7 @@ module CycleAnalyticsHelpers ...@@ -10,7 +10,7 @@ module CycleAnalyticsHelpers
repository = project.repository repository = project.repository
oldrev = repository.commit(branch_name)&.sha || Gitlab::Git::BLANK_SHA oldrev = repository.commit(branch_name)&.sha || Gitlab::Git::BLANK_SHA
if Timecop.frozen? && Gitlab::GitalyClient.feature_enabled?(:operation_user_commit_files) if Timecop.frozen?
mock_gitaly_multi_action_dates(repository, commit_time) mock_gitaly_multi_action_dates(repository, commit_time)
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