Add Gitlab::Redis::BufferedCounter to migrate buffered counters
What does this MR do and why?
This MR creates a new Redis class for BufferedCounter
which uses redis.shared_state.yml
or SharedState
's config file.
This stops the use of MultiStore for buffered counter. Since buffered counter is write-heavy and prone to data race, MultiStore
is not an ideal mode of migration.
See gitlab-com/gl-infra/production#17188 (comment 1687915727)
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
- Open a rails console and verify that the
Redis::BufferedCounter
usesSharedState
's instrumentation class.
pry(main)> Gitlab::Redis::BufferedCounter.params
=> {:instrumentation_class=>Gitlab::Instrumentation::Redis::SharedState, :path=>"/Users/sylvesterchin/work/gitlab-development-kit/redis/redis.socket", :db=>0}
- It is a single Redis connection (non-multistore)
[1] pry(main)> Gitlab::Redis::BufferedCounter.with{|c|c}
=> #<Redis client v4.8.0 for unix:///Users/sylvesterchin/work/gitlab-development-kit/redis/redis.socket/0>
[2] pry(main)> Gitlab::Redis::SharedState.with{|c|c}
Feature::FlipperGate Pluck (0.4ms) SELECT "feature_gates"."key", "feature_gates"."value" FROM "feature_gates" WHERE "feature_gates"."feature_key" = 'use_primary_store_as_default_for_shared_state' /*application:console,db_config_name:main,console_hostname:SylvestersMBP2.localdomain,console_username:sylvesterchin,line:/lib/feature.rb:314:in `block in current_feature_value'*/
=> #<Gitlab::Redis::MultiStore:0x0000000137c9c7b8
@instance_name="SharedState",
@primary_store=#<Redis client v4.8.0 for unix:///Users/sylvesterchin/work/gitlab-development-kit/redis/redis.socket/0>,
@same_redis_store=true,
@secondary_store=#<Redis client v4.8.0 for unix:///Users/sylvesterchin/work/gitlab-development-kit/redis/redis.socket/0>>
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Sylvester Chin