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

feat(quotas): Add ability to use namespace in non-global quotas. #3090

Merged
merged 10 commits into from
Feb 21, 2024

Conversation

TBS1996
Copy link
Contributor

@TBS1996 TBS1996 commented Feb 12, 2024

#2716

With this PR, we can also use namespace in non-global quotas.

The reason for this PR was the requirement to be able to ratelimit based on namespace per org, but in reality it's pretty flexible so we can do namespace per project as well.

@TBS1996 TBS1996 self-assigned this Feb 12, 2024
@TBS1996 TBS1996 marked this pull request as ready for review February 13, 2024 04:47
@TBS1996 TBS1996 requested a review from a team as a code owner February 13, 2024 04:47
Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please address the suggestions below before merging.


let rate_limiter = build_rate_limiter();

for i in 0..10 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're effectively having two loops in one, and splitting it increases readability:

for i in 0..5 {
  assert_eq!(
    rate_limits[0].reason_code,
    Some(ReasonCode::new("ns: None"))
  );
}
for i in 0..5 {
  assert_eq!(rate_limits, vec![]);
}

(Same with the loop below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i get your point but it also makes it a bit less clear the separation of the loop with and without the namespace, and we'd also have to duplicate the let ratelimits = ... block more.

I agree it's not as clear as can be though, I uploaded some changes.

  1. added comments
  2. the 'quota_limit' variable should be more clear
  3. flipped the if/else statements

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably my personal opinion, and not going to block the PR for that, but this is one case in which I'm ok with some code duplication given I find less cognitive load and thus more readable.

relay-quotas/src/redis.rs Show resolved Hide resolved

let rate_limiter = build_rate_limiter();

for i in 0..10 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably my personal opinion, and not going to block the PR for that, but this is one case in which I'm ok with some code duplication given I find less cognitive load and thus more readable.

@TBS1996 TBS1996 merged commit d2efdc3 into master Feb 21, 2024
20 checks passed
@TBS1996 TBS1996 deleted the quotans branch February 21, 2024 09:57
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.

4 participants