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

Clean up UploadXXX tasks #592

Closed
wants to merge 6 commits into from
Closed

Clean up UploadXXX tasks #592

wants to merge 6 commits into from

Conversation

Swatinem
Copy link
Contributor

@Swatinem Swatinem commented Aug 6, 2024

Various improvements like fixing typos, adding types and using more modern code patterns

For the Upload task in particular:

  • Use a LoggerAdapter to simplify adding more logging context
  • Use a custom chunks generator together with list comprehension instead of manual loops
    • ☝🏻 this also fixes a problem where previously the last chunk/task would not be properly flagged as is_final

As this re-indents a bunch of code, I highly recommend to use "ignore whitespace" when reviewing.

@Swatinem Swatinem self-assigned this Aug 6, 2024
Copy link

codecov bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 94.21488% with 14 lines in your changes missing coverage. Please review.

Project coverage is 97.65%. Comparing base (1357214) to head (edbc490).

Changes have been made to critical files, which contain lines commonly executed in production. Learn more

✅ All tests successful. No failed tests found.

Files Patch % Lines
tasks/upload.py Critical 86.81% 12 Missing ⚠️
tasks/upload_finisher.py 85.71% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #592      +/-   ##
==========================================
+ Coverage   97.61%   97.65%   +0.04%     
==========================================
  Files         464      464              
  Lines       37157    37098      -59     
==========================================
- Hits        36271    36229      -42     
+ Misses        886      869      -17     
Flag Coverage Δ
integration 97.61% <94.21%> (+0.04%) ⬆️
latest-uploader-overall 97.61% <94.21%> (+0.04%) ⬆️
unit 97.61% <94.21%> (+0.04%) ⬆️

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

Components Coverage Δ
NonTestCode 94.90% <91.56%> (+0.09%) ⬆️
OutsideTasks 97.81% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/repository.py Critical 96.69% <100.00%> (+0.34%) ⬆️
services/tests/test_repository_service.py 99.78% <100.00%> (+0.01%) ⬆️
tasks/preprocess_upload.py 100.00% <100.00%> (+8.64%) ⬆️
tasks/tests/unit/test_preprocess_upload.py 100.00% <ø> (ø)
tasks/tests/unit/test_upload_finisher_task.py 100.00% <ø> (ø)
tasks/tests/unit/test_upload_processing_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_upload_task.py 99.52% <100.00%> (-0.04%) ⬇️
tasks/upload_processor.py 92.59% <100.00%> (-0.48%) ⬇️
tasks/upload_finisher.py 73.70% <85.71%> (-0.03%) ⬇️
tasks/upload.py Critical 93.65% <86.81%> (+2.05%) ⬆️

... and 1 file with indirect coverage changes

Related Entrypoints
run/app.tasks.upload.Upload
run/app.tasks.upload.UploadFinisher
run/app.tasks.upload.UploadProcessor
run/app.tasks.upload.PreProcessUpload

@codecov-staging
Copy link

codecov-staging bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 94.21488% with 14 lines in your changes missing coverage. Please review.

Files Patch % Lines
tasks/upload.py 86.81% 12 Missing ⚠️
tasks/upload_finisher.py 85.71% 2 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #592      +/-   ##
==========================================
+ Coverage   97.57%   97.61%   +0.04%     
==========================================
  Files         429      429              
  Lines       35951    35892      -59     
==========================================
- Hits        35079    35037      -42     
+ Misses        872      855      -17     
Flag Coverage Δ
integration 97.61% <94.21%> (+0.04%) ⬆️
latest-uploader-overall 97.61% <94.21%> (+0.04%) ⬆️
unit 97.61% <94.21%> (+0.04%) ⬆️

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

Components Coverage Δ
NonTestCode 94.82% <91.56%> (+0.09%) ⬆️
OutsideTasks 97.81% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/repository.py 96.69% <100.00%> (+0.34%) ⬆️
services/tests/test_repository_service.py 99.78% <100.00%> (+0.01%) ⬆️
tasks/preprocess_upload.py 100.00% <100.00%> (+8.75%) ⬆️
tasks/tests/unit/test_preprocess_upload.py 100.00% <ø> (ø)
tasks/tests/unit/test_upload_finisher_task.py 100.00% <ø> (ø)
tasks/tests/unit/test_upload_processing_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_upload_task.py 99.52% <100.00%> (-0.04%) ⬇️
tasks/upload_processor.py 92.02% <100.00%> (-0.52%) ⬇️
tasks/upload_finisher.py 73.58% <85.71%> (-0.03%) ⬇️
tasks/upload.py 93.61% <86.81%> (+2.06%) ⬆️

... and 1 file with indirect coverage changes

@codecov-qa
Copy link

codecov-qa bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 94.21488% with 14 lines in your changes missing coverage. Please review.

Project coverage is 97.61%. Comparing base (1357214) to head (edbc490).

✅ All tests successful. No failed tests found.

Files Patch % Lines
tasks/upload.py 86.81% 12 Missing ⚠️
tasks/upload_finisher.py 85.71% 2 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #592      +/-   ##
==========================================
+ Coverage   97.57%   97.61%   +0.04%     
==========================================
  Files         429      429              
  Lines       35951    35892      -59     
