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,6 +78,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -78,6 +78,7 @@ 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(
include(
message: 'Rack_Attack', message: 'Rack_Attack',
env: match_type, env: match_type,
remote_ip: '1.2.3.4', remote_ip: '1.2.3.4',
...@@ -85,6 +86,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -85,6 +86,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do
path: '/api/v4/internal/authorized_keys', path: '/api/v4/internal/authorized_keys',
matched: 'throttle_unauthenticated' matched: 'throttle_unauthenticated'
) )
)
subscriber.send(match_type, event) subscriber.send(match_type, event)
end end
end end
...@@ -109,6 +111,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -109,6 +111,7 @@ 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(
include(
message: 'Rack_Attack', message: 'Rack_Attack',
env: match_type, env: match_type,
remote_ip: '1.2.3.4', remote_ip: '1.2.3.4',
...@@ -117,6 +120,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -117,6 +120,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do
matched: 'throttle_authenticated_api', matched: 'throttle_authenticated_api',
user_id: 'not_exist_user_id' user_id: 'not_exist_user_id'
) )
)
subscriber.send(match_type, event) subscriber.send(match_type, event)
end end
end end
...@@ -141,6 +145,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -141,6 +145,7 @@ 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(
include(
message: 'Rack_Attack', message: 'Rack_Attack',
env: match_type, env: match_type,
remote_ip: '1.2.3.4', remote_ip: '1.2.3.4',
...@@ -150,6 +155,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do ...@@ -150,6 +155,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do
user_id: user.id, user_id: user.id,
'meta.user' => user.username 'meta.user' => user.username
) )
)
subscriber.send(match_type, event) subscriber.send(match_type, event)
end end
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