Turn on Cat-File cache by default

The feature flag has been introduced an was turned off by default,
now the it will default to be turned on. That change would still allow
users to turn this feature off by leveraging the Rails console by
running:

`Feature.disable("gitaly_catfile-cache")`

Another option is to manage the number of items the LRU cache will
contain, by updating the `config.toml` for Gitaly. This would be the
`catfile_cache_size`:
https://gitlab.com/gitlab-org/gitaly/blob/0dcb5c579e63754f557aef91a4fa7a00e5b8b127/config.toml.example#L27

Closes: https://gitlab.com/gitlab-org/gitaly/issues/1712
上级 968674e4
# 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 should use '_' to separate words.
SERVER_FEATURE_FLAGS = [CATFILE_CACHE].freeze
DEFAULT_ON_FLAGS = Set.new([CATFILE_CACHE]).freeze
class << self
def enabled?(feature_flag)
Feature::FlipperFeature.table_exists? && Feature.enabled?("gitaly_#{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 ||=
begin
SERVER_FEATURE_FLAGS.map do |f|
["gitaly-feature-#{f.tr('_', '-')}", enabled?(f).to_s]
end.to_h
end
SERVER_FEATURE_FLAGS.map do |f|
["gitaly-feature-#{f.tr('_', '-')}", enabled?(f).to_s]
end.to_h
end
end
end
......
......@@ -240,7 +240,6 @@ module Gitlab
Gitlab::SafeRequestStore[:gitaly_session_id] ||= SecureRandom.uuid
end
def self.token(storage)
params = Gitlab.config.repositories.storages[storage]
raise "storage not found: #{storage.inspect}" if params.nil?
......
......@@ -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
......
require 'spec_helper'
describe Feature::Gitaly do
let(:feature_flag) { "mepmep" }
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
allow(Feature).to receive(:enabled?).with("gitaly_mepmep").and_return(false)
stub_feature_flags(gitaly_mep_mep: false)
end
it 'returns false' do
expect(described_class.enabled?(feature_flag)).to be(false)
end
end
end
describe ".server_feature_flags" do
before do
stub_const("#{described_class}::SERVER_FEATURE_FLAGS", [feature_flag])
allow(Feature).to receive(:enabled?).with("gitaly_mepmep").and_return(false)
context 'when the flag defaults to on' do
it 'returns true' do
expect(described_class.enabled?(feature_flag)).to be(true)
end
end
end
subject { described_class.server_feature_flags }
describe ".server_feature_flags" do
context 'when one flag is disabled' do
before do
stub_feature_flags(gitaly_mep_mep: false)
end
it { is_expected.to be_a(Hash) }
subject { described_class.server_feature_flags }
context 'when one flag is disabled' do
it { is_expected.to eq("gitaly-feature-mepmep" => "false") }
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
end
describe '.disk_access_denied?' do
it 'return false when Rugged is enabled', :enable_rugged do
expect(described_class.disk_access_denied?).to be_falsey
context 'when Rugged is enabled', :enable_rugged do
it 'returns false' do
expect(described_class.disk_access_denied?).to be_falsey
end
end
it 'returns true' do
expect(described_class.disk_access_denied?).to be_truthy
context 'when Rugged is disabled' do
it 'returns true' do
expect(described_class.disk_access_denied?).to be_truthy
end
end
end
end
......@@ -10,7 +10,7 @@ module CycleAnalyticsHelpers
repository = project.repository
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)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册