Skip to content

ref(allocation-policies): Remove old concurrency policies - #8724

Merged
dezzeddi merged 40 commits into
masterfrom
dani/remove-old-concurrency-policies
Dec 1, 2026
Merged

dezzeddi merged 40 commits into
masterfrom
dani/remove-old-concurrency-policies

Conversation

@dezzeddi

Copy link
Copy Markdown
Member

Depends on #8712, and on getsentry/sentry-options-automator#10664 migrating both policies. Merge only after both.

  • Deletes ConcurrentRateLimitAllocationPolicy, ReferrerGuardRailPolicy and their shared base.
  • errors and errors_ro now use ConcurrentQueriesPerRefPolicy (limit 100, not enforced), matching the old defaults.
  • Referrer thread throttling is dropped.
  • Tests for the old policies are removed; config tests use the v2 names.

dezzeddi and others added 30 commits November 11, 2026 22:38
…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.
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
@dezzeddi
dezzeddi marked this pull request as ready for review November 17, 2026 23:29
@dezzeddi
dezzeddi requested review from a team as code owners November 17, 2026 23:29
Base automatically changed from dani/concurrent-queries-policy-v2 to master November 18, 2026 20:36
…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
…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.
@dezzeddi
dezzeddi requested a review from pbhandari November 19, 2026 22:42
@dezzeddi
dezzeddi merged commit 8e76547 into master Dec 1, 2026
73 checks passed
@dezzeddi
dezzeddi deleted the dani/remove-old-concurrency-policies branch December 1, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants