Repository navigation
Conversation
- Replace dur.as_secs() as f64 with dur.as_secs_f64() in LeakyBucket::check_availability so sub-second rates and intervals are not truncated to zero. - Compute elapsed duration and advance last_time on every forward check_availability call before consuming a token, preventing stale last_time from granting a double initial burst after idle periods. - Clamp negative or non-finite bucket_size/span_per_sec inputs in LeakyBucket::new and LeakyBucket::update to 0.0. - Add regression tests and CHANGELOG entry.
Pull request dashboard statusWaiting on reviewers · refreshed 2026-12-05 01:45 UTC Review the latest changes. Status above doesn't look right?
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3879 +/- ##
=====================================
Coverage 86.8% 86.8%
=====================================
Files 131 131
Lines 34801 34847 +46
=====================================
+ Hits 30216 30268 +52
+ Misses 4585 4579 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…et-subsecond-refill
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three rate-limiting bugs in
opentelemetry_sdk::trace::sampler::jaeger_remote::rate_limit::LeakyBucket(opentelemetry-sdk/src/trace/sampler/jaeger_remote/rate_limit.rs):dur.as_secs() as f64):Any sub-second elapsed duration was floored to
0.0before advancingself.last_time = cur_time, permanently discarding fractional credit on rates > 1 span/sec or frequent calls. Replaced withdur.as_secs_f64().Returning early on
if self.available >= 1.0leftself.last_timeat initialization time until all burst tokens drained. Subsequent calls in the same instant then saw the entire prior idle duration and refilled another full burst immediately ([true, true, true, true]instead of[true, true, false, false]). Refillingself.available(and advancingself.last_time) on forwardduration_sincebefore consuming1.0eliminates the double burst.Clamped non-finite and negative
bucket_size/span_per_secinputs inLeakyBucket::newandLeakyBucket::updateto0.0so negative rates cannot accumulate token debt or propagateNaN/infinite capacities.Verification
test_leaky_bucket_subsecond_refill,test_leaky_bucket_idle_does_not_double_burst, andtest_leaky_bucket_clamps_negative_or_non_finite_paramsinrate_limit.rs(confirmed all 3 failed before the fix while existing 2 passed; all 5 pass after).cargo +stable fmt --all -- --check: passedcargo +stable clippy -p opentelemetry_sdk --all-targets --all-features -- -Dwarnings: passed (0 warnings)cargo +stable test -p opentelemetry_sdk --all-features --lib: 516 passed, 0 failed, 25 ignored