Skip to content
代码片段 群组 项目
提交 ebaebe73 编辑于 作者: Bojan Marjanovic's avatar Bojan Marjanovic
浏览文件

Merge branch 'sc1-buffered-counter-redis-migration-helper' into 'master'

Add Gitlab::Redis::BufferedCounter to migrate buffered counters

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/139348



Merged-by: default avatarBojan Marjanovic <bmarjanovic@gitlab.com>
Approved-by: default avatarBojan Marjanovic <bmarjanovic@gitlab.com>
Reviewed-by: default avatarBojan Marjanovic <bmarjanovic@gitlab.com>
Co-authored-by: default avatarSylvester Chin <schin@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -248,7 +248,7 @@ def remove_flushed_key
end
def redis_state(&block)
Gitlab::Redis::SharedState.with(&block)
Gitlab::Redis::BufferedCounter.with(&block)
end
def with_exclusive_lease(&block)
......
......@@ -8,6 +8,7 @@ module Redis
# This will make sure the connection pool is initialized on application boot in
# config/initializers/7_redis.rb, instrumented, and used in health- & readiness checks.
ALL_CLASSES = [
Gitlab::Redis::BufferedCounter,
Gitlab::Redis::Cache,
Gitlab::Redis::ClusterSharedState,
Gitlab::Redis::DbLoadBalancing,
......
# frozen_string_literal: true
module Gitlab
module Redis
class BufferedCounter < ::Gitlab::Redis::Wrapper
class << self
def config_fallback
SharedState
end
def params
# This avoid using Gitlab::Instrumentation::Redis::BufferedCounter since this class is a temporary
# helper for migration. The redis commands should be tracked under the label of `storage: shared_state`.
super.merge({ instrumentation_class: ::Gitlab::Instrumentation::Redis::SharedState })
end
end
end
end
end
......@@ -13,7 +13,7 @@
describe '#get' do
it 'returns the value when there is an existing value stored in the counter' do
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
redis.set(counter.key, 456)
end
......@@ -393,7 +393,7 @@
it 'removes the key from Redis' do
counter.initiate_refresh!
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
expect(redis.exists?(counter.key)).to eq(false)
end
end
......@@ -488,7 +488,7 @@
end
it 'removes all tracking keys' do
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
expect { counter.cleanup_refresh }
.to change { redis.scan_each(match: "#{counter.refresh_key}*").to_a.count }.from(4).to(0)
end
......@@ -533,7 +533,7 @@
let(:flushed_amount) { 10 }
before do
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
redis.incrby(counter.flushed_key, flushed_amount)
end
end
......@@ -546,7 +546,7 @@
it 'deletes the relative :flushed key' do
counter.commit_increment!
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
key_exists = redis.exists?(counter.flushed_key)
expect(key_exists).to be_falsey
end
......@@ -555,7 +555,7 @@
context 'when deleting :flushed key fails' do
before do
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
redis.incrby(counter.flushed_key, 10)
allow(redis).to receive(:del).and_raise('could not delete key')
......@@ -614,7 +614,7 @@
with_them do
before do
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
redis.set(increment_key, increment) if increment
redis.set(flushed_key, flushed) if flushed
end
......@@ -635,19 +635,19 @@
end
def redis_get_key(key)
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
redis.get(key)
end
end
def redis_exists_key(key)
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
redis.exists?(key)
end
end
def redis_key_ttl(key)
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::BufferedCounter.with do |redis|
redis.ttl(key)
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Redis::BufferedCounter, feature_category: :redis do
include_examples "redis_new_instance_shared_examples", 'buffered_counter', Gitlab::Redis::SharedState
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Projects::RefreshBuildArtifactsSizeStatisticsService, :clean_gitlab_redis_shared_state, feature_category: :build_artifacts do
RSpec.describe Projects::RefreshBuildArtifactsSizeStatisticsService, :clean_gitlab_redis_buffered_counter, feature_category: :build_artifacts do
let(:service) { described_class.new }
describe '#execute' do
......@@ -79,7 +79,7 @@
end
before do
allow(Gitlab::Redis::SharedState).to receive(:with).and_raise(StandardError, 'error')
allow(Gitlab::Redis::BufferedCounter).to receive(:with).and_raise(StandardError, 'error')
expect { service.execute }.to raise_error(StandardError)
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册