Repository navigation
fix(sdk): keep exemplars per timeseries - #2180
Open
gowtham-padala wants to merge 1 commit into
Open
gowtham-padala wants to merge 1 commit into
gowtham-padala wants to merge 1 commit into
Conversation
gowtham-padala
force-pushed
the
fix/exemplar-reservoir-per-series
branch
from
December 5, 2026 02:55
dc143ad to
7794756
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2180 +/- ##
============================================
+ Coverage 74.02% 74.05% +0.03%
Complexity 3786 3786
============================================
Files 493 493
Lines 10653 10651 -2
============================================
+ Hits 7886 7888 +2
+ Misses 2767 2763 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
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.
Closes #2168
Summary
Every series of a metric stream shared one exemplar reservoir, so one series' measurements replaced another's exemplars. A histogram that records 0.2 for
http.route=/aand then 0.2 forhttp.route=/bexported an exemplar only for/b. The spec requires a reservoir per timeseries.Following the issue, there is still one reservoir object per stream, but its state is kept per series index, so
ExemplarReservoirInterfaceandStreamFactorydon't change.Changes
BucketStoragekeys its entries by series index and bucket.collect()returns every series' exemplars, keyed"<index>:<bucket>", and clears the state, so series that stop recording don't hold memory. The keys are unique per series and bucket, becauseDeltaStorage::mergeInto()merges exemplars with+=, which keeps only one entry per key.FixedSizeReservoirkeeps a measurement count per series, and fills empty slots before sampling, as in the spec's SimpleFixedSizeExemplarReservoir algorithm. Before, it drewrandom_int(0, $measurements)from the first measurement, so the second one could overwrite the first.FixedSizeReservoirdefaults to 1 exemplar instead of 4, since PHP has no threads to size it by. This is under Changed in the changelog.BucketStorageno longer takes a size, since it no longer preallocates. It is@internal.Testing
HistogramBucketReservoirTest: two series offering into the same bucket each get their exemplar back.FixedSizeReservoirTest: two measurements into an empty reservoir of size 4 give two exemplars; a series with one measurement keeps its exemplar after another series offers 100; a reservoir built with no size returns one exemplar per series;collect()resets it.BucketStorageTest: unique keys per series and bucket, andcollect()clears the storage.tests/Integration/SDK/Metrics/ExemplarTest: the/aand/bexample through aMeterProviderwith the in-memory exporter and thealways_onfilter. Both data points carry an exemplar.mainand pass with this change. On PHP 8.2 with the dev image, the unit and integration suites pass apart from tests that also fail onmainlocally (composer resource detector,TraceTestreference tests).phpstanandphp-cs-fixerare clean.