Commit 18e9506d authored by Sean McGivern's avatar Sean McGivern

Merge branch '1334-add-use-primary-store-feature-flag' into 'master'

[Follow up] Add use_pirmary_store_as_default feature flag for MultiStore [RUN ALL RSPEC]

See merge request gitlab-org/gitlab!75258
parents 40e71b22 b9d605b6
---
name: use_multi_store
name: use_primary_and_secondary_stores_for_sessions
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/73660
rollout_issue_url: https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/1429
milestone: '14.5'
milestone: '14.6'
type: development
group: group::memory
default_enabled: false
---
name: use_primary_store_as_default_for_sessions
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75258
rollout_issue_url:
milestone: '14.6'
type: development
group: group::memory
default_enabled: false
......@@ -39,41 +39,42 @@ module Gitlab
flushdb
).freeze
def initialize(primary_store, secondary_store, instance_name = nil)
def initialize(primary_store, secondary_store, instance_name)
@primary_store = primary_store
@secondary_store = secondary_store
@instance_name = instance_name
validate_stores!
end
# rubocop:disable GitlabSecurity/PublicSend
READ_COMMANDS.each do |name|
define_method(name) do |*args, &block|
if multi_store_enabled?
if use_primary_and_secondary_stores?
read_command(name, *args, &block)
else
secondary_store.send(name, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
default_store.send(name, *args, &block)
end
end
end
WRITE_COMMANDS.each do |name|
define_method(name) do |*args, &block|
if multi_store_enabled?
if use_primary_and_secondary_stores?
write_command(name, *args, &block)
else
secondary_store.send(name, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
default_store.send(name, *args, &block)
end
end
end
def method_missing(...)
return @instance.send(...) if @instance # rubocop:disable GitlabSecurity/PublicSend
return @instance.send(...) if @instance
log_method_missing(...)
secondary_store.send(...) # rubocop:disable GitlabSecurity/PublicSend
default_store.send(...)
end
# rubocop:enable GitlabSecurity/PublicSend
def respond_to_missing?(command_name, include_private = false)
true
......@@ -83,22 +84,30 @@ module Gitlab
# https://github.com/redis-store/redis-rack/blob/a833086ba494083b6a384a1a4e58b36573a9165d/lib/redis/rack/connection.rb#L15
# Done similarly in https://github.com/lsegal/yard/blob/main/lib/yard/templates/template.rb#L122
def is_a?(klass)
return true if klass == secondary_store.class
return true if klass == default_store.class
super(klass)
end
alias_method :kind_of?, :is_a?
def to_s
if multi_store_enabled?
primary_store.to_s
else
secondary_store.to_s
end
use_primary_and_secondary_stores? ? primary_store.to_s : default_store.to_s
end
def use_primary_and_secondary_stores?
Feature.enabled?("use_primary_and_secondary_stores_for_#{instance_name.underscore}", default_enabled: :yaml) && !same_redis_store?
end
def use_primary_store_as_default?
Feature.enabled?("use_primary_store_as_default_for_#{instance_name.underscore}", default_enabled: :yaml) && !same_redis_store?
end
private
def default_store
use_primary_store_as_default? ? primary_store : secondary_store
end
def log_method_missing(command_name, *_args)
log_error(MethodMissingError.new, command_name)
increment_method_missing_count(command_name)
......@@ -155,10 +164,6 @@ module Gitlab
send_command(secondary_store, command_name, *args, &block)
end
def multi_store_enabled?
Feature.enabled?(:use_multi_store, default_enabled: :yaml) && !same_redis_store?
end
def same_redis_store?
strong_memoize(:same_redis_store) do
# <Redis client v4.4.0 for redis:///path_to/redis/redis.socket/5>"
......@@ -200,6 +205,7 @@ module Gitlab
def validate_stores!
raise ArgumentError, 'primary_store is required' unless primary_store
raise ArgumentError, 'secondary_store is required' unless secondary_store
raise ArgumentError, 'instance_name is required' unless instance_name
raise ArgumentError, 'invalid primary_store' unless primary_store.is_a?(::Redis)
raise ArgumentError, 'invalid secondary_store' unless secondary_store.is_a?(::Redis)
end
......
......@@ -24,7 +24,7 @@ module Gitlab
primary_store = ::Redis.new(params)
secondary_store = ::Redis.new(config_fallback.params)
MultiStore.new(primary_store, secondary_store, name)
MultiStore.new(primary_store, secondary_store, store_name)
end
end
......@@ -35,7 +35,7 @@ module Gitlab
primary_store = create_redis_store(redis_store_options, extras)
secondary_store = create_redis_store(self.class.config_fallback.params, extras)
MultiStore.new(primary_store, secondary_store, self.class.name)
MultiStore.new(primary_store, secondary_store, self.class.store_name)
end
private
......
This diff is collapsed.
......@@ -53,5 +53,7 @@ RSpec.describe Gitlab::Redis::Sessions do
expect(subject).to be_instance_of(::Gitlab::Redis::MultiStore)
end
end
it_behaves_like 'multi store feature flags', :use_primary_and_secondary_stores_for_sessions, :use_primary_store_as_default_for_sessions
end
end
# frozen_string_literal: true
RSpec.shared_examples 'multi store feature flags' do |use_primary_and_secondary_stores, use_primary_store_as_default|
context "with feature flag :#{use_primary_and_secondary_stores} is enabled" do
before do
stub_feature_flags(use_primary_and_secondary_stores => true)
end
it 'multi store is enabled' do
expect(subject.use_primary_and_secondary_stores?).to be true
end
end
context "with feature flag :#{use_primary_and_secondary_stores} is disabled" do
before do
stub_feature_flags(use_primary_and_secondary_stores => false)
end
it 'multi store is disabled' do
expect(subject.use_primary_and_secondary_stores?).to be false
end
end
context "with feature flag :#{use_primary_store_as_default} is enabled" do
before do
stub_feature_flags(use_primary_store_as_default => true)
end
it 'primary store is enabled' do
expect(subject.use_primary_store_as_default?).to be true
end
end
context "with feature flag :#{use_primary_store_as_default} is disabled" do
before do
stub_feature_flags(use_primary_store_as_default => false)
end
it 'primary store is disabled' do
expect(subject.use_primary_store_as_default?).to be false
end
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