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

Global ratelimiter helper: a small atomic-like map #6027

Merged
merged 2 commits into from
May 22, 2024

Conversation

Groxx
Copy link
Member

@Groxx Groxx commented May 18, 2024

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.

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.
Copy link

codecov bot commented May 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.06%. Comparing base (02c7efb) to head (5b4aaca).
Report is 3 commits behind head on master.

Additional details and impacted files
Files Coverage Δ
...mon/quotas/global/collection/internal/atomicmap.go 100.00% <100.00%> (ø)

... and 8 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 02c7efb...5b4aaca. Read the comment docs.

@Groxx Groxx changed the title Ratelimiter Global ratelimiter helper: an atomic-like map to simplify other use Global ratelimiter helper: an atomic-like map to simplify other use May 18, 2024
@Groxx Groxx changed the title Global ratelimiter helper: an atomic-like map to simplify other use Global ratelimiter helper: a small atomic-like map May 18, 2024
@Groxx Groxx merged commit 144a627 into cadence-workflow:master May 22, 2024
20 checks passed
@Groxx Groxx deleted the ratelimiter-map branch May 22, 2024 22:09
timl3136 pushed a commit to timl3136/cadence that referenced this pull request Jun 6, 2024
…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.
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