-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(ratelimits): Add metric buckets rate limit #11506
Conversation
size-limit report 📦
|
b44c390
to
945c6e5
Compare
packages/utils/src/ratelimit.ts
Outdated
@@ -85,7 +85,16 @@ export function updateRateLimits( | |||
updatedRateLimits.all = now + delay; | |||
} else { | |||
for (const category of categories.split(';')) { | |||
updatedRateLimits[category] = now + delay; | |||
if (category === 'metric_bucket') { | |||
const namespaces = limit.split(':', 5)[4] ? limit.split(':', 5)[4].split(';') : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we combine this limit.split
call with the one above in const [retryAfter, categories]
?
also generally we prefer against using null
, undefined
is returned by default when array access returns nothing, and it helps reduce bundle size generally.
|
||
if (!namespaces || namespaces.includes('custom')) { | ||
// back off transmitting metrics from the SDK | ||
updatedRateLimits[category] = now + delay; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the same as line 96, can we merge the logic somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added all in one if
statement. But as it is not so clear anymore that 'metric_bucket'
actually is the category when namespaces
is defined, I added a comment that explains it :)
packages/utils/src/ratelimit.ts
Outdated
// namespaces will be present when category === 'metric_bucket' | ||
if (category !== 'metric_bucket' || !namespaces || namespaces.split(';').includes('custom')) { | ||
updatedRateLimits[category] = now + delay; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// namespaces will be present when category === 'metric_bucket' | |
if (category !== 'metric_bucket' || !namespaces || namespaces.split(';').includes('custom')) { | |
updatedRateLimits[category] = now + delay; | |
} | |
if (category === 'metric_bucket') { | |
// namespaces will be present when category === 'metric_bucket' | |
if (!namespaces || namespaces.split(';').includes('custom')) { | |
updatedRateLimits[category] = now + delay; | |
} | |
} else { | |
updatedRateLimits[category] = now + delay; | |
} |
This is giga nitting but I would do it like this. Regardless of bundlesize (hoping terser is smart enough). Makes it easier to understand this admittedly convoluted logic.
@@ -197,3 +197,35 @@ describe('updateRateLimits()', () => { | |||
expect(updatedRateLimits.all).toEqual(60_000); | |||
}); | |||
}); | |||
|
|||
describe('data category "metric_bucket"', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add another test case for 2700:metric_bucket:organization:quota_exceeded:
closes #11336