Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/sentry/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from sentry.utils.sdk import capture_exception, merge_context_into_scope, set_span_attribute
from sentry.utils.snuba import (
DatasetSelectionError,
QueryBytesScannedExceeded,
QueryConnectionFailed,
QueryExecutionError,
QueryExecutionTimeMaximum,
Expand Down Expand Up @@ -402,6 +403,11 @@ def handle_query_errors() -> Generator[None]:
if isinstance(error, RateLimitExceeded):
sentry_sdk.set_tag("query.error_reason", "RateLimitExceeded")
raise Throttled(detail=RATE_LIMIT_ERROR_MESSAGE)
elif isinstance(error, QueryBytesScannedExceeded):
sentry_sdk.set_tag("query.error_reason", "QueryBytesScannedExceeded")
raise TimeoutException(
detail="Query has exceeded its bytes scanned limit. Please try your query with a smaller date range or fewer projects."
)
if isinstance(
error,
(
Expand Down
9 changes: 9 additions & 0 deletions src/sentry/utils/snuba.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ class QueryConnectionFailed(QueryExecutionError):
"""


class QueryBytesScannedExceeded(QueryExecutionError):
"""
The query exceeded the max_bytes_to_read limit set by an allocation policy.
This is a ClickHouse-level rejection (error code 307, TOO_MANY_BYTES),
distinct from Snuba-level rate limiting.
"""


clickhouse_error_codes_map = {
10: QueryMissingColumn,
43: QueryIllegalTypeOfArgument,
Expand All @@ -456,6 +464,7 @@ class QueryConnectionFailed(QueryExecutionError):
241: QueryMemoryLimitExceeded,
271: DatasetSelectionError,
279: QueryConnectionFailed,
307: QueryBytesScannedExceeded,
}


Expand Down
Loading