Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync_repos: allow private repo permissions to be set on error #478

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

matt-codecov
Copy link
Contributor

@matt-codecov matt-codecov commented May 30, 2024

codecov/engineering-team#1757

in most tasks, all db writes occur in a transaction and if an uncaught error occurs we roll the transaction back. for sync_repos, if a user syncs 999/1000 repos and then encounters an error, we actually don't want to roll everything back.

sync_repos already commits after each repo insert so the repo data won't be thrown away. however, what we don't do is update the list of private repos that the syncing user can see. so if they sync 999 new private repos and then get a 502, the 999 repos will be in our database but we won't let the user view any of them. this PR changes that

the old behavior, when catching a worker task timeout or TorngitClientError, would clear the private repo permission list entirely to avoid the possibility of leaving the user with permission they shouldn't have. that was stricter than necessary though; the private_project_ids list may be incomplete if an error occurs before we've processed every repo but the things it does have are definitely visible to the user. so it's fine to set owner.permission = private_project_ids.

the old behavior did not catch TorngitServerFailureError and if such an error occurred (as it would if github returns a 504) no changes would be made to the private repo permission list. no new repos will be added, and if access to a private repo was supposed to have been revoked, the user will still be able to see it in codecov.

the new behavior handles timeouts, TorngitClientErrors, and TorngitServerFailureErrors the same way: log the error, mention that the private repo permission list may be incomplete, and then set owner.permission and complete the task normally. the way this appears to the user:

  • a new or existing user who sees a worker task timeout or TorngitClientError (e.g. rate limit, token flukes) will no longer have the list of private repos they can see totally wiped. the list may be incomplete, but it will no longer be empty
  • a new user who sees a TorngitServerFailureError (e.g. github 504) will not be left with an empty list of private repos. they will be able to see any repos that successfully synced
  • an existing user who sees a TorngitServerFailureError (e.g. github 504) will have their permission list updated to a new, possibly incomplete list. some repos may be added, some repos may "disappear". repos that should not be in the list will no longer be in the list

@codecov-staging
Copy link

codecov-staging bot commented May 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #478   +/-   ##
=======================================
  Coverage   97.26%   97.26%           
=======================================
  Files         412      412           
  Lines       34122    34114    -8     
=======================================
- Hits        33189    33182    -7     
+ Misses        933      932    -1     
Flag Coverage Δ
integration 97.26% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.26% <100.00%> (+<0.01%) ⬆️
unit 97.26% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.38% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.52% <ø> (ø)
Files Coverage Δ
tasks/sync_repos.py 97.57% <100.00%> (+0.44%) ⬆️
tasks/tests/unit/test_sync_repos_task.py 99.41% <100.00%> (-0.01%) ⬇️

@codecov-qa
Copy link

codecov-qa bot commented May 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.26%. Comparing base (2d39bca) to head (1932d02).

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #478   +/-   ##
=======================================
  Coverage   97.26%   97.26%           
=======================================
  Files         412      412           
  Lines       34122    34114    -8     
=======================================
- Hits        33189    33182    -7     
+ Misses        933      932    -1     
Flag Coverage Δ
integration 97.26% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.26% <100.00%> (+<0.01%) ⬆️
unit 97.26% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.38% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.52% <ø> (ø)
Files Coverage Δ
tasks/sync_repos.py 97.57% <100.00%> (+0.44%) ⬆️
tasks/tests/unit/test_sync_repos_task.py 99.41% <100.00%> (-0.01%) ⬇️

Copy link

codecov-public-qa bot commented May 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.26%. Comparing base (2d39bca) to head (1932d02).

✅ All tests successful. No failed tests found ☺️

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #478   +/-   ##
=======================================
  Coverage   97.26%   97.26%           
=======================================
  Files         412      412           
  Lines       34122    34114    -8     
=======================================
- Hits        33189    33182    -7     
+ Misses        933      932    -1     
Flag Coverage Δ
integration 97.26% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.26% <100.00%> (+<0.01%) ⬆️
unit 97.26% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.38% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.52% <ø> (ø)
Files Coverage Δ
tasks/sync_repos.py 97.57% <100.00%> (+0.44%) ⬆️
tasks/tests/unit/test_sync_repos_task.py 99.41% <100.00%> (-0.01%) ⬇️

Copy link

codecov bot commented May 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.29%. Comparing base (2d39bca) to head (1932d02).

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #478   +/-   ##
=======================================
  Coverage   97.29%   97.29%           
=======================================
  Files         443      443           
  Lines       34851    34843    -8     
=======================================
- Hits        33908    33901    -7     
+ Misses        943      942    -1     
Flag Coverage Δ
integration 97.26% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.26% <100.00%> (+<0.01%) ⬆️
unit 97.26% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 94.43% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.52% <ø> (ø)
Files Coverage Δ
tasks/sync_repos.py 97.58% <100.00%> (+0.44%) ⬆️
tasks/tests/unit/test_sync_repos_task.py 99.41% <100.00%> (-0.01%) ⬇️
Related Entrypoints
run/app.tasks.sync_repos.SyncRepos

number_old_permissions=len(old_permissions),
number_new_permissions=len(set(private_project_ids)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goated log ngl

Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@matt-codecov matt-codecov added this pull request to the merge queue Jun 4, 2024
Merged via the queue into main with commit 0e1095f Jun 4, 2024
29 of 30 checks passed
@matt-codecov matt-codecov deleted the pr478 branch June 4, 2024 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants