[Arch] Three independently-invented rate-limiting mechanisms #51
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: Medium | Category: Backend
_write_timestamps/_check_write_rate_limit()(main.py:24-27,583-588),_ingest_timestamps(main.py:145,600-609), and_last_manual_scrape/_MANUAL_SCRAPE_COOLDOWN(scheduler.py:430-431,455-460) all reimplement "limit calls per window" with three different shapes across two files.Recommendation: Extract one small
RateLimiterhelper used by all three call sites.Refactoring safety: Add characterization tests asserting current rate-limit behavior for all three call sites before consolidating.
Full detail:
docs/architecture-review.md§ C, Finding "Three independently-invented rate-limiting mechanisms"Fixed on branch
architecture-rework, commit64fa05d: addedrate_limit.RateLimiter(one sliding-window class;max_calls=1is behaviorally equivalent to the old single-timestamp cooldown, verified with a dedicated test). All three call sites —main._write_rate_limiter,main._ingest_rate_limiter,scheduler._manual_scrape_rate_limiter— now share it. Addedtests/test_rate_limit.py. Full suite: 257 passed.