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