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

fix: UI and status report diff patch numbers #679

Merged
merged 3 commits into from
Sep 5, 2024

Conversation

giovanni-guidini
Copy link
Contributor

related: https://github.com/codecov/internal-issues/issues/721
related: codecov/engineering-team#2387

We have a problem that the UI and the statuses are reporting different numbers for patch.
Part of this issue is that the NotifyTask (calculates patch for status) has access to the Pull while the ComputeComparison (calculates for the UI) doesn't.

This is a problem because the base for patch coverage might be different, so numbers would be different (see here that we assume no action is needed cause there's nothing we can do).

So the 1st change here is to have the NotifyTask calculate and save patch coverage.
The second change is to cache the patch calculation so we don't compute it more than once.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

related: codecov/internal-issues#721
related: codecov/engineering-team#2387

We have a problem that the UI and the statuses are reporting different numbers for patch.
Part of this issue is that the `NotifyTask` (calculates patch for status) has access to the `Pull` while the `ComputeComparison` (calculates for the UI) doesn't.

This is a problem because the base for patch coverage might be different, so numbers would be different (see [here](https://github.com/codecov/worker/blob/9078de24b4dbed1bb64250b2b3864336954f310c/tasks/compute_comparison.py#L334) that we assume no action is needed cause there's nothing we can do).

So the 1st change here is to have the `NotifyTask` calculate and save patch coverage.
The second change is to cache the patch calculation so we don't compute it more than once.
@giovanni-guidini giovanni-guidini requested a review from a team September 3, 2024 18:12
@codecov-notifications
Copy link

codecov-notifications bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 91.52542% with 5 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files Patch % Lines
tasks/notify.py 81.81% 4 Missing ⚠️
services/comparison/__init__.py 92.30% 1 Missing ⚠️

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #679    +/-   ##
========================================
  Coverage   98.06%   98.07%            
========================================
  Files         434      433     -1     
  Lines       36626    36759   +133     
========================================
+ Hits        35919    36051   +132     
- Misses        707      708     +1     
Flag Coverage Δ
integration 98.07% <91.52%> (+<0.01%) ⬆️
latest-uploader-overall 98.07% <91.52%> (+<0.01%) ⬆️
unit 98.07% <91.52%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 95.95% <89.58%> (+<0.01%) ⬆️
OutsideTasks 98.07% <95.45%> (+<0.01%) ⬆️
Files Coverage Δ
helpers/comparison.py 100.00% <100.00%> (ø)
services/notification/notifiers/mixins/status.py 98.21% <100.00%> (-0.02%) ⬇️
services/repository.py 96.77% <100.00%> (+0.02%) ⬆️
tasks/compute_comparison.py 100.00% <100.00%> (+0.62%) ⬆️
tasks/tests/integration/test_notify_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_notify_task.py 100.00% <100.00%> (ø)
services/comparison/__init__.py 97.10% <92.30%> (-0.30%) ⬇️
tasks/notify.py 97.23% <81.81%> (-1.48%) ⬇️

... and 23 files with indirect coverage changes

@codecov-qa
Copy link

codecov-qa bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 91.52542% with 5 lines in your changes missing coverage. Please review.

Project coverage is 98.07%. Comparing base (f8f4c0a) to head (4eb707d).
Report is 16 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tasks/notify.py 81.81% 4 Missing ⚠️
services/comparison/__init__.py 92.30% 1 Missing ⚠️

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #679    +/-   ##
========================================
  Coverage   98.06%   98.07%            
========================================
  Files         434      433     -1     
  Lines       36626    36759   +133     
========================================
+ Hits        35919    36051   +132     
- Misses        707      708     +1     
Flag Coverage Δ
integration 98.07% <91.52%> (+<0.01%) ⬆️
latest-uploader-overall 98.07% <91.52%> (+<0.01%) ⬆️
unit 98.07% <91.52%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 95.95% <89.58%> (+<0.01%) ⬆️
OutsideTasks 98.07% <95.45%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
helpers/comparison.py 100.00% <100.00%> (ø)
services/notification/notifiers/mixins/status.py 98.21% <100.00%> (-0.02%) ⬇️
services/repository.py 96.77% <100.00%> (+0.02%) ⬆️
tasks/compute_comparison.py 100.00% <100.00%> (+0.62%) ⬆️
tasks/tests/integration/test_notify_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_notify_task.py 100.00% <100.00%> (ø)
services/comparison/__init__.py 97.10% <92.30%> (-0.30%) ⬇️
tasks/notify.py 97.23% <81.81%> (-1.48%) ⬇️

... and 23 files with indirect coverage changes

Copy link

codecov-public-qa bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 91.52542% with 5 lines in your changes missing coverage. Please review.

Project coverage is 98.07%. Comparing base (f8f4c0a) to head (4eb707d).
Report is 14 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff            @@
##             main     #679    +/-   ##
========================================
  Coverage   98.06%   98.07%            
========================================
  Files         434      433     -1     
  Lines       36626    36759   +133     
========================================
+ Hits        35919    36051   +132     
- Misses        707      708     +1     
Flag Coverage Δ
integration 98.07% <91.52%> (+<0.01%) ⬆️
latest-uploader-overall 98.07% <91.52%> (+<0.01%) ⬆️
unit 98.07% <91.52%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 95.95% <89.58%> (+<0.01%) ⬆️
OutsideTasks 98.07% <95.45%> (+<0.01%) ⬆️
Files Coverage Δ
helpers/comparison.py 100.00% <100.00%> (ø)
services/notification/notifiers/mixins/status.py 98.21% <100.00%> (-0.02%) ⬇️
services/repository.py 96.77% <100.00%> (+0.02%) ⬆️
tasks/compute_comparison.py 100.00% <100.00%> (+0.62%) ⬆️
tasks/tests/integration/test_notify_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_notify_task.py 100.00% <100.00%> (ø)
services/comparison/__init__.py 97.10% <92.30%> (-0.30%) ⬇️
tasks/notify.py 97.23% <81.81%> (-1.48%) ⬇️

... and 23 files with indirect coverage changes

Copy link

codecov bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 91.52542% with 5 lines in your changes missing coverage. Please review.

Project coverage is 98.13%. Comparing base (f8f4c0a) to head (4eb707d).
Report is 16 commits behind head on main.

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

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tasks/notify.py Critical 81.81% 4 Missing ⚠️
services/comparison/__init__.py 92.30% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #679      +/-   ##
==========================================
+ Coverage   98.11%   98.13%   +0.02%     
==========================================
  Files         474      475       +1     
  Lines       37952    38655     +703     
==========================================
+ Hits        37237    37936     +699     
- Misses        715      719       +4     
Flag Coverage Δ
integration 98.07% <91.52%> (+<0.01%) ⬆️
latest-uploader-overall 98.07% <91.52%> (+<0.01%) ⬆️
unit 98.07% <91.52%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 96.10% <89.58%> (+0.04%) ⬆️
OutsideTasks 98.07% <95.45%> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
helpers/comparison.py 100.00% <100.00%> (ø)
services/notification/notifiers/mixins/status.py 99.40% <100.00%> (-0.01%) ⬇️
services/repository.py Critical 96.77% <100.00%> (+0.02%) ⬆️
tasks/compute_comparison.py 100.00% <100.00%> (+0.62%) ⬆️
tasks/tests/integration/test_notify_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_notify_task.py 100.00% <100.00%> (ø)
services/comparison/__init__.py 97.11% <92.30%> (-0.30%) ⬇️
tasks/notify.py Critical 97.23% <81.81%> (-1.48%) ⬇️

... and 23 files with indirect coverage changes

Related Entrypoints
run/app.tasks.notify.Notify
run/app.tasks.compute_comparison.ComputeComparison

Copy link
Contributor

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

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

i think this is good? i feel weird about save_patch_totals() using the project coverage base, but i don't think there is a patch coverage base field on the model. and i don't think we expect there to be multiple CommitComparisons with the same head and project base but different patch base. so i think the logic is right?

tasks/notify.py Outdated
Comment on lines 523 to 526
if comparison.project_coverage_base.commit is None:
# This is the base that will be saved in the CommitComparison
# Even if the patch coverage could come from a different commit
return
Copy link
Contributor

Choose a reason for hiding this comment

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

in other words, we identify a CommitComparison by its project coverage base irrespective of whether its patch coverage base is different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's right... but this was a good callout.
The Comparison is created by the UploadFinisher task here. I thought that Pull.compared_to was the project base. But maybe that's not the case... I'll review before merging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tracking the code to this (where we decide what is the base_commit for the comparison) it seems that it's always the project base, unless there is no pull, then we use the commit's parent

So I guess the logic is fine. If we have a project base we would have created a comparison. Otherwise there is no Pull object and so there's no Comparison.

But this also means we might emit patch coverage in the UI 🤔
Should we then get_or_create a comparison instead of only updating if it exists... it might be a better idea

@matt-codecov
Copy link
Contributor

i think codecov/engineering-team#884 describes a different approach for the same problem. so it can be closed, but take a peek at the sync_pull task stuff it describes first to see if that's a place you could be reading your cached patch totals instead of recomputing them

@giovanni-guidini giovanni-guidini added this pull request to the merge queue Sep 5, 2024
Merged via the queue into main with commit c1fddb7 Sep 5, 2024
23 of 27 checks passed
@giovanni-guidini giovanni-guidini deleted the gio/notify-save-patch branch September 5, 2024 15:25
Copy link

sentry-io bot commented Sep 6, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ JSONDecodeError: Expecting value: line 1 column 1 (char 0) app.tasks.compute_comparison.ComputeComparison View Issue
  • ‼️ TorngitServerUnreachableError: GitHub was not able to be reached. app.tasks.notify.Notify View Issue
  • ‼️ JSONDecodeError: Expecting value: line 1 column 1 (char 0) app.tasks.notify.Notify View Issue
  • ‼️ TypeError: string indices must be integers, not 'str' app.tasks.notify.Notify View Issue

Did you find this useful? React with a 👍 or 👎

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