codecov / codecov-api

Code for the API of Codecov
Other
216 stars 30 forks source link

fix: Resolve race condition when resolving measurements #828

Closed ajay-sentry closed 1 month ago

ajay-sentry commented 1 month ago

Purpose/Motivation

This PR aims to fix these two Sentry issues: https://codecov.sentry.io/issues/3984451805 https://codecov.sentry.io/issues/3984451718

where we're trying to resolve measurements on the repository object but there is a race condition that exists where calling create may result in a duplicate key value (race condition)

The fix was to change the create to a get_or_Create and add some conditional logic to only backfill if the function returns "true" for created

Links to relevant tickets

Closes https://github.com/codecov/engineering-team/issues/2525

Notes to Reviewer

Anything to note to the team? Any tips on how to review, or where to start?

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-notifications[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

:white_check_mark: All tests successful. No failed tests found.

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.29%. Comparing base (ff2e8dd) to head (478f27f). Report is 14 commits behind head on main.

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

:white_check_mark: All tests successful. No failed tests found.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #828 +/- ## ================================================ + Coverage 96.22000 96.29000 +0.07000 ================================================ Files 812 812 Lines 18529 18941 +412 ================================================ + Hits 17830 18240 +410 - Misses 699 701 +2 ``` | [Flag](https://app.codecov.io/gh/codecov/codecov-api/pull/828/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=codecov) | Coverage Δ | | |---|---|---| | [unit](https://app.codecov.io/gh/codecov/codecov-api/pull/828/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=codecov) | `92.46% <100.00%> (+0.38%)` | :arrow_up: | | [unit-latest-uploader](https://app.codecov.io/gh/codecov/codecov-api/pull/828/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=codecov) | `92.46% <100.00%> (+0.38%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=codecov#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.