Repository navigation
ref(allocation-policies): Remove old concurrency policies - #8724
Merged
Merged
Conversation
…y base Adds KeyedAllocationPolicy, a v2 base that counts usage per key and rejects once a key reaches its limit, and BytesScannedPolicy on top of it with per-org, per-referrer and per-org-referrer variants. Settings (limit, enforce, max_threads, timeout_penalty) come only from allocation_policies match blocks. Refs EAP-871
tests/ has no __init__.py files, so two test_base.py modules collide during pytest collection.
Move KeyedAllocationPolicy and the BytesScannedPer*Policy classes into the main allocation_policies package. The package's submodule scan now registers them, so the separate v2 scan is gone. No behavior change.
KeyedAllocationPolicy and BytesScannedPolicy take their settings as keyword-only parameters instead of **kwargs. The resolver drops the config entry's name before construction. An unknown key or a bad value raises AllocationPolicyError, and the resolver catches only that error to skip the policy with a warning, so other errors still surface.
KeyedAllocationPolicy._record and _update_quota_balance now return the amount added to the key's usage: BytesScannedPolicy returns the bytes recorded, 0 when nothing is recorded or for cross-org queries. AllocationPolicy.update_quota_balance and _update_quota_balance widen to int | None so v1 policies returning None stay valid. update_quota_balance returns None when it fails open. Callers ignore the value.
Replace the abstract quota_unit, suggestion and default_limit properties with class attributes (DEFAULT_LIMIT as a constant), drop the unused limit and enforce properties, and inline _storage_prefix into BytesScannedPolicy, its only user. No behavior change.
…licy Remove the module-level org_key, ref_key and org_ref_key functions. Each BytesScannedPer* policy now builds its own key in _key, and the missing-tenant check moves to KeyedAllocationPolicy._tenant. The Redis key strings are unchanged, so live counters keep their usage. Add a test pinning each policy's key string, and cover org_ref without a referrer in the missing-tenant test.
…w setting Reviewers asked whether the 10-minute window is configurable. Add a time_window setting, in seconds, set per policy in the allocation_policies match block next to limit. It defaults to 600 and must be a positive multiple of the 60-second granularity. The window is part of the Redis prefix, so blocks with different windows on the same key never share a counter. This resets existing counters once on deploy; the policy is not deployed anywhere yet. The rejection suggestion now names the configured window instead of a hard-coded 10 minutes.
…s own counter Configures BytesScannedPerOrgPolicy, BytesScannedPerRefPolicy and BytesScannedPerOrgRefPolicy in one match block and checks which counters each query updates, and that a limit rejects only through the policy that reached it.
Move the timeout check into a module-level _is_timeout helper and drop the assert, cast and isinstance check. A missing profile or progress_bytes still counts as 0. Add a test for results with no progress_bytes.
The sentry-options schema already validates setting types, so assign the typed constructor arguments directly. Range checks and the unknown-key check still raise AllocationPolicyError.
…onPolicy A config key that __init__ does not accept now raises TypeError from AllocationPolicy.from_kwargs instead of AllocationPolicyError, so the resolver no longer skips the policy with a warning.
Config is reviewed by humans, so BytesScannedPolicy no longer checks time_window or timeout_penalty. AllocationPolicyError has no users left, so it and the resolver branch that skipped invalid policies are removed.
…dPolicy KeyedAllocationPolicy had one subclass, so the split only added code. Move its settings, overrides and helpers into BytesScannedPolicy, inline _check/_record into the quota hooks, and drop the abstract declarations and ClassVars that only existed for the split. Behavior and Redis key names are unchanged.
…wance Return one _allowance call driven by can_run instead of separate within-limit and rejected blocks, and drop the "limit" explanation entry, which repeats QuotaAllowance.rejection_threshold.
Cut the class docstring to a short summary and one line per setting, drop method docstrings that restate the code, and merge the four repeated refactor markers into one.
…to dani/bytes-scanned-policy-v2
The sliding-window limiter counts whole 60-second granules, so a window in seconds that is not a multiple of 60 shrinks or never counts. Taking minutes makes every positive whole number valid.
v2 concurrent-queries policy in the style of BytesScannedPolicy. Rejects a query when its key already has `limit` queries running, using the existing Redis concurrency helpers. Settings come only from the match block. Refs EAP-871
…2' into dani/concurrent-queries-policy-v2
Remove ConcurrentRateLimitAllocationPolicy, ReferrerGuardRailPolicy and their shared base. The errors storages now use ConcurrentQueriesPerRefPolicy.
…currency-policies # Conflicts: # snuba/datasets/configuration/events/storages/errors.yaml # snuba/datasets/configuration/events/storages/errors_ro.yaml # snuba/query/allocation_policies/OVERRIDES.md # tests/query/allocation_policies/test_allocation_policy_base.py # tests/query/allocation_policies/test_attachment.py
pbhandari
requested changes
Nov 19, 2026
…hema in docs Errors storages now take their allocation policies from sentry-options only. OVERRIDES.md uses an AllocationPolicy class and the nested allocation_policies example.
pbhandari
approved these changes
Nov 20, 2026
pbhandari
approved these changes
Dec 1, 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.
Depends on #8712, and on getsentry/sentry-options-automator#10664 migrating both policies. Merge only after both.
ConcurrentRateLimitAllocationPolicy,ReferrerGuardRailPolicyand their shared base.errorsanderrors_ronow useConcurrentQueriesPerRefPolicy(limit 100, not enforced), matching the old defaults.