Commit a51f4e64 authored by Piotr Skorupa's avatar Piotr Skorupa

Add HLLRedisCounter errors to redis_usage_counter

There are instances (e.g. in Gitlab::UsageData) of passing
HLLRedisCounter to the block in #redis_usage_data and it's errors
wouldn't be rescued to return fallback value. This would potentially
result in failing the entire Usage Ping generation.

This prevents that and hardens the method. All HLLRedisCounter custom
exceptions are rescued, since EventError is their superclass.

See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/54600
parent 3262be6b
......@@ -24,7 +24,8 @@
# alt_usage_data(fallback: nil) { Gitlab.config.registry.enabled }
#
# * redis_usage_data method
# handles ::Redis::CommandError, Gitlab::UsageDataCounters::BaseCounter::UnknownEvent
# handles ::Redis::CommandError, Gitlab::UsageDataCounters::BaseCounter::UnknownEvent,
# Gitlab::UsageDataCounters::HLLRedisCounter::EventError
# returns -1 when a block is sent or hash with all values -1 when a counter is sent
# different behaviour due to 2 different implementations of redis counter
#
......@@ -160,7 +161,7 @@ module Gitlab
def redis_usage_counter
yield
rescue ::Redis::CommandError, Gitlab::UsageDataCounters::BaseCounter::UnknownEvent
rescue ::Redis::CommandError, Gitlab::UsageDataCounters::BaseCounter::UnknownEvent, Gitlab::UsageDataCounters::HLLRedisCounter::EventError
FALLBACK
end
......
......@@ -203,6 +203,12 @@ RSpec.describe Gitlab::Utils::UsageData do
expect(described_class.redis_usage_data { raise ::Redis::CommandError } ).to eq(-1)
end
it 'returns the fallback when Redis HLL raises any error' do
stub_const("Gitlab::Utils::UsageData::FALLBACK", 15)
expect(described_class.redis_usage_data { raise Gitlab::UsageDataCounters::HLLRedisCounter::CategoryMismatch } ).to eq(15)
end
it 'returns the evaluated block when given' do
expect(described_class.redis_usage_data { 1 }).to eq(1)
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