Коммит 1fcfc5b3 создал по автору Sylvester Chin's avatar Sylvester Chin Зафиксировано автором Marius Bobin
Просмотр файлов

Add new Redis singleton to shard out feature flags

This also allow us to instrument feature-flag-specific Redis commands
on the client side to help with sizing new Redis instance.
владелец b4ad4f1b
...@@ -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.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать