fix: bound observation buffering during collection - #2336
Open
zeitlinger wants to merge 7 commits into
Open
Conversation
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Contributor
|
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
zeitlinger
marked this pull request as ready for review
August 18, 2026 08:38
jaydeluca
requested changes
Aug 27, 2026
Member
There was a problem hiding this comment.
Two things I think block merge:
- The
==→>=change is hiding a real accounting bug. The phase
gate inappend()created a class of observation that increments its stripe after the
collector'sgetAndAdd— so it is excluded fromexpectedCount— yet still incrementscount.
maincould not produce that, which is why==was exact there and hangs here. Normally>=
absorbs it, but whenmaybeReset()callscount.reset()the offset absorbs only the snapshot,
not that observation, soexpectedCountstays permanently one too high. I reproduced a
permanently failingcollect()(details inline onBuffer.java). observeDirect()takes a lock on every observation in steady state. JMH from
HistogramBenchmark, both trees built from source (-f 1 -wi 3 -i 5 -r 2s -w 2s):
prometheusClassicSingleThread−38%,prometheusClassicPerThread−44% (uncontended!),
prometheusClassic−72%,prometheusNative−73%. The exclusion is only needed while a
collection is in flight.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Contributor
Benchmark resultsBenchmark run succeeded for
Prometheus Java Client BenchmarksRun Information
Comparison with base
Results for PR headCounterBenchmark
HistogramBenchmark
HistogramTextFormatBenchmark
TextFormatUtilBenchmark
Raw ResultsNotes
Benchmark Descriptions
|
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
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
observe()This is stacked on the focused #2282 fix so the two
Bufferconcerns can be reviewed separately. It replaces the #2287 portion of #2297.Fixes #2287
Ongoing discussion
The earlier concerns about an unbounded second wait and exceptions escaping from native-histogram maintenance are addressed by this implementation.
Validation
mise run lint:fixmise run build./mvnw test -pl prometheus-metrics-core -Dcoverage.skip=true -Dcheckstyle.skip=true