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

Expose the current Limit() on existing ratelimiters #6235

Merged
merged 6 commits into from
Aug 22, 2024

Conversation

Groxx
Copy link
Member

@Groxx Groxx commented Aug 16, 2024

A rather minor change, but it will be useful for a later PR:
I'm building some logic into the global ratelimiter that needs to know what the "local" limit would be, because that value is assumed to be "safe" in the absence of other info.
The easiest and IMO cleanest way to implement this is to allow interrogating the existing limiters (the global-fallback one specifically), rather than re-implementing the "get the limit and divide by the ring size" logic separately, because that logic may drift.

More generally: I think we'll eventually either get rid of quotas.Limiter, or turn it into a complete read-only subset of clock.Ratelimiter (because very few things need to write to limits). This is an incremental step towards that.

I also attempted to change all the other things touching this to rate.Limit, but... that turned out to be rather large. I think it's worth doing, primitive types are unnecessarily vague in nearly all cases, but not right now.

A rather minor but wide-touching change, but it will be useful for a later PR.
Copy link

codecov bot commented Aug 19, 2024

Codecov Report

Attention: Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 72.96%. Comparing base (67fcf12) to head (6323f62).
Report is 10 commits behind head on master.

Files Patch % Lines
common/quotas/dynamicratelimiter.go 0.00% 2 Missing ⚠️
common/quotas/ratelimiter.go 80.00% 1 Missing ⚠️
Additional details and impacted files
Files Coverage Δ
...ommon/quotas/global/collection/internal/counted.go 100.00% <100.00%> (ø)
...mmon/quotas/global/collection/internal/fallback.go 96.36% <100.00%> (+0.28%) ⬆️
...mmon/quotas/global/collection/internal/shadowed.go 100.00% <100.00%> (ø)
service/matching/tasklist/matcher.go 63.67% <100.00%> (ø)
common/quotas/ratelimiter.go 78.84% <80.00%> (+25.90%) ⬆️
common/quotas/dynamicratelimiter.go 66.66% <0.00%> (-8.34%) ⬇️

... and 6 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67fcf12...6323f62. Read the comment docs.

return tm.limiter.Limit()
return float64(tm.limiter.Limit())
Copy link
Member Author

Choose a reason for hiding this comment

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

though I'd like to add this....... it leads to a massive explosion in "well this is also the same value, so change that too..." chain of changes, with no good place to cut things off.

I think changing all these is very much worth it, float64 is rather obviously a worse type. But I'm not tackling that right now.

@Groxx Groxx changed the title Use rate.Limit instead of untyped floats in ratelimiters Expose the current Limit() on existing ratelimiters Aug 19, 2024
Comment on lines +61 to +63
// limiter. This is currently only used in tests.
func NewSimpleRateLimiter(t *testing.T, rps int) *RateLimiter {
t.Helper() // ensure a T has been passed
Copy link
Member Author

@Groxx Groxx Aug 19, 2024

Choose a reason for hiding this comment

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

seems very likely that this will only ever be used in tests. almost all of our real limiters are dynamically configurable.

Copy link
Member

@davidporter-id-au davidporter-id-au Aug 21, 2024

Choose a reason for hiding this comment

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

I'd consider s/Simple/Test/ because it presumably means this has testing functionality and that makes it considerably easier to find when casting about for functions to use in tests

Comment on lines -110 to +111
func (rl *RateLimiter) Limit() float64 {
func (rl *RateLimiter) Limit() rate.Limit {
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to change because this is also a quotas.Limiter, and the signature is incompatible.

@davidporter-id-au
Copy link
Member

davidporter-id-au commented Aug 21, 2024

Would you mind adding a line or two about the why to the PR description? The change makes sense, but it's not immediately clear from reading the description and code what the goal of your change is, besides that it seemed like a good thing to expose.

@Groxx
Copy link
Member Author

Groxx commented Aug 22, 2024

Would you mind adding a line or two about the why to the PR description? The change makes sense, but it's not immediately clear from reading the description and code what the goal of your change is, besides that it seemed like a good thing to expose.

yep, completely agreed, it was unclear. updated!

@Groxx Groxx merged commit b689bad into cadence-workflow:master Aug 22, 2024
19 checks passed
@Groxx Groxx deleted the quota-limit-api branch August 22, 2024 21:23
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