Commit ca0859c5 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'tc-geo-ff' into 'master'

Change how flipping features creates Geo event

Closes #247535

See merge request gitlab-org/gitlab!42070
parents fdafc413 1a5fbd44
---
title: Create a Geo cache invalidation event when toggling feature flags through the
API
merge_request: 42070
author:
type: fixed
......@@ -2,70 +2,42 @@
module EE
module Feature
module ClassMethods
module ActiveSupportCacheStoreAdapter
extend ::Gitlab::Utils::Override
override :enable
def enable(key, thing = true)
super
log_geo_event(key)
end
override :disable
def disable(key, thing = false)
super
log_geo_event(key)
end
override :enable_group
def enable_group(key, group)
super
log_geo_event(key)
end
override :disable_group
def disable_group(key, group)
super
log_geo_event(key)
override :remove
def remove(key)
super.tap do |result|
log_geo_event(key) if result
end
end
override :enable_percentage_of_time
def enable_percentage_of_time(key, percentage)
super
log_geo_event(key)
override :clear
def clear(key)
super.tap do |result|
log_geo_event(key) if result
end
end
override :disable_percentage_of_time
def disable_percentage_of_time(key)
super
log_geo_event(key)
end
override :enable_percentage_of_actors
def enable_percentage_of_actors(key, percentage)
super
log_geo_event(key)
override :enable
def enable(key, *_)
super.tap do |result|
log_geo_event(key) if result
end
end
override :disable_percentage_of_actors
def disable_percentage_of_actors(key)
super
log_geo_event(key)
override :disable
def disable(key, *_)
super.tap do |result|
log_geo_event(key) if result
end
end
private
def log_geo_event(key)
Geo::CacheInvalidationEventStore.new(cache_store.key_for(key)).create!
Geo::CacheInvalidationEventStore.new(key_for(key)).create!
end
def cache_store
Flipper::Adapters::ActiveSupportCacheStore
end
end
def self.prepended(base)
base.singleton_class.prepend ClassMethods
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Feature do
RSpec.describe Feature, stub_feature_flags: false do
include EE::GeoHelpers
describe '.enable' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Features, stub_feature_flags: false do
include EE::GeoHelpers
let_it_be(:admin) { create(:admin) }
before do
Feature.reset
Flipper.unregister_groups
Flipper.register(:perf_team) do |actor|
actor.respond_to?(:admin) && actor.admin?
end
end
describe 'POST /feature' do
let(:feature_name) { 'my_feature' }
context 'when running on a Geo primary node' do
before do
stub_primary_node
allow(Gitlab::Geo).to receive(:secondary_nodes) { [double] }
end
it 'creates Geo cache invalidation event' do
expect do
post api("/features/#{feature_name}", admin), params: { value: 'true' }
end.to change(Geo::CacheInvalidationEvent, :count).by(1)
end
end
end
describe 'DELETE /feature/:name' do
let(:feature_name) { 'my_feature' }
context 'when running on a Geo primary node' do
before do
stub_primary_node
allow(Gitlab::Geo).to receive(:secondary_nodes) { [double] }
end
it 'creates Geo cache invalidation event' do
Feature.enable(feature_name)
expect do
delete api("/features/#{feature_name}", admin)
end.to change(Geo::CacheInvalidationEvent, :count).by(1)
end
end
end
end
......@@ -18,6 +18,10 @@ class Feature
superclass.table_name = 'feature_gates'
end
class ActiveSupportCacheStoreAdapter < Flipper::Adapters::ActiveSupportCacheStore
# overrides methods in EE
end
InvalidFeatureFlagError = Class.new(Exception) # rubocop:disable Lint/InheritException
class << self
......@@ -160,7 +164,7 @@ class Feature
# Redis L2 cache
redis_cache_adapter =
Flipper::Adapters::ActiveSupportCacheStore.new(
ActiveSupportCacheStoreAdapter.new(
active_record_adapter,
l2_cache_backend,
expires_in: 1.hour)
......@@ -237,4 +241,4 @@ class Feature
end
end
Feature.prepend_if_ee('EE::Feature')
Feature::ActiveSupportCacheStoreAdapter.prepend_if_ee('EE::Feature::ActiveSupportCacheStoreAdapter')
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