-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
chore(hybridcloud) Remove role switching and update guard method #52673
Conversation
- Add guards for deletes on hybridcloudforeignkey models. - Remove role creation/permisission setting. - Add unguarded_write() context manager that emits fencing queries. - Make in_test_psql_role_override an alias to unguarded_write
_fencing_counters: MutableMapping[str, int] = defaultdict(int) | ||
|
||
|
||
@contextlib.contextmanager | ||
def in_test_psql_role_override(role_name: str, using: str | None = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be around for a bit longer until I can update getsentry.
@@ -94,6 +93,8 @@ def increment_project_counter(project, delta=1, using="default"): | |||
# this must be idempotent because it seems to execute twice | |||
# (at least during test runs) | |||
def create_counter_function(app_config, using, **kwargs): | |||
from sentry.testutils.silo import unguarded_write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circular import sadness.
src/sentry/testutils/asserts.py
Outdated
@@ -1,7 +1,5 @@ | |||
from typing import Optional | |||
|
|||
from sentry.models import AuditLogEntry, CommitFileChange |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More circular import sadness.
src/sentry/testutils/silo.py
Outdated
|
||
@contextlib.contextmanager | ||
def unguarded_write(using: str | None = None, *args: Any, **kwargs: Any): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 💯 sold on this name, and welcome any suggestions to improve it.
seen_models: MutableSet[type] = set() | ||
for app_config in apps.get_app_configs(): | ||
for model in iter_models(app_config.name): | ||
for field in model._meta.fields: | ||
if not isinstance(field, HybridCloudForeignKey): | ||
continue | ||
fk_model = field.foreign_model | ||
if fk_model is None or fk_model in seen_models: | ||
continue | ||
seen_models.add(fk_model) | ||
_protected_operations.append(protected_table(fk_model._meta.db_table, "delete")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed adding these guards in the initial pass, but noticed these were missing when removing the role based methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should also be a test, somewhere, I wrote that fails if a raw deletion succeeds without throwing an exception.
@@ -10,14 +7,6 @@ | |||
|
|||
@control_silo_test(stable=True) | |||
class IntegrationTest(TestCase): | |||
def test_cannot_delete_with_queryset(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests had to be removed as they now throw during teardown which we can't catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some alternative that ensures atleast that this logic does exist?
src/sentry/db/postgres/roles.py
Outdated
# TODO(mark) Move this closer to other silo code. | ||
_fencing_counters[using] += 1 | ||
# Deprecated shim for getsentry compatibility | ||
from sentry.testutils.silo import unguarded_write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need the using = determine_using_by_silo_mode
logic for split db still?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, it is captured inside the call.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #52673 +/- ##
==========================================
+ Coverage 77.54% 79.39% +1.84%
==========================================
Files 4921 4922 +1
Lines 206673 206698 +25
Branches 35331 35340 +9
==========================================
+ Hits 160264 164100 +3836
+ Misses 41347 37573 -3774
+ Partials 5062 5025 -37
|
I'm having a hard time getting #52673 to pass CI because of getsentry dependencies. These changes add the new helpers to adopt query auditing instead of role swapping without touching role. My plan now is to get these changes merged, then update getsentry to use query auditing and then update sentry and remove role swapping.
I'm having a hard time getting #52673 to pass CI because of getsentry dependencies. These changes add the new helpers to adopt query auditing instead of role swapping without touching role. My plan now is to get these changes merged, then update getsentry to use query auditing and then update sentry and remove role swapping.
PR reverted: ace3ab5 |
Mulligan on #52673 as using testutils code in application code blows up docker image generation. Because of that I've moved unguarded_write to sentry.silo instead.
) The role switching logic to catch write operations that are missing outboxes has been causing test flakiness and disrupting development workflows. These changes finish replacing role switching with query auditing that is done during test teardown. Switching to a teardown based audit means we can't give the precise location of where the bad operation was as the stack frames have been lost. However, we are able to show the offending query and its location in the SQL logs for a test.
) The role switching logic to catch write operations that are missing outboxes has been causing test flakiness and disrupting development workflows. These changes finish replacing role switching with query auditing that is done during test teardown. Switching to a teardown based audit means we can't give the precise location of where the bad operation was as the stack frames have been lost. However, we are able to show the offending query and its location in the SQL logs for a test.
The role switching logic to catch write operations that are missing outboxes has been causing test flakiness and disrupting development workflows.
These changes finish replacing role switching with query auditing that is done during test teardown. Switching to a teardown based audit means we can't give the precise location of where the bad operation was as the stack frames have been lost. However, we are able to show the offending query and its location in the SQL logs for a test.