fix: off-by-one bug for FixedSizeReservoir#8309
Draft
dashpole wants to merge 1 commit into
Draft
Conversation
eb084a8 to
18983cb
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an off-by-one error in the FixedSizeReservoir (Algorithm L) reset initialization that previously made the first measurement after the reservoir filled (the k+1th offer) impossible to sample, and adds a regression test plus a changelog entry.
Changes:
- Fix
FixedSizeReservoir.reset()initialization ofr.nextso the first post-fill replacement opportunity can occur at the correct count. - Add a regression test that would deterministically fail under the prior behavior (second offered item never sampled for
k=1). - Document the fix in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
sdk/metric/exemplar/fixed_size_reservoir.go |
Adjusts reset() to initialize r.next as cap-1 so the subsequent advance() produces the correct first eligible replacement count. |
sdk/metric/exemplar/fixed_size_reservoir_test.go |
Adds a regression test ensuring the k+1th offer can be sampled (verifies the off-by-one is fixed). |
CHANGELOG.md |
Adds a “Fixed” entry describing the off-by-one bug and its user-visible impact. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8309 +/- ##
=====================================
Coverage 82.9% 82.9%
=====================================
Files 314 314
Lines 24985 24985
=====================================
+ Hits 20730 20733 +3
+ Misses 3882 3880 -2
+ Partials 373 372 -1
🚀 New features to boost your workflow:
|
Collaborator
Author
|
Test failure is because this needs #8295 |
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.
While working on #8306, I found an off-by-one error.
Reset was setting
r.nexttok, and then calling advance(), which meantr.nextwas always at leastk+1.The first
kexemplars are unconditionally stored during the "fill" phase. Count is incremented at the end of the Offer call, so thek+1th exemplar was never stored becauser.nextiskwhen that Offer call is being evaluated.