[fix][broker] Fix precision loss in DataSketchesSummaryLogger by replacing LongAdder with DoubleAdder for sum accumulation#25594
Merged
nodece merged 1 commit intoApr 29, 2026
Conversation
…acing LongAdder with DoubleAdder for sum accumulation
poorbarcode
pushed a commit
to poorbarcode/pulsar
that referenced
this pull request
May 6, 2026
…acing LongAdder with DoubleAdder for sum accumulation (apache#25594)
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.
Fixes
Motivation
In
DataSketchesSummaryLogger#registerEvent, thevalueMillis(adouble) was previously cast tolongbefore being added tosumAdder:This caused precision loss in the
_summetric exposed to Prometheus:1.8mswas recorded as1ms.longproduces0, meaning these events contribute nothing to the sum._summetric to be significantly lower than the actual total latency.This leads to inaccurate
_sumvalues in Prometheus Summary metrics, which in turn causes incorrect average latency calculations (sum / count).Modifications
Replace
LongAdderwithDoubleAdderforsumAdderinDataSketchesSummaryLoggerto preserve the fulldoubleprecision ofvalueMillis, eliminating the lossy(long)cast.Verifying this change
This change is a small refactor that fixes a data precision issue. The existing tests should continue to pass. The behavioral change is that
getSum()now returnsdoubleinstead oflong, which is compatible with all call sites since they already acceptdoublevalues (e.g.,MetricFamilySamples.Sampleconstructor andwriteMetricmethods).Does this pull request potentially affect one of the following parts?
Documentation
doc-requireddoc-not-neededdocdoc-complete