Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set scope_id property for project scoped abuse quota #67791

Conversation

ministicraft
Copy link

The get_usage() function in RedisQuota doesn't return the AbuseQuota usage for project because QuotaConfig lack the scope_id properties

This result in incorrect generation of the quota redis_key

Current generated redis key:
quota:pae{1}:xxxxxxxx
Should be like:
quota:pae{1}2:xxxxxxxx

This PR set the scope_id in QuotaConfig for project scoped abuse quota with the current project id when getting it's quotas

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@ministicraft ministicraft requested a review from a team as a code owner March 27, 2024 16:45
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 27, 2024
@Dav1dde
Copy link
Member

Dav1dde commented Mar 28, 2024

Thanks, good find!

I will double check back with my team, but I think we need to fix the Redis Key creation, to also consider the project scope:

def __get_redis_key(
self, quota: QuotaConfig, timestamp: float, shift: int, organization_id: int
) -> str:
scope_id = quota.scope_id or "" if quota.scope != QuotaScope.ORGANIZATION else ""
local_key = f"{quota.id}{{{organization_id}}}{scope_id}"
interval = quota.window
return f"{self.namespace}:{local_key}:{int((timestamp - shift) // interval)}"

@Dav1dde
Copy link
Member

Dav1dde commented Apr 3, 2024

Sorry for the late reply, I was away over easter. So the fix we need for this is to sync the __get_redis_key implementation with the one in Relay: https://github.com/getsentry/relay/blob/7828241ba8c8d781e89e593c7c3609d50190c4a6/relay-quotas/src/redis.rs#L130-L150

I think for a simple initial fix, adding in code for the project scope would be enough (as there is already for orgs), but for total completeness we'd also need to consider the namespace.

@getsantry
Copy link
Contributor

getsantry bot commented Apr 25, 2024

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you add the label WIP, I will leave it alone unless WIP is removed ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Apr 25, 2024
@getsantry getsantry bot closed this May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants