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: use original PR base to compute patch coverage #199

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

matt-codecov
Copy link
Contributor

codecov/engineering-team#814

this code could use some cleanup one day but this is a minimal change to remove unnecessary inaccuracy from patch coverage

currently for both patch coverage and project coverage deltas we compare the PR head's report against the base, or if the base isn't in our database, the next-oldest commit (the "adjusted base"). that's necessary for project coverage, it's unnecessary (and problematic) for patch coverage

this PR:

  • saves original_base_commitid in the Comparison object
    • in places where we can't access the PR we just assume the original is the same as the adjusted base
  • adds use_original_base switch to ComparisonProxy.get_diff()
  • add use_original_base=True to calls to get_diff() in the notification service
    • services/notification/notifiers/mixins/status.py: context is explicitly patch-coverage-related
    • services/notification/notifiers/checks/patch.py: explicitly a patch-coverage check
    • services/notification/notifiers/mixins/message/__init__.py: the diff computed here is plumbed through all of the various comment section implementations. afaict the only usages of it are patch-coverage-related, so changing the top of the funnel shouldn't impact anything else

extra notes

  • afaict tasks/save_report_results.py is dead code
  • tasks/sync_pull.py computes patch coverage against the correct base and saves it to pull.diff in the database! but then afaict nothing ever reads from it (link)
  • tasks/upload_processor.py computes patch coverage for just the current commit (not compared to the PR base) but doesn't do anything with it
    • internally, the Report model will use it to update ReportFileSummary.diff_totals for each file in the report, and that gets saved in network_file_json() or whatever it's called and then rehydrated. but after a quick scan i couldn't find anything that tries to read this field
  • the reason we adjust the base is because we want the base to have a report, but we never actually check for it. maybe we can't/don't check for it because we're hoping by the time we get to sending notifications the report is there?
  • i am leaving tasks/compute_comparison.py alone
  • pull.base is the real base and pull.compared_to is the adjusted base, but everywhere else they use base to refer to the adjusted base so i had to call the real base original_base

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.

@codecov-qa
Copy link

codecov-qa bot commented Dec 2, 2023

Codecov Report

Merging #199 (ce4ac0b) into main (82832af) will decrease coverage by 0.01%.
The diff coverage is 98.18%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #199      +/-   ##
==========================================
- Coverage   98.35%   98.34%   -0.01%     
==========================================
  Files         353      354       +1     
  Lines       27844    27934      +90     
==========================================
+ Hits        27386    27473      +87     
- Misses        458      461       +3     
Flag Coverage Δ
integration 98.34% <98.18%> (-0.01%) ⬇️
latest-uploader-overall 98.34% <98.18%> (-0.01%) ⬇️
unit 98.34% <98.18%> (-0.01%) ⬇️

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

Components Coverage Δ
NonTestCode 96.79% <95.55%> (-0.02%) ⬇️
OutsideTasks 98.15% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/comparison/__init__.py 96.59% <100.00%> (-0.29%) ⬇️
services/comparison/conftest.py 100.00% <ø> (ø)
...ces/comparison/tests/unit/test_comparison_proxy.py 100.00% <100.00%> (ø)
services/comparison/types.py 100.00% <100.00%> (ø)
services/notification/notifiers/checks/base.py 98.20% <ø> (-0.03%) ⬇️
services/notification/notifiers/checks/patch.py 100.00% <100.00%> (ø)
.../notification/notifiers/mixins/message/__init__.py 100.00% <100.00%> (ø)
services/notification/notifiers/mixins/status.py 99.37% <100.00%> (ø)
services/notification/notifiers/status/base.py 98.64% <ø> (-0.02%) ⬇️
services/notification/notifiers/tests/conftest.py 100.00% <ø> (ø)
... and 7 more

Copy link

codecov bot commented Dec 2, 2023

Codecov Report

Merging #199 (ce4ac0b) into main (82832af) will decrease coverage by 0.01%.
The diff coverage is 98.18%.

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

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #199      +/-   ##
==========================================
- Coverage   98.31%   98.31%   -0.01%     
==========================================
  Files         382      383       +1     
  Lines       28489    28579      +90     
==========================================
+ Hits        28010    28097      +87     
- Misses        479      482       +3     
Flag Coverage Δ
integration 98.34% <98.18%> (-0.01%) ⬇️
latest-uploader-overall 98.34% <98.18%> (-0.01%) ⬇️
onlysomelabels 98.31% <98.18%> (-0.01%) ⬇️
unit 98.34% <98.18%> (-0.01%) ⬇️

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

Components Coverage Δ
NonTestCode 96.67% <95.55%> (-0.02%) ⬇️
OutsideTasks 98.15% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/comparison/__init__.py Critical 96.61% <100.00%> (-0.29%) ⬇️
services/comparison/conftest.py 100.00% <ø> (ø)
...ces/comparison/tests/unit/test_comparison_proxy.py 100.00% <100.00%> (ø)
services/comparison/types.py 100.00% <100.00%> (ø)
services/notification/notifiers/checks/base.py 98.20% <ø> (-0.03%) ⬇️
services/notification/notifiers/checks/patch.py 100.00% <100.00%> (ø)
.../notification/notifiers/mixins/message/__init__.py 100.00% <100.00%> (ø)
services/notification/notifiers/mixins/status.py 99.37% <100.00%> (ø)
services/notification/notifiers/status/base.py 98.64% <ø> (-0.02%) ⬇️
services/notification/notifiers/tests/conftest.py 100.00% <ø> (ø)
... and 7 more
Related Entrypoints
run/app.tasks.compute_comparison.ComputeComparison
run/app.tasks.notify.Notify

Copy link
Contributor

@giovanni-guidini giovanni-guidini left a comment

Choose a reason for hiding this comment

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

LGTM

# To see how a patch changes project coverage, we compare the branch head's
# report against the base's report, or if the base isn't in our database,
# the next-oldest commit that is. Be aware that this base commit may not be
# the true base that, for example, a PR is based on.
base: FullCommit
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if using project_coverage_base and patch_coverage_base would be better names from an understanding perspective.

Although the comments do a good job of explaining the difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh you're right those are much better names. i tried renaming base to adjusted_base and it was a very messy rename so i backed out since merging this was a priority, but i assigned myself a GH issue to rename the fields with your suggested names when i get a spare minute #203

@matt-codecov matt-codecov merged commit a404e8e into main Dec 5, 2023
15 of 21 checks passed
@matt-codecov matt-codecov deleted the matt/patch-coverage-original-base branch December 5, 2023 03:06
scott-codecov added a commit that referenced this pull request Dec 6, 2023
* main:
  Only trigger AI PR review if pull is open
  Add log line when triggering AI PR review task
  fix: use original PR base to compute patch coverage (#199)
  Prepare release 23.12.4
  Update workflows
  chore(deps): Update codecov-shared dependency (#194)
  Prep the terrain for reports with label compression. (#188)
  allow staging deploy when pushing to staging (#192)
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