Commit 86251eb3 authored by Imre Farkas's avatar Imre Farkas

Expand logs of authorized projects refresh

parent 2c3ae4c3
...@@ -92,7 +92,7 @@ module Users ...@@ -92,7 +92,7 @@ module Users
# remove - The IDs of the authorization rows to remove. # remove - The IDs of the authorization rows to remove.
# add - Rows to insert in the form `[user id, project id, access level]` # add - Rows to insert in the form `[user id, project id, access level]`
def update_authorizations(remove = [], add = []) def update_authorizations(remove = [], add = [])
log_refresh_details(remove.length, add.length) log_refresh_details(remove, add)
User.transaction do User.transaction do
user.remove_project_authorizations(remove) unless remove.empty? user.remove_project_authorizations(remove) unless remove.empty?
...@@ -104,11 +104,16 @@ module Users ...@@ -104,11 +104,16 @@ module Users
user.reset user.reset
end end
def log_refresh_details(rows_deleted, rows_added) def log_refresh_details(remove, add)
Gitlab::AppJsonLogger.info(event: 'authorized_projects_refresh', Gitlab::AppJsonLogger.info(event: 'authorized_projects_refresh',
user_id: user.id,
'authorized_projects_refresh.source': source, 'authorized_projects_refresh.source': source,
'authorized_projects_refresh.rows_deleted': rows_deleted, 'authorized_projects_refresh.rows_deleted_count': remove.length,
'authorized_projects_refresh.rows_added': rows_added) 'authorized_projects_refresh.rows_added_count': add.length,
# most often there's only a few entries in remove and add, but limit it to the first 5
# entries to avoid flooding the logs
'authorized_projects_refresh.rows_deleted_slice': remove.first(5),
'authorized_projects_refresh.rows_added_slice': add.first(5))
end end
def fresh_access_levels_per_project def fresh_access_levels_per_project
......
...@@ -152,9 +152,13 @@ RSpec.describe Users::RefreshAuthorizedProjectsService do ...@@ -152,9 +152,13 @@ RSpec.describe Users::RefreshAuthorizedProjectsService do
expect(Gitlab::AppJsonLogger).to( expect(Gitlab::AppJsonLogger).to(
receive(:info) receive(:info)
.with(event: 'authorized_projects_refresh', .with(event: 'authorized_projects_refresh',
user_id: user.id,
'authorized_projects_refresh.source': source, 'authorized_projects_refresh.source': source,
'authorized_projects_refresh.rows_deleted': 0, 'authorized_projects_refresh.rows_deleted_count': 0,
'authorized_projects_refresh.rows_added': 1)) 'authorized_projects_refresh.rows_added_count': 1,
'authorized_projects_refresh.rows_deleted_slice': [],
'authorized_projects_refresh.rows_added_slice': [[user.id, project.id, Gitlab::Access::MAINTAINER]])
)
service.update_authorizations([], [[user.id, project.id, Gitlab::Access::MAINTAINER]]) service.update_authorizations([], [[user.id, project.id, Gitlab::Access::MAINTAINER]])
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