Skip to content

Commit

Permalink
fix(issues): Add project id to occurrence rate limit key (#79695)
Browse files Browse the repository at this point in the history
this pr adds the project id to the occurrence rate limit key, some
fingerprints can be the same across projects and we don't want to rate
limit across projects
  • Loading branch information
roggenkemper authored Oct 24, 2024
1 parent 04127b7 commit 7cceb28
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/sentry/issues/occurrence_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ class EventLookupError(Exception):
pass


def create_rate_limit_key(fingerprint: str) -> str:
rate_limit_key = f"occurrence_rate_limit:{fingerprint}"
def create_rate_limit_key(project_id: int, fingerprint: str) -> str:
rate_limit_key = f"occurrence_rate_limit:{project_id}-{fingerprint}"
return rate_limit_key


def is_rate_limited(
project_id: int,
fingerprint: str,
) -> bool:
try:
rate_limit_enabled = options.get("issues.occurrence-consumer.rate-limit.enabled")
if not rate_limit_enabled:
return False

rate_limit_key = create_rate_limit_key(fingerprint)
rate_limit_key = create_rate_limit_key(project_id, fingerprint)
rate_limit_quota = Quota(**options.get("issues.occurrence-consumer.rate-limit.quota"))
granted_quota = rate_limiter.check_and_use_quotas(
[
Expand Down Expand Up @@ -353,7 +354,7 @@ def process_occurrence_message(
txn.set_tag("result", "dropped_feature_disabled")
return None

if is_rate_limited(fingerprint=occurrence_data["fingerprint"][0]):
if is_rate_limited(project.id, fingerprint=occurrence_data["fingerprint"][0]):
metrics.incr(
"occurrence_ingest.dropped_rate_limited",
sample_rate=1.0,
Expand Down

0 comments on commit 7cceb28

Please sign in to comment.