fix(slo): Correctly report TOO_MANY_BYTES from allocation policy as rate-limited#7846
Merged
fix(slo): Correctly report TOO_MANY_BYTES from allocation policy as rate-limited#7846
Conversation
…ate-limited When the BytesScannedRejectingPolicy sets max_bytes_to_read to allow smaller queries through, exceeding this limit triggers a TOO_MANY_BYTES error from ClickHouse. Previously, this was incorrectly reported as a generic ERROR in SLO metrics, counting against the SLO. This change: - Tracks when max_bytes_to_read is set by allocation policy via a flag - Updates get_request_status to accept context and check the flag - Only classifies TOO_MANY_BYTES as RATE_LIMITED when set by policy - Adds comprehensive test coverage for both scenarios Result: Allocation policy rate limiting no longer incorrectly impacts SLO. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
MeredithAnya
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human summary
Our SnQL API supposedly has a very high error rate:
https://app.datadoghq.com/s/FH6-Y3/7s2-qbw-ap9
but these errors are not being captured in sentry. I dug into the querylog and noticed that almost all of them scanned too many bytes. This is a decision the
BytesScannedRejectingPolicycan make to allow small queries through. It's surfaced as a rate limit to the caller but the metrics call it an error. This PR fixes itRobot Summary
Fixes SLO reporting for
TOO_MANY_BYTESerrors that occur when queries exceed themax_bytes_to_readlimit set by theBytesScannedRejectingPolicyallocation policy.Problem
When the
BytesScannedRejectingPolicydetermines a customer is over their scan limit, it can setmax_bytes_to_readon the ClickHouse query settings to allow smaller queries through instead of rejecting them outright. When a query exceeds this limit, ClickHouse raises aTOO_MANY_BYTESerror (code 307).Previously, this was being reported as a generic ERROR in SLO metrics, which counts against the SLO. However, this is actually rate limiting behavior and should be reported as RATE_LIMITED, which does not count against the SLO.
Changes
Track allocation policy context (
snuba/web/db_query.py:860)max_bytes_to_read_set_by_policyflag to stats when the allocation policy setsmax_bytes_to_readUpdate error handling (
snuba/web/db_query.py:479-483)RateLimitExceededwhen the flag is setContext-aware status determination (
snuba/querylog/query_metadata.py:128-149)get_request_status()to accept optional context parametermax_bytes_to_read_set_by_policyflag when handling TOO_MANY_BYTES errorsRequestStatus.RATE_LIMITEDonly when the flag is presentComprehensive test coverage
get_request_status()context handlingResult
Test Plan
All tests pass ✅