==========================================
- Hits        35079    35037      -42     
+ Misses        872      855      -17     
Flag Coverage Δ
integration 97.61% <94.21%> (+0.04%) ⬆️
latest-uploader-overall 97.61% <94.21%> (+0.04%) ⬆️
unit 97.61% <94.21%> (+0.04%) ⬆️

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

Components Coverage Δ
NonTestCode 94.82% <91.56%> (+0.09%) ⬆️
OutsideTasks 97.81% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/repository.py 96.69% <100.00%> (+0.34%) ⬆️
services/tests/test_repository_service.py 99.78% <100.00%> (+0.01%) ⬆️
tasks/preprocess_upload.py 100.00% <100.00%> (+8.75%) ⬆️
tasks/tests/unit/test_preprocess_upload.py 100.00% <ø> (ø)
tasks/tests/unit/test_upload_finisher_task.py 100.00% <ø> (ø)
tasks/tests/unit/test_upload_processing_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_upload_task.py 99.52% <100.00%> (-0.04%) ⬇️
tasks/upload_processor.py 92.02% <100.00%> (-0.52%) ⬇️
tasks/upload_finisher.py 73.58% <85.71%> (-0.03%) ⬇️
tasks/upload.py 93.61% <86.81%> (+2.06%) ⬆️

... and 1 file with indirect coverage changes

Copy link

codecov-public-qa bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 94.21488% with 14 lines in your changes missing coverage. Please review.

Project coverage is 97.61%. Comparing base (1357214) to head (edbc490).

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #592      +/-   ##
==========================================
+ Coverage   97.57%   97.61%   +0.04%     
==========================================
  Files         429      429              
  Lines       35951    35892      -59     
==========================================
- Hits        35079    35037      -42     
+ Misses        872      855      -17     
Flag Coverage Δ
integration 97.61% <94.21%> (+0.04%) ⬆️
latest-uploader-overall 97.61% <94.21%> (+0.04%) ⬆️
unit 97.61% <94.21%> (+0.04%) ⬆️

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

Components Coverage Δ
NonTestCode 94.82% <91.56%> (+0.09%) ⬆️
OutsideTasks 97.81% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/repository.py 96.69% <100.00%> (+0.34%) ⬆️
services/tests/test_repository_service.py 99.78% <100.00%> (+0.01%) ⬆️
tasks/preprocess_upload.py 100.00% <100.00%> (+8.75%) ⬆️
tasks/tests/unit/test_preprocess_upload.py 100.00% <ø> (ø)
tasks/tests/unit/test_upload_finisher_task.py 100.00% <ø> (ø)
tasks/tests/unit/test_upload_processing_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_upload_task.py 99.52% <100.00%> (-0.04%) ⬇️
tasks/upload_processor.py 92.02% <100.00%> (-0.52%) ⬇️
tasks/upload_finisher.py 73.58% <85.71%> (-0.03%) ⬇️
tasks/upload.py 93.61% <86.81%> (+2.06%) ⬆️

... and 1 file with indirect coverage changes

@@ -609,8 +595,7 @@ def test_upload_task_call_multiple_processors(
],
report_code=None,
in_parallel=False,
is_final=False,
),
is_final=True,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an interesting driveby fix. The previous code would get this wrong for the last chunk happens to be on a chunk border. I initially replicated the same buggy behavior, but then found a better fix for it that correctly flags the final chunk/task.

@Swatinem Swatinem marked this pull request as ready for review August 7, 2024 10:20
@Swatinem Swatinem requested a review from a team August 7, 2024 10:21
tasks/upload.py Outdated
)
return {"was_setup": was_setup, "was_updated": was_updated}

def fetch_commit_yaml_and_possibly_store(self, commit, repository_service):
def fetch_commit_yaml_and_possibly_store(self, commit: Commit, repository_service):
Copy link
Contributor

Choose a reason for hiding this comment

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

If you'd like to type report_service, that's TorngitBaseAdapter 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah nice, that is good to know! I found out that PreProcessUpload.fetch_commit_yaml_and_possibly_store is a duplicated version of this function, so I moved it and its associated tests over to services.repository, as it was also not dependent on self at all.

Copy link
Contributor

@adrian-codecov adrian-codecov left a comment

Choose a reason for hiding this comment

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

Thanks for this change Arpad! All for typing + better conventions.

I left some comments although I didn't have as thorough input with the parallel processing part in uploads.py as I'm not as familiar, I'd encourage you to have someone's eyes on that if possible, also being a big change in the system.

And have you given this a test run locally/in staging to ensure it works with these changes?

This removes some unused code, and cleans up the rest:

- Adds types and moves to more modern code patterns
- Uses a `LoggerAdapter` to automatically add common log extras
- Prefers list comprehensions and a chunks generator over manual loops and slicing
@Swatinem
Copy link
Contributor Author

Swatinem commented Aug 9, 2024

Converting this to a draft. I will be splitting this up into smaller more digestible pieces.

@Swatinem Swatinem deleted the swatinem/cleanup-upload branch August 14, 2024 11:13
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.

2 participants