Skip to content

fix(hybrid-cloud): Cross-DB tombstone resubmission #69814

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

Merged
merged 7 commits into from
Apr 30, 2024

Conversation

GabeVillalobos
Copy link
Member

@GabeVillalobos GabeVillalobos commented Apr 26, 2024

Resubmission of PR #69480 with added support for row watermarking, which covers the case when a row is created after the relevant tombstone is already processed.

To make this behavior easier to test, I've split the convenience helper method that queries for model IDs requiring cascade changes into multiple new functions that can be tested individually.

This PR also adds commented tests that assert that this watermarking behavior is working as expected. Please pay attention to both the commented and uncommented test cases when reviewing.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 26, 2024
Copy link

codecov bot commented Apr 27, 2024

Codecov Report

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

Project coverage is 79.84%. Comparing base (3597aaf) to head (c4e95e3).
Report is 102 commits behind head on master.

❗ Current head c4e95e3 differs from pull request most recent head 63c0619. Consider uploading reports for the commit 63c0619 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #69814      +/-   ##
==========================================
+ Coverage   79.14%   79.84%   +0.70%     
==========================================
  Files        6486     6488       +2     
  Lines      288272   288414     +142     
  Branches    49667    49684      +17     
==========================================
+ Hits       228139   230295    +2156     
+ Misses      59731    57717    -2014     
  Partials      402      402              
Files Coverage Δ
src/sentry/options/defaults.py 100.00% <ø> (ø)
src/sentry/tasks/deletion/hybrid_cloud.py 91.46% <89.36%> (-1.40%) ⬇️

... and 268 files with indirect coverage changes

Comment on lines 327 to 351
# @region_silo_test
# class TestCrossDatabaseTombstoneCascadeBehavior(TestCase):
# def assert_monitors_unchanged(self, unaffected_data: list[dict]):
# for u_data in unaffected_data:
# u_user, u_monitor = itemgetter("user", "monitor")(u_data)
# queried_monitor = Monitor.objects.get(id=u_monitor.id)
# # Validate that none of the existing user's monitors have been affected
# assert u_monitor.owner_user_id is not None
# assert u_monitor.owner_user_id == queried_monitor.owner_user_id
# assert u_monitor.owner_user_id == u_user.id
#
# def assert_monitors_user_ids_null(self, monitors: list[Monitor]):
# for monitor in monitors:
# monitor.refresh_from_db()
# assert monitor.owner_user_id is None
#
# def run_hybrid_cloud_fk_jobs(self):
# with override_options({"hybrid_cloud.allow_cross_db_tombstones": True}):
# with BurstTaskRunner() as burst:
# schedule_hybrid_cloud_foreign_key_jobs()
#
# burst()
#
# def test_raises_when_option_disabled(self):
# data = setup_cross_db_deletion_data()
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests actually validate the cross-DB tombstone behavior, but rely entirely on PR #69697 in order to function correctly. Unfortunately, PR #69697 is also reliant on these fixes in order to pass testing 🐔/🥚 .

Copy link
Member

Choose a reason for hiding this comment

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

Instead of checking in commented out code which can be misinterpreted as a mistake, you could use pytest.mark.skip to not run the tests but include them as well.

@GabeVillalobos GabeVillalobos marked this pull request as ready for review April 29, 2024 21:56
@GabeVillalobos GabeVillalobos requested a review from a team as a code owner April 29, 2024 21:56

object_ids_to_check = fk_to_model_id_map.keys()
tombstone_entries = tombstone_cls.objects.filter(
object_identifier__in=object_ids_to_check
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a table condition here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do, adding this and another test for this as well 🤦🏼‍♂️

Comment on lines 327 to 351
# @region_silo_test
# class TestCrossDatabaseTombstoneCascadeBehavior(TestCase):
# def assert_monitors_unchanged(self, unaffected_data: list[dict]):
# for u_data in unaffected_data:
# u_user, u_monitor = itemgetter("user", "monitor")(u_data)
# queried_monitor = Monitor.objects.get(id=u_monitor.id)
# # Validate that none of the existing user's monitors have been affected
# assert u_monitor.owner_user_id is not None
# assert u_monitor.owner_user_id == queried_monitor.owner_user_id
# assert u_monitor.owner_user_id == u_user.id
#
# def assert_monitors_user_ids_null(self, monitors: list[Monitor]):
# for monitor in monitors:
# monitor.refresh_from_db()
# assert monitor.owner_user_id is None
#
# def run_hybrid_cloud_fk_jobs(self):
# with override_options({"hybrid_cloud.allow_cross_db_tombstones": True}):
# with BurstTaskRunner() as burst:
# schedule_hybrid_cloud_foreign_key_jobs()
#
# burst()
#
# def test_raises_when_option_disabled(self):
# data = setup_cross_db_deletion_data()
Copy link
Member

Choose a reason for hiding this comment

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

Instead of checking in commented out code which can be misinterpreted as a mistake, you could use pytest.mark.skip to not run the tests but include them as well.

@GabeVillalobos GabeVillalobos merged commit 980632a into master Apr 30, 2024
48 checks passed
@GabeVillalobos GabeVillalobos deleted the gv/cross-db-tombstone-support-redux branch April 30, 2024 19:28
Copy link

sentry-io bot commented May 1, 2024

Suspect Issues

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

  • ‼️ Exception: Cannot process tombstones due to model living in separate database. sentry.tasks.deletion.process_hybrid_cloud_fore... View Issue

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

@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants