Commit 526200ba authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Add addition instrumentation data into auth logs

parent 197132cd
...@@ -77,6 +77,8 @@ module Gitlab ...@@ -77,6 +77,8 @@ module Gitlab
rack_attack_info['meta.user'] = user.username unless user.nil? rack_attack_info['meta.user'] = user.username unless user.nil?
end end
Gitlab::InstrumentationHelper.add_instrumentation_data(rack_attack_info)
logger.error(rack_attack_info) logger.error(rack_attack_info)
end end
......
...@@ -78,12 +78,14 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -78,12 +78,14 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do
it 'logs request information' do it 'logs request information' do
expect(Gitlab::AuthLogger).to receive(:error).with( expect(Gitlab::AuthLogger).to receive(:error).with(
message: 'Rack_Attack', include(
env: match_type, message: 'Rack_Attack',
remote_ip: '1.2.3.4', env: match_type,
request_method: 'GET', remote_ip: '1.2.3.4',
path: '/api/v4/internal/authorized_keys', request_method: 'GET',
matched: 'throttle_unauthenticated' path: '/api/v4/internal/authorized_keys',
matched: 'throttle_unauthenticated'
)
) )
subscriber.send(match_type, event) subscriber.send(match_type, event)
end end
...@@ -109,13 +111,15 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -109,13 +111,15 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do
it 'logs request information and user id' do it 'logs request information and user id' do
expect(Gitlab::AuthLogger).to receive(:error).with( expect(Gitlab::AuthLogger).to receive(:error).with(
message: 'Rack_Attack', include(
env: match_type, message: 'Rack_Attack',
remote_ip: '1.2.3.4', env: match_type,
request_method: 'GET', remote_ip: '1.2.3.4',
path: '/api/v4/internal/authorized_keys', request_method: 'GET',
matched: 'throttle_authenticated_api', path: '/api/v4/internal/authorized_keys',
user_id: 'not_exist_user_id' matched: 'throttle_authenticated_api',
user_id: 'not_exist_user_id'
)
) )
subscriber.send(match_type, event) subscriber.send(match_type, event)
end end
...@@ -141,14 +145,16 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -141,14 +145,16 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do
it 'logs request information and user meta' do it 'logs request information and user meta' do
expect(Gitlab::AuthLogger).to receive(:error).with( expect(Gitlab::AuthLogger).to receive(:error).with(
message: 'Rack_Attack', include(
env: match_type, message: 'Rack_Attack',
remote_ip: '1.2.3.4', env: match_type,
request_method: 'GET', remote_ip: '1.2.3.4',
path: '/api/v4/internal/authorized_keys', request_method: 'GET',
matched: 'throttle_authenticated_api', path: '/api/v4/internal/authorized_keys',
user_id: user.id, matched: 'throttle_authenticated_api',
'meta.user' => user.username user_id: user.id,
'meta.user' => user.username
)
) )
subscriber.send(match_type, event) subscriber.send(match_type, event)
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