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