sdk/metric/exemplar: skip Offer on a zero-sized FixedSizeReservoir#8243
Closed
SAY-5 wants to merge 1 commit into
Closed
sdk/metric/exemplar: skip Offer on a zero-sized FixedSizeReservoir#8243SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
NewFixedSizeReservoir already clamps k to 0 when the caller passes a negative value, but FixedSizeReservoir.Offer doesn't defend against k == 0: after the first call, count reaches next and the random-index branch runs rand.IntN(int(r.k)) = rand.IntN(0), which panics with 'invalid argument to IntN'. The SDK path doesn't expose this today, but callers that hand-roll a reservoir (or reach it through a custom ReservoirProvider) can, as Copilot noted on open-telemetry#8230 / open-telemetry#8232. Short-circuit Offer when r.k == 0. Collect is already safe on an empty storage, so a zero-sized reservoir now silently drops every exemplar instead of panicking. Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com> Fixes open-telemetry#8232
Collaborator
|
Needs a unit test, and the giant comment probably isn't necessary. A one-line comment should be sufficient. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8243 +/- ##
=====================================
Coverage 82.6% 82.7%
=====================================
Files 310 310
Lines 24648 24650 +2
=====================================
+ Hits 20381 20386 +5
+ Misses 3890 3887 -3
Partials 377 377
🚀 New features to boost your workflow:
|
3 tasks
Author
|
@pellared sorry for the duplicate. To answer your questions directly:
|
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
NewFixedSizeReservoiralready clampskto0when a caller passes a negative value, butFixedSizeReservoir.Offerdoes not defend againstr.k == 0. After a single call,countreachesnextand the random-index branch runs:which panics with
invalid argument to IntN. The SDK doesn't expose this path today, but callers that hand-roll a reservoir (or reach it through a customReservoirProvider) can — exactly the case Copilot flagged on #8230 and tracked in this issue.Fixes #8232.
Change
Short-circuit
Offerwhenr.k == 0:Collectis already safe on an emptystorage, so a zero-sized reservoir now silently drops every exemplar instead of panicking.Testing
go test ./sdk/metric/exemplar/...passes.Offerregression against a reservoir built withNewFixedSizeReservoir(0)and then calledOffer100 times; previously it panicked on the second call, now it runs cleanly andCollectreturns an empty slice.