Коммит fa51b07e создал по автору Marius Bobin's avatar Marius Bobin
Просмотр файлов

Merge branch 'sc1-shard-feature-flag' into 'master'

Add new Redis singleton to shard out feature flags

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119279



Merged-by: default avatarMarius Bobin <mbobin@gitlab.com>
Approved-by: default avatarGregorius Marco <gmarco@gitlab.com>
Approved-by: default avatarMarius Bobin <mbobin@gitlab.com>
Approved-by: default avatarAlejandro Rodríguez <alejandro@gitlab.com>
Reviewed-by: default avatarAlejandro Rodríguez <alejandro@gitlab.com>
Co-authored-by: default avatarAlejandro Rodríguez <alejandro@gitlab.com>
Co-authored-by: default avatarSylvester Chin <schin@gitlab.com>
владельцы 369fbb42 1fcfc5b3
...@@ -326,7 +326,7 @@ def l1_cache_backend ...@@ -326,7 +326,7 @@ def l1_cache_backend
end end
def l2_cache_backend def l2_cache_backend
Rails.cache ::Gitlab::Redis::FeatureFlag.cache_store
end end
def log(key:, action:, **extra) def log(key:, action:, **extra)
......
...@@ -10,6 +10,7 @@ module Redis ...@@ -10,6 +10,7 @@ module Redis
ALL_CLASSES = [ ALL_CLASSES = [
Gitlab::Redis::Cache, Gitlab::Redis::Cache,
Gitlab::Redis::DbLoadBalancing, Gitlab::Redis::DbLoadBalancing,
Gitlab::Redis::FeatureFlag,
Gitlab::Redis::Queues, Gitlab::Redis::Queues,
Gitlab::Redis::RateLimiting, Gitlab::Redis::RateLimiting,
Gitlab::Redis::RepositoryCache, Gitlab::Redis::RepositoryCache,
......
# frozen_string_literal: true
module Gitlab
module Redis
class FeatureFlag < ::Gitlab::Redis::Wrapper
FeatureFlagStore = Class.new(ActiveSupport::Cache::RedisCacheStore)
class << self
# The data we store on FeatureFlag is currently stored on Cache.
def config_fallback
Cache
end
def cache_store
@cache_store ||= FeatureFlagStore.new(
redis: pool,
compress: Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_REDIS_CACHE_COMPRESSION', '1')),
namespace: Cache::CACHE_NAMESPACE,
expires_in: 1.hour
)
end
end
end
end
end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Feature, stub_feature_flags: false, feature_category: :shared do RSpec.describe Feature, :clean_gitlab_redis_feature_flag, stub_feature_flags: false, feature_category: :shared do
include StubVersion include StubVersion
before do before do
...@@ -212,7 +212,7 @@ ...@@ -212,7 +212,7 @@
end end
it { expect(described_class.send(:l1_cache_backend)).to eq(Gitlab::ProcessMemoryCache.cache_backend) } it { expect(described_class.send(:l1_cache_backend)).to eq(Gitlab::ProcessMemoryCache.cache_backend) }
it { expect(described_class.send(:l2_cache_backend)).to eq(Rails.cache) } it { expect(described_class.send(:l2_cache_backend)).to eq(Gitlab::Redis::FeatureFlag.cache_store) }
it 'caches the status in L1 and L2 caches', it 'caches the status in L1 and L2 caches',
:request_store, :use_clean_rails_memory_store_caching do :request_store, :use_clean_rails_memory_store_caching do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Redis::FeatureFlag, feature_category: :redis do
include_examples "redis_new_instance_shared_examples", 'feature_flag', Gitlab::Redis::Cache
describe '.cache_store' do
it 'has a default ttl of 1 hour' do
expect(described_class.cache_store.options[:expires_in]).to eq(1.hour)
end
end
end
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать