Commit e3acaaa8 authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Rename rack_attack.redis channel to redis.rack_attack

Issue https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/751
parent 4ca0e4ab
......@@ -10,8 +10,9 @@ module Gitlab
# - rack_attack_redis_duration_s: the total duration of all redis calls
# triggered by RackAttack in a request.
class RackAttack < ActiveSupport::Subscriber
attach_to 'rack_attack'
INSTRUMENTATION_STORE_KEY = :rack_attack_instrumentation
attach_to 'redis'
PAYLOAD_KEYS = [
:rack_attack_redis_count,
......@@ -25,7 +26,7 @@ module Gitlab
}
end
def rack_attack(event)
def redis(event)
self.class.payload[:rack_attack_redis_count] += 1
self.class.payload[:rack_attack_redis_duration_s] += event.duration.to_f / 1000
end
......
......@@ -10,7 +10,7 @@ module Gitlab
# For more information, please see
# https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/751
class InstrumentedCacheStore
NOTIFICATION_CHANNEL = 'rack_attack.redis'
NOTIFICATION_CHANNEL = 'redis.rack_attack'
delegate :silence!, :mute, to: :@upstream_store
......
......@@ -32,22 +32,22 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do
end
end
describe '#rack_attack' do
describe '#redis' do
it 'accumulates per-request RackAttack cache usage' do
freeze_time do
subscriber.rack_attack(
subscriber.redis(
ActiveSupport::Notifications::Event.new(
'rack_attack.redis', Time.current, Time.current + 1.second, '1', { operation: 'fetch' }
'redis.rack_attack', Time.current, Time.current + 1.second, '1', { operation: 'fetch' }
)
)
subscriber.rack_attack(
subscriber.redis(
ActiveSupport::Notifications::Event.new(
'rack_attack.redis', Time.current, Time.current + 2.seconds, '1', { operation: 'write' }
'redis.rack_attack', Time.current, Time.current + 2.seconds, '1', { operation: 'write' }
)
)
subscriber.rack_attack(
subscriber.redis(
ActiveSupport::Notifications::Event.new(
'rack_attack.redis', Time.current, Time.current + 3.seconds, '1', { operation: 'read' }
'redis.rack_attack', Time.current, Time.current + 3.seconds, '1', { operation: 'read' }
)
)
end
......
......@@ -32,10 +32,10 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do
published = false
begin
subscriber = ActiveSupport::Notifications.subscribe("rack_attack.redis") do |*args|
subscriber = ActiveSupport::Notifications.subscribe("redis.rack_attack") do |*args|
published = true
event = ActiveSupport::Notifications::Event.new(*args)
expect(event.name).to eq("rack_attack.redis")
expect(event.name).to eq("redis.rack_attack")
expect(event.duration).to be_a(Float).and(be > 0.0)
expect(event.payload[:operation]).to eql(operation)
end
......@@ -54,10 +54,10 @@ RSpec.describe Gitlab::RackAttack::InstrumentedCacheStore do
exception = false
begin
subscriber = ActiveSupport::Notifications.subscribe("rack_attack.redis") do |*args|
subscriber = ActiveSupport::Notifications.subscribe("redis.rack_attack") do |*args|
published = true
event = ActiveSupport::Notifications::Event.new(*args)
expect(event.name).to eq("rack_attack.redis")
expect(event.name).to eq("redis.rack_attack")
expect(event.duration).to be_a(Float).and(be > 0.0)
expect(event.payload[:operation]).to eql(operation)
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