Skip to content

Commit eea762c

Browse files

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

src/sentry/utils/snuba.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from snuba_sdk.legacy import json_to_snql
2828
from snuba_sdk.query import SelectableExpression
2929

30-
from sentry import options
3130
from sentry.api.helpers.error_upsampling import (
3231
UPSAMPLED_ERROR_AGGREGATION,
3332
are_any_projects_error_upsampled,
@@ -1256,34 +1255,33 @@ def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet:
12561255
if body.get("error"):
12571256
error = body["error"]
12581257
if response.status == 429:
1259-
if options.get("issues.use-snuba-error-data"):
1260-
try:
1261-
if (
1262-
"quota_allowance" not in body
1263-
or "summary" not in body["quota_allowance"]
1264-
):
1265-
# Should not hit this - snuba gives us quota_allowance with a 429
1266-
raise RateLimitExceeded(error["message"])
1267-
quota_allowance_summary = body["quota_allowance"]["summary"]
1268-
rejected_by = quota_allowance_summary["rejected_by"]
1269-
throttled_by = quota_allowance_summary["throttled_by"]
1270-
1271-
policy_info = rejected_by or throttled_by
1272-
1273-
if policy_info:
1274-
raise RateLimitExceeded(
1275-
error["message"],
1276-
policy=policy_info["policy"],
1277-
quota_unit=policy_info["quota_unit"],
1278-
storage_key=policy_info["storage_key"],
1279-
quota_used=policy_info["quota_used"],
1280-
rejection_threshold=policy_info["rejection_threshold"],
1281-
)
1282-
except KeyError:
1283-
logger.warning(
1284-
"Failed to parse rate limit error details from Snuba response",
1285-
extra={"error": error["message"]},
1258+
try:
1259+
if (
1260+
"quota_allowance" not in body
1261+
or "summary" not in body["quota_allowance"]
1262+
):
1263+
# Should not hit this - snuba gives us quota_allowance with a 429
1264+
raise RateLimitExceeded(error["message"])
1265+
quota_allowance_summary = body["quota_allowance"]["summary"]
1266+
rejected_by = quota_allowance_summary["rejected_by"]
1267+
throttled_by = quota_allowance_summary["throttled_by"]
1268+
1269+
policy_info = rejected_by or throttled_by
1270+
1271+
if policy_info:
1272+
raise RateLimitExceeded(
1273+
error["message"],
1274+
policy=policy_info["policy"],
1275+
quota_unit=policy_info["quota_unit"],
1276+
storage_key=policy_info["storage_key"],
1277+
quota_used=policy_info["quota_used"],
1278+
rejection_threshold=policy_info["rejection_threshold"],
12861279
)
1280+
except KeyError:
1281+
logger.warning(
1282+
"Failed to parse rate limit error details from Snuba response",
1283+
extra={"error": error["message"]},
1284+
)
12871285

12881286
raise RateLimitExceeded(error["message"])
12891287

tests/sentry/utils/test_snuba.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from sentry.models.release import Release
1515
from sentry.snuba.dataset import Dataset
1616
from sentry.testutils.cases import TestCase
17-
from sentry.testutils.helpers import override_options
1817
from sentry.utils import json
1918
from sentry.utils.snuba import (
2019
ROUND_UP,
@@ -475,7 +474,6 @@ def setUp(self):
475474
)
476475

477476
@mock.patch("sentry.utils.snuba._snuba_query")
478-
@override_options({"issues.use-snuba-error-data": 1.0})
479477
def test_rate_limit_error_handling(self, mock_snuba_query) -> None:
480478
"""
481479
Test error handling for rate limit errors creates a RateLimitExceeded exception
@@ -515,7 +513,6 @@ def test_rate_limit_error_handling(self, mock_snuba_query) -> None:
515513
)
516514

517515
@mock.patch("sentry.utils.snuba._snuba_query")
518-
@override_options({"issues.use-snuba-error-data": 1.0})
519516
def test_rate_limit_error_handling_without_quota_details(self, mock_snuba_query) -> None:
520517
"""
521518
Test that error handling gracefully handles malformed message
@@ -542,7 +539,6 @@ def test_rate_limit_error_handling_without_quota_details(self, mock_snuba_query)
542539
)
543540

544541
@mock.patch("sentry.utils.snuba._snuba_query")
545-
@override_options({"issues.use-snuba-error-data": 1.0})
546542
def test_rate_limit_error_handling_with_stats_but_no_quota_details(
547543
self, mock_snuba_query
548544
) -> None:

0 commit comments

Comments
 (0)