Commit b9d605b6 authored by nmilojevic1's avatar nmilojevic1

Rename the feature flags

- Fix specs for multi_store and sessions
parent 2bf1b322
--- ---
name: sessions_use_multi_store name: use_primary_and_secondary_stores_for_sessions
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/73660 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 rollout_issue_url: https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/1429
milestone: '14.6' milestone: '14.6'
......
--- ---
name: sessions_use_primary_store name: use_primary_store_as_default_for_sessions
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75258 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75258
rollout_issue_url: rollout_issue_url:
milestone: '14.6' milestone: '14.6'
......
...@@ -49,7 +49,7 @@ module Gitlab ...@@ -49,7 +49,7 @@ module Gitlab
# rubocop:disable GitlabSecurity/PublicSend # rubocop:disable GitlabSecurity/PublicSend
READ_COMMANDS.each do |name| READ_COMMANDS.each do |name|
define_method(name) do |*args, &block| define_method(name) do |*args, &block|
if multi_store_enabled? if use_primary_and_secondary_stores?
read_command(name, *args, &block) read_command(name, *args, &block)
else else
default_store.send(name, *args, &block) default_store.send(name, *args, &block)
...@@ -59,7 +59,7 @@ module Gitlab ...@@ -59,7 +59,7 @@ module Gitlab
WRITE_COMMANDS.each do |name| WRITE_COMMANDS.each do |name|
define_method(name) do |*args, &block| define_method(name) do |*args, &block|
if multi_store_enabled? if use_primary_and_secondary_stores?
write_command(name, *args, &block) write_command(name, *args, &block)
else else
default_store.send(name, *args, &block) default_store.send(name, *args, &block)
...@@ -91,29 +91,21 @@ module Gitlab ...@@ -91,29 +91,21 @@ module Gitlab
alias_method :kind_of?, :is_a? alias_method :kind_of?, :is_a?
def to_s def to_s
if multi_store_enabled? use_primary_and_secondary_stores? ? primary_store.to_s : default_store.to_s
primary_store.to_s
else
default_store.to_s
end
end end
def multi_store_enabled? def use_primary_and_secondary_stores?
Feature.enabled?("#{instance_name.underscore}_use_multi_store", default_enabled: :yaml) && !same_redis_store? Feature.enabled?("use_primary_and_secondary_stores_for_#{instance_name.underscore}", default_enabled: :yaml) && !same_redis_store?
end end
def primary_store_enabled? def use_primary_store_as_default?
Feature.enabled?("#{instance_name.underscore}_use_primary_store", default_enabled: :yaml) && !same_redis_store? Feature.enabled?("use_primary_store_as_default_for_#{instance_name.underscore}", default_enabled: :yaml) && !same_redis_store?
end end
private private
def default_store def default_store
if primary_store_enabled? use_primary_store_as_default? ? primary_store : secondary_store
primary_store
else
secondary_store
end
end end
def log_method_missing(command_name, *_args) def log_method_missing(command_name, *_args)
......
...@@ -189,9 +189,9 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -189,9 +189,9 @@ RSpec.describe Gitlab::Redis::MultiStore do
allow(secondary_store).to receive(name).and_call_original allow(secondary_store).to receive(name).and_call_original
end end
context 'with feature flag :test_store_use_multi_store enabled' do context 'with feature flag :use_primary_and_secondary_stores_for_test_store' do
before do before do
stub_feature_flags(test_store_use_multi_store: true) stub_feature_flags(use_primary_and_secondary_stores_for_test_store: true)
end end
context 'when reading from the primary is successful' do context 'when reading from the primary is successful' do
...@@ -266,22 +266,22 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -266,22 +266,22 @@ RSpec.describe Gitlab::Redis::MultiStore do
end end
end end
context 'with feature flag :test_store_use_multi_store is disabled' do context 'with feature flag :use_primary_and_secondary_stores_for_test_store' do
before do before do
stub_feature_flags(test_store_use_multi_store: false) stub_feature_flags(use_primary_and_secondary_stores_for_test_store: false)
end end
context 'with feature flag :test_store_use_primary_store is disabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is disabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: false) stub_feature_flags(use_primary_store_as_default_for_test_store: false)
end end
it_behaves_like 'secondary store' it_behaves_like 'secondary store'
end end
context 'with feature flag :test_store_use_primary_store is enabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is enabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: true) stub_feature_flags(use_primary_store_as_default_for_test_store: true)
end end
it 'execute on the primary instance' do it 'execute on the primary instance' do
...@@ -375,9 +375,9 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -375,9 +375,9 @@ RSpec.describe Gitlab::Redis::MultiStore do
allow(secondary_store).to receive(name).and_call_original allow(secondary_store).to receive(name).and_call_original
end end
context 'with feature flag :test_store_use_multi_store enabled' do context 'with feature flag :use_primary_and_secondary_stores_for_test_store' do
before do before do
stub_feature_flags(test_store_use_multi_store: true) stub_feature_flags(use_primary_and_secondary_stores_for_test_store: true)
end end
context 'when executing on primary instance is successful' do context 'when executing on primary instance is successful' do
...@@ -428,14 +428,14 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -428,14 +428,14 @@ RSpec.describe Gitlab::Redis::MultiStore do
end end
end end
context 'with feature flag :test_store_use_multi_store is disabled' do context 'with feature flag :use_primary_and_secondary_stores_for_test_store is disabled' do
before do before do
stub_feature_flags(test_store_use_multi_store: false) stub_feature_flags(use_primary_and_secondary_stores_for_test_store: false)
end end
context 'with feature flag :test_store_use_primary_store is disabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is disabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: false) stub_feature_flags(use_primary_store_as_default_for_test_store: false)
end end
it 'executes only on the secondary redis store', :aggregate_errors do it 'executes only on the secondary redis store', :aggregate_errors do
...@@ -448,9 +448,9 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -448,9 +448,9 @@ RSpec.describe Gitlab::Redis::MultiStore do
include_examples 'verify that store contains values', :secondary_store include_examples 'verify that store contains values', :secondary_store
end end
context 'with feature flag :test_store_use_primary_store is enabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is enabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: true) stub_feature_flags(use_primary_store_as_default_for_test_store: true)
end end
it 'executes only on the primary_redis redis store', :aggregate_errors do it 'executes only on the primary_redis redis store', :aggregate_errors do
...@@ -501,9 +501,9 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -501,9 +501,9 @@ RSpec.describe Gitlab::Redis::MultiStore do
subject subject
end end
context 'with feature flag :test_store_use_primary_store is enabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is enabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: true) stub_feature_flags(use_primary_store_as_default_for_test_store: true)
end end
it 'fallback and executes only on the secondary store', :aggregate_errors do it 'fallback and executes only on the secondary store', :aggregate_errors do
...@@ -521,9 +521,9 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -521,9 +521,9 @@ RSpec.describe Gitlab::Redis::MultiStore do
end end
end end
context 'with feature flag :test_store_use_primary_store is disabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is disabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: false) stub_feature_flags(use_primary_store_as_default_for_test_store: false)
end end
it 'fallback and executes only on the secondary store', :aggregate_errors do it 'fallback and executes only on the secondary store', :aggregate_errors do
...@@ -567,9 +567,9 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -567,9 +567,9 @@ RSpec.describe Gitlab::Redis::MultiStore do
describe '#to_s' do describe '#to_s' do
subject { multi_store.to_s } subject { multi_store.to_s }
context 'with feature flag :test_store_use_multi_store is enabled' do context 'with feature flag :use_primary_and_secondary_stores_for_test_store is enabled' do
before do before do
stub_feature_flags(test_store_use_multi_store: true) stub_feature_flags(use_primary_and_secondary_stores_for_test_store: true)
end end
it 'returns same value as primary_store' do it 'returns same value as primary_store' do
...@@ -577,14 +577,14 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -577,14 +577,14 @@ RSpec.describe Gitlab::Redis::MultiStore do
end end
end end
context 'with feature flag :test_store_use_multi_store is disabled' do context 'with feature flag :use_primary_and_secondary_stores_for_test_store is disabled' do
before do before do
stub_feature_flags(test_store_use_multi_store: false) stub_feature_flags(use_primary_and_secondary_stores_for_test_store: false)
end end
context 'with feature flag :test_store_use_primary_store is enabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is enabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: true) stub_feature_flags(use_primary_store_as_default_for_test_store: true)
end end
it 'returns same value as primary_store' do it 'returns same value as primary_store' do
...@@ -592,9 +592,9 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -592,9 +592,9 @@ RSpec.describe Gitlab::Redis::MultiStore do
end end
end end
context 'with feature flag :test_store_use_primary_store is disabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is disabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: false) stub_feature_flags(use_primary_store_as_default_for_test_store: false)
end end
it 'returns same value as primary_store' do it 'returns same value as primary_store' do
...@@ -610,46 +610,46 @@ RSpec.describe Gitlab::Redis::MultiStore do ...@@ -610,46 +610,46 @@ RSpec.describe Gitlab::Redis::MultiStore do
end end
end end
describe '#multi_store_enabled?' do describe '#use_primary_and_secondary_stores?' do
context 'with feature flag :test_store_use_multi_store is enabled' do context 'with feature flag :use_primary_and_secondary_stores_for_test_store is enabled' do
before do before do
stub_feature_flags(test_store_use_multi_store: true) stub_feature_flags(use_primary_and_secondary_stores_for_test_store: true)
end end
it 'multi store is disabled' do it 'multi store is disabled' do
expect(multi_store.multi_store_enabled?).to be true expect(multi_store.use_primary_and_secondary_stores?).to be true
end end
end end
context 'with feature flag :test_store_use_multi_store is disabled' do context 'with feature flag :use_primary_and_secondary_stores_for_test_store is disabled' do
before do before do
stub_feature_flags(test_store_use_multi_store: false) stub_feature_flags(use_primary_and_secondary_stores_for_test_store: false)
end end
it 'multi store is disabled' do it 'multi store is disabled' do
expect(multi_store.multi_store_enabled?).to be false expect(multi_store.use_primary_and_secondary_stores?).to be false
end end
end end
end end
describe '#primary_store_enabled?' do describe '#use_primary_store_as_default?' do
context 'with feature flag :test_store_use_primary_store is enabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is enabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: true) stub_feature_flags(use_primary_store_as_default_for_test_store: true)
end end
it 'multi store is disabled' do it 'multi store is disabled' do
expect(multi_store.primary_store_enabled?).to be true expect(multi_store.use_primary_store_as_default?).to be true
end end
end end
context 'with feature flag :test_store_use_primary_store is disabled' do context 'with feature flag :use_primary_store_as_default_for_test_store is disabled' do
before do before do
stub_feature_flags(test_store_use_primary_store: false) stub_feature_flags(use_primary_store_as_default_for_test_store: false)
end end
it 'multi store is disabled' do it 'multi store is disabled' do
expect(multi_store.primary_store_enabled?).to be false expect(multi_store.use_primary_store_as_default?).to be false
end end
end end
end end
......
...@@ -54,6 +54,6 @@ RSpec.describe Gitlab::Redis::Sessions do ...@@ -54,6 +54,6 @@ RSpec.describe Gitlab::Redis::Sessions do
end end
end end
it_behaves_like 'multi store feature flags', :sessions_use_multi_store, :sessions_use_primary_store it_behaves_like 'multi store feature flags', :use_primary_and_secondary_stores_for_sessions, :use_primary_store_as_default_for_sessions
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'multi store feature flags' do |use_multi_store, use_primary_store| RSpec.shared_examples 'multi store feature flags' do |use_primary_and_secondary_stores, use_primary_store_as_default|
context "with feature flag :#{use_multi_store} is enabled" do context "with feature flag :#{use_primary_and_secondary_stores} is enabled" do
before do before do
stub_feature_flags(use_multi_store => true) stub_feature_flags(use_primary_and_secondary_stores => true)
end end
it 'multi store is enabled' do it 'multi store is enabled' do
expect(subject.multi_store_enabled?).to be true expect(subject.use_primary_and_secondary_stores?).to be true
end end
end end
context "with feature flag :#{use_multi_store} is disabled" do context "with feature flag :#{use_primary_and_secondary_stores} is disabled" do
before do before do
stub_feature_flags(use_multi_store => false) stub_feature_flags(use_primary_and_secondary_stores => false)
end end
it 'multi store is disabled' do it 'multi store is disabled' do
expect(subject.multi_store_enabled?).to be false expect(subject.use_primary_and_secondary_stores?).to be false
end end
end end
context "with feature flag :#{use_primary_store} is enabled" do context "with feature flag :#{use_primary_store_as_default} is enabled" do
before do before do
stub_feature_flags(use_primary_store => true) stub_feature_flags(use_primary_store_as_default => true)
end end
it 'primary store is enabled' do it 'primary store is enabled' do
expect(subject.primary_store_enabled?).to be true expect(subject.use_primary_store_as_default?).to be true
end end
end end
context "with feature flag :#{use_primary_store} is disabled" do context "with feature flag :#{use_primary_store_as_default} is disabled" do
before do before do
stub_feature_flags(use_primary_store => false) stub_feature_flags(use_primary_store_as_default => false)
end end
it 'primary store is disabled' do it 'primary store is disabled' do
expect(subject.primary_store_enabled?).to be false expect(subject.use_primary_store_as_default?).to be false
end end
end 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