Skip to content

Commit be03c95

Browse files
xurui-cRachel Chen
andauthored
Don't emit Sentry warnings for throttled queries to Snuba (#75879)
Allocation policies are our mechanism for doing traffic management for Snuba queries. Currently, we see a lot of warnings (Warning: Query from referrer ... is throttled) on Sentry Issues. This is because these queries are throttled due to being in the "warning zone"; however, we got feedback that this isn't actually actionable, so we're getting rid of them. We will only emit Sentry *errors* for rejected queries. Co-authored-by: Rachel Chen <[email protected]>
1 parent 17195f1 commit be03c95

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/sentry/utils/snuba.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import functools
55
import logging
66
import os
7-
import random
87
import re
98
import time
109
from collections import namedtuple
@@ -1075,6 +1074,15 @@ def _apply_cache_and_build_results(
10751074
return [result[1] for result in results]
10761075

10771076

1077+
def _is_rejected_query(body: Any) -> bool:
1078+
return (
1079+
"quota_allowance" in body
1080+
and "summary" in body["quota_allowance"]
1081+
and "rejected_by" in body["quota_allowance"]["summary"]
1082+
and body["quota_allowance"]["summary"]["rejected_by"] is not None
1083+
)
1084+
1085+
10781086
def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet:
10791087
snuba_requests_list = list(snuba_requests)
10801088

@@ -1131,7 +1139,7 @@ def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet:
11311139
raise UnexpectedResponseError(f"Could not decode JSON response: {response.data!r}")
11321140

11331141
allocation_policy_prefix = "allocation_policy."
1134-
if "quota_allowance" in body and "summary" in body["quota_allowance"]:
1142+
if _is_rejected_query(body):
11351143
quota_allowance_summary = body["quota_allowance"]["summary"]
11361144
span.set_tag(
11371145
f"{allocation_policy_prefix}threads_used",
@@ -1150,19 +1158,6 @@ def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet:
11501158
span.set_tag(k, v)
11511159
sentry_sdk.set_tag(k, v)
11521160

1153-
if (
1154-
"throttled_by" in quota_allowance_summary
1155-
and quota_allowance_summary["throttled_by"]
1156-
):
1157-
metrics.incr("snuba.client.query.throttle", tags={"referrer": referrer})
1158-
if random.random() < 0.01:
1159-
logger.warning(
1160-
"Warning: Query is throttled", extra={"response.data": response.data}
1161-
)
1162-
sentry_sdk.capture_message(
1163-
f"Warning: Query from referrer {referrer} is throttled", level="warning"
1164-
)
1165-
11661161
if response.status != 200:
11671162
_log_request_query(snuba_requests_list[index].request)
11681163
metrics.incr(

0 commit comments

Comments
 (0)