Skip to content

Update sentry_app queries to use the read replica #93081

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kneeyo1
Copy link
Contributor

@kneeyo1 kneeyo1 commented Jun 6, 2025

WIP. need to double check these are safe operations

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 6, 2025
Copy link

codecov bot commented Jun 6, 2025

❌ 305 Tests Failed:

Tests completed Failed Passed Skipped
26349 305 26044 211
View the top 3 failed test(s) by shortest run time
tests.sentry.incidents.endpoints.test_serializers.TestAlertRuleSerializer::test_enforce_max_subscriptions
Stack Traces | 1.25s run time
#x1B[1m#x1B[.../incidents/endpoints/test_serializers.py#x1B[0m:789: in test_enforce_max_subscriptions
    serializer = AlertRuleSerializer(context=self.context, data=self.valid_params)
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/functools.py#x1B[0m:1039: in __get__
    val = self.func(instance)
#x1B[1m#x1B[.../incidents/endpoints/test_serializers.py#x1B[0m:123: in context
    "installations": app_service.installations_for_organization(
#x1B[1m#x1B[.../services/app/service.py#x1B[0m:71: in installations_for_organization
    return get_installations_for_organization(organization_id)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:148: in __call__
    return self.get_results(object_id)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:182: in get_results
    return _consume_generator(self.resolve_from(object_id, values))
#x1B[1m#x1B[.../rpc/caching/impl.py#x1B[0m:24: in _consume_generator
    g.send(None)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:171: in resolve_from
    result = self.cb(object_id)
#x1B[1m#x1B[.../services/app/service.py#x1B[0m:246: in get_installations_for_organization
    return app_service.get_installations_for_organization(organization_id=organization_id)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:354: in remote_method
    return dispatch_remote_call(
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:476: in dispatch_remote_call
    return remote_silo_call.dispatch(use_test_client)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:511: in dispatch
    serial_response = self._send_to_remote_silo(use_test_client)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:582: in _send_to_remote_silo
    self._raise_from_response_status_error(response)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:605: in _raise_from_response_status_error
    raise self._remote_exception(
#x1B[1m#x1B[31mE   sentry.hybridcloud.rpc.service.RpcRemoteException: app.get_installations_for_organization: Error invoking rpc at '.../rpc/app/get_installations_for_organization/': check error logs for more details#x1B[0m
tests.sentry.incidents.endpoints.test_serializers.TestAlertRuleSerializer::test_validation_no_params
Stack Traces | 1.47s run time
#x1B[1m#x1B[.../incidents/endpoints/test_serializers.py#x1B[0m:139: in test_validation_no_params
    serializer = AlertRuleSerializer(context=self.context, data={})
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/functools.py#x1B[0m:1039: in __get__
    val = self.func(instance)
#x1B[1m#x1B[.../incidents/endpoints/test_serializers.py#x1B[0m:123: in context
    "installations": app_service.installations_for_organization(
#x1B[1m#x1B[.../services/app/service.py#x1B[0m:71: in installations_for_organization
    return get_installations_for_organization(organization_id)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:148: in __call__
    return self.get_results(object_id)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:182: in get_results
    return _consume_generator(self.resolve_from(object_id, values))
#x1B[1m#x1B[.../rpc/caching/impl.py#x1B[0m:24: in _consume_generator
    g.send(None)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:171: in resolve_from
    result = self.cb(object_id)
#x1B[1m#x1B[.../services/app/service.py#x1B[0m:246: in get_installations_for_organization
    return app_service.get_installations_for_organization(organization_id=organization_id)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:354: in remote_method
    return dispatch_remote_call(
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:476: in dispatch_remote_call
    return remote_silo_call.dispatch(use_test_client)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:511: in dispatch
    serial_response = self._send_to_remote_silo(use_test_client)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:582: in _send_to_remote_silo
    self._raise_from_response_status_error(response)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:605: in _raise_from_response_status_error
    raise self._remote_exception(
#x1B[1m#x1B[31mE   sentry.hybridcloud.rpc.service.RpcRemoteException: app.get_installations_for_organization: Error invoking rpc at '.../rpc/app/get_installations_for_organization/': check error logs for more details#x1B[0m
tests.sentry.incidents.endpoints.test_serializers.TestAlertRuleSerializer::test_transaction_dataset
Stack Traces | 1.54s run time
#x1B[1m#x1B[.../incidents/endpoints/test_serializers.py#x1B[0m:287: in test_transaction_dataset
    serializer = AlertRuleSerializer(context=self.context, data=self.valid_transaction_params)
#x1B[1m#x1B[.../hostedtoolcache/Python/3.13.1.../x64/lib/python3.13/functools.py#x1B[0m:1039: in __get__
    val = self.func(instance)
#x1B[1m#x1B[.../incidents/endpoints/test_serializers.py#x1B[0m:123: in context
    "installations": app_service.installations_for_organization(
#x1B[1m#x1B[.../services/app/service.py#x1B[0m:71: in installations_for_organization
    return get_installations_for_organization(organization_id)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:148: in __call__
    return self.get_results(object_id)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:182: in get_results
    return _consume_generator(self.resolve_from(object_id, values))
#x1B[1m#x1B[.../rpc/caching/impl.py#x1B[0m:24: in _consume_generator
    g.send(None)
#x1B[1m#x1B[.../rpc/caching/service.py#x1B[0m:171: in resolve_from
    result = self.cb(object_id)
#x1B[1m#x1B[.../services/app/service.py#x1B[0m:246: in get_installations_for_organization
    return app_service.get_installations_for_organization(organization_id=organization_id)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:354: in remote_method
    return dispatch_remote_call(
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:476: in dispatch_remote_call
    return remote_silo_call.dispatch(use_test_client)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:511: in dispatch
    serial_response = self._send_to_remote_silo(use_test_client)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:582: in _send_to_remote_silo
    self._raise_from_response_status_error(response)
#x1B[1m#x1B[.../hybridcloud/rpc/service.py#x1B[0m:605: in _raise_from_response_status_error
    raise self._remote_exception(
#x1B[1m#x1B[31mE   sentry.hybridcloud.rpc.service.RpcRemoteException: app.get_installations_for_organization: Error invoking rpc at '.../rpc/app/get_installations_for_organization/': check error logs for more details#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Comment on lines 67 to +69
def get_sentry_app_by_id(self, *, id: int) -> RpcSentryApp | None:
try:
sentry_app = SentryApp.objects.get(id=id)
sentry_app = SentryApp.objects.using_replica().get(id=id)
Copy link
Member

Choose a reason for hiding this comment

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

Have you considered using get_from_cache() on these id reads? It might be possible to get a good cache hit rate on these and skip postgres entirely most of the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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