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: don't eager merge sessions into report #336

Merged
merged 2 commits into from
Mar 18, 2024

Conversation

giovanni-guidini
Copy link
Contributor

context: https://l.codecov.dev/xvGZaM

Because we eagerly merge sessions when processing a report the following scenario can happen:

  1. You upload an empty report with a flag set to carryforward
  2. There will be a new session for that upload (even though it's empty)
  3. In the next commit the session will be carried forward

If no real upload was made to clean up old carriedforward sessions from empty uploads
they would accumulate in the report (because _adjust_sessions only runs after the
processing is done, and doesn't run if it's an empty upload). What prompted this
investigation is that a customer was fund with thousands of carryforward session in
some of their commits.

So I'm exploiting the fact that merges into the report need to be made from within a lock
and getting the ID for the session without actually adding it to the original report.

If the report is successful we add it and run _adjust_sessions. If the report was empty,
we just never add it to the report, as if it didn't existed.

OBS.: Even though I use the litle exploit I believe that passing the sessionid to
ReportBuilder is unecessary. We can likely not get a sessionid at all when processin the report
and it would still work. I decided to leave this for it's own change tho.

Also I decided to bump the severity of the messages that indicate a report is empty.
Users are not expected to upload empty reports, so it's at least sensible it should be
a warning.

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.

context: https://l.codecov.dev/xvGZaM

Because we eagerly merge sessions when processing a report the following scenario can happen:
1. You upload an empty report with a flag set to carryforward
2. There will be a new session for that upload (even though it's empty)
3. In the next commit the session will be carried forward

If no real upload was made to clean up old carriedforward sessions from empty uploads
they would accumulate in the report (because `_adjust_sessions` only runs *after* the
processing is done, and *doesn't run* if it's an empty upload). What prompted this
investigation is that a customer was fund with thousands of carryforward session in
some of their commits.

So I'm exploiting the fact that merges into the report need to be made from within a lock
and getting the ID for the session _without_ actually adding it to the original report.

If the report is successful we add it and run `_adjust_sessions`. If the report was empty,
we just never add it to the report, as if it didn't existed.

OBS.: Even though I use the litle exploit I believe that passing the `sessionid` to
`ReportBuilder` is unecessary. We can likely not get a sessionid at all when processin the report
and it would still work. I decided to leave this for it's own change tho.

Also I decided to bump the severity of the messages that indicate a report is empty.
Users are not expected to upload empty reports, so it's at least sensible it should be
a warning.
@giovanni-guidini
Copy link
Contributor Author

PS about tests changed in this PR:

I started by creating a new test to verify the behavior observed on the investigation could be reproduced.
In fixing it the other test - that showed what happens when you upload an empty report - broke. It was left there so we wouldn't accidentally break this behavior (thanks Thiago for thinking forward like that 🙏 )

As I am not breaking the behavior accidentally, but very much intentionally, I altered the test to match the new behavior. And left my test too because it was there at this point 😅

@giovanni-guidini giovanni-guidini requested a review from a team March 18, 2024 15:18
@codecov-staging
Copy link

codecov-staging bot commented Mar 18, 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     #336   +/-   ##
=======================================
  Coverage   98.11%   98.11%           
=======================================
  Files         385      385           
  Lines       31988    32006   +18     
=======================================
+ Hits        31385    31403   +18     
  Misses        603      603           
Flag Coverage Δ
integration ?
latest-uploader-overall 98.11% <100.00%> (+<0.01%) ⬆️
unit 98.11% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 96.22% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.91% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/report/__init__.py 97.77% <100.00%> (ø)
services/report/raw_upload_processor.py 94.41% <100.00%> (+0.05%) ⬆️
services/report/report_processor.py 93.84% <100.00%> (ø)
services/report/tests/unit/test_process.py 99.04% <100.00%> (+0.05%) ⬆️

@codecov-qa
Copy link

codecov-qa bot commented Mar 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.11%. Comparing base (97ce1f7) to head (7bba05f).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #336   +/-   ##
=======================================
  Coverage   98.11%   98.11%           
=======================================
  Files         385      385           
  Lines       31988    32006   +18     
=======================================
+ Hits        31385    31403   +18     
  Misses        603      603           
Flag Coverage Δ
integration ?
latest-uploader-overall 98.11% <100.00%> (+<0.01%) ⬆️
unit ?

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

Components Coverage Δ
NonTestCode 96.22% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.91% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/report/__init__.py 97.77% <100.00%> (ø)
services/report/raw_upload_processor.py 94.41% <100.00%> (+0.05%) ⬆️
services/report/report_processor.py 93.84% <100.00%> (ø)
services/report/tests/unit/test_process.py 99.04% <100.00%> (+0.05%) ⬆️

Copy link

codecov-public-qa bot commented Mar 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (97ce1f7) 98.11% compared to head (7bba05f) 98.11%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #336   +/-   ##
=======================================
  Coverage   98.11%   98.11%           
=======================================
  Files         385      385           
  Lines       31988    32006   +18     
=======================================
+ Hits        31385    31403   +18     
  Misses        603      603           
Flag Coverage Δ
integration 98.11% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 98.11% <100.00%> (+<0.01%) ⬆️
unit 98.11% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 96.22% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.91% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/report/__init__.py 97.77% <100.00%> (ø)
services/report/raw_upload_processor.py 94.41% <100.00%> (+0.05%) ⬆️
services/report/report_processor.py 93.84% <100.00%> (ø)
services/report/tests/unit/test_process.py 99.04% <100.00%> (+0.05%) ⬆️

Copy link

codecov bot commented Mar 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.10%. Comparing base (97ce1f7) to head (22be527).

❗ Current head 22be527 differs from pull request most recent head 7bba05f. Consider uploading reports for the commit 7bba05f to get more accurate results

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

✅ All tests successful. No failed tests found ☺️

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #336   +/-   ##
=======================================
  Coverage   98.10%   98.10%           
=======================================
  Files         416      416           
  Lines       32688    32706   +18     
=======================================
+ Hits        32069    32087   +18     
  Misses        619      619           
Flag Coverage Δ
integration 98.11% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 98.11% <100.00%> (+<0.01%) ⬆️
unit 98.11% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 96.17% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.91% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/report/__init__.py Critical 97.77% <100.00%> (ø)
services/report/raw_upload_processor.py 94.41% <100.00%> (+0.05%) ⬆️
services/report/report_processor.py 93.84% <100.00%> (ø)
services/report/tests/unit/test_process.py 99.04% <100.00%> (+0.05%) ⬆️

... and 1 file with indirect coverage changes

Related Entrypoints
run/app.tasks.upload.UploadProcessor

"""
original_report = self._generate_sample_report()
original_sessions = original_report.sessions
expected_sessions = {
Copy link
Contributor

Choose a reason for hiding this comment

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

In the previous behaviour, would we have seen 3 sessions instead of 2 here, with two of them being for the flag "somethingold"?

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. You can see a similar behavior in the test I altered. The removed parts are the outcome of the old behavior, where an extra session would be present.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah I see now, thanks for pointing that out

@giovanni-guidini giovanni-guidini requested review from joseph-sentry and a team March 18, 2024 17:08
Copy link
Contributor

@joseph-sentry joseph-sentry left a comment

Choose a reason for hiding this comment

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

lgtm

@giovanni-guidini giovanni-guidini merged commit 77e34ba into main Mar 18, 2024
23 checks passed
@giovanni-guidini giovanni-guidini deleted the gio/dont-eager-merge-session branch March 18, 2024 17:21
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