-
Notifications
You must be signed in to change notification settings - Fork 805
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
Global ratelimiter helper: a small atomic-like map #6027
Conversation
Global ratelimiter helper: an atomic-like map to simplify other use This commit largely exists to break this out for separate review, as it's relatively simple and isolated.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
... and 8 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
common/quotas/global/collection/internal/atomicmap_external_test.go
Outdated
Show resolved
Hide resolved
common/quotas/global/collection/internal/atomicmap_external_test.go
Outdated
Show resolved
Hide resolved
…6027) This commit largely exists to break this out for separate review, as it's relatively simple and isolated. In a later PR, this will be used by the "limiter"-side logic to hold known ratelimiters, and simplify its logic. So it does just two core things, and exposes a *very* small API that's intended to be difficult or impossible to misuse: 1. Tracks length, so a "iterate over everything and collect data for sending to aggregators" loop can pre-allocate a collection that is likely large enough to store everything. 2. Implicitly initializes missing values, so the using logic does not ever need to check for existence or explicitly handle fallbacks or decide how to order atomic operations. It could have other methods, but so far they do not seem necessary. Delete is not currently planned to be used, but it seems important to reserve / guarantee it's possible to build, so I've included that as well. --- This is not intended to be broadly reusable as we do not currently have any other locations that will use it, and the auto-initializing behavior is potentially unique. It's mostly just isolating and simplifying some logic to prevent accidental misuse, because early iterations had some easily-missed flaws. We very likely *should* have a "just a type-safe `sync.Map`" wrapper, which this could easily be changed to use, but the vast majority of that API would be unused here so I haven't built that.
This commit largely exists to break this out for separate review, as it's relatively simple and isolated.
In a later PR, this will be used by the "limiter"-side logic to hold known ratelimiters, and simplify its logic. So it does just two core things, and exposes a very small API that's intended to be difficult or impossible to misuse:
It could have other methods, but so far they do not seem necessary. Delete is not currently planned to be used, but it seems important to reserve / guarantee it's possible to build, so I've included that as well.
This is not intended to be broadly reusable as we do not currently have any other locations that will use it, and the auto-initializing behavior is potentially unique. It's mostly just isolating and simplifying some logic to prevent accidental misuse, because early iterations had some easily-missed flaws.
We very likely should have a "just a type-safe
sync.Map
" wrapper, which this could easily be changed to use, but the vast majority of that API would be unused here so I haven't built that.