Skip to content

fix(sdk): fix sub-second refill and idle burst in Jaeger LeakyBucket - #3879

Open
xgbtxy wants to merge 2 commits into
open-telemetry:mainfrom
xgbtxy:fix/jaeger-leaky-bucket-subsecond-refill
Open

xgbtxy wants to merge 2 commits into
open-telemetry:mainfrom
xgbtxy:fix/jaeger-leaky-bucket-subsecond-refill

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Nov 24, 2026 •

Copy link
Copy Markdown

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):

  1. Sub-second elapsed intervals truncated (dur.as_secs() as f64):
    Any sub-second elapsed duration was floored to 0.0 before advancing self.last_time = cur_time, permanently discarding fractional credit on rates > 1 span/sec or frequent calls. Replaced with dur.as_secs_f64().
  2. Double initial burst after idle period:
    Returning early on if self.available >= 1.0 left self.last_time at 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]). Refilling self.available (and advancing self.last_time) on forward duration_since before consuming 1.0 eliminates the double burst.
  3. Negative or non-finite rate/capacity inputs:
    Clamped non-finite and negative bucket_size / span_per_sec inputs in LeakyBucket::new and LeakyBucket::update to 0.0 so negative rates cannot accumulate token debt or propagate NaN/infinite capacities.

Verification

  • Added test_leaky_bucket_subsecond_refill, test_leaky_bucket_idle_does_not_double_burst, and test_leaky_bucket_clamps_negative_or_non_finite_params in rate_limit.rs (confirmed all 3 failed before the fix while existing 2 passed; all 5 pass after).
  • cargo +stable fmt --all -- --check: passed
  • cargo +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

- 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.
@xgbtxy
xgbtxy requested a review from a team as a code owner November 24, 2026 00:17
Copilot AI balanced review requested due to automatic review settings November 24, 2026 00:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-12-05 01:45 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with the author? Comment /dashboard route:author to route it back.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.8%. Comparing base (7385eda) to head (78ebfd3).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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