sec: replace math/rand v1 with math/rand/v2 for rate-limiter jitter (closes #419) - #856
Conversation
…419) math/rand/v2 (Go 1.22+) is the project standard for non-crypto jitter (already used in pkg/retry/exponential.go). Swaps the package-level import in providers/aws/recommendations/ratelimiter.go; the call-site (rand.Float64()) is identical in v2. Adds TestWait_JitterRange: 200 iterations verify jitter stays within [0, 20%] of the base delay and spans more than 5% (non-stuck source).
|
@coderabbitai review |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR upgrades the rate limiter's jitter system from ChangesRate Limiter Jitter Upgrade
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
…k flakiness (refs #419) Extract computeJitter(delay, r) as a pure function and replace the wall-clock-based TestWait_JitterRange with TestComputeJitter, which drives the function with 10,000 evenly-spaced r values in [0,1) and asserts the output is within [0, 0.2*delay]. No sleeping means OS scheduling overhead cannot blow the upper-bound check. The spread assertion (max observed >= 95% of cap) still catches a regressed always-zero jitter source.
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
"math/rand"(v1) with"math/rand/v2"inproviders/aws/recommendations/ratelimiter.go-- the only v1 call site found inproviders/,internal/, andpkg/.math/rand/v2is already the project standard for non-crypto jitter (seepkg/retry/exponential.gowith an explanatory comment); this aligns the rate-limiter with that convention.rand.Float64()) is API-identical in v2; no logic changes.Test plan
go build ./...passesgo test github.com/LeanerCloud/CUDly/providers/aws/recommendations-- all 281 tests passTestWait_JitterRange: 200 iterations assert jitter stays within[0, 20%]of base delay and spans more than 5% (confirms the source is not stuck at zero)Closes #419
Summary by CodeRabbit
Refactor
Tests