Skip to content

tsdb: keep a staleness marker followed by a later sample in one commit - #20530

Open
r0h1tb wants to merge 1 commit into
prometheus:mainfrom
r0h1tb:fix/tsdb-stale-marker-before-histogram
Open

r0h1tb wants to merge 1 commit into
prometheus:mainfrom
r0h1tb:fix/tsdb-stale-marker-before-histogram

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Which issue(s) does the PR fix:

No issue filed. Regression from #17296 (v3.7.0).

If the first sample of a native histogram series in an append is a float staleness marker, and the same append has a later sample for that series, Commit() returns nil but the marker is not stored:

app.AppendHistogram(0, l, 100, h, nil) // committed earlier
app = head.Appender(ctx)
app.Append(0, l, 200, math.Float64frombits(value.StaleNaN))
app.AppendHistogram(0, l, 300, h, nil)
app.Commit() // nil; the head has 100 and 300, a WAL replay has 100, 200 and 300

commitFloats turns the marker into a histogram marker and appends it after the batch's histograms. Its comment relies on there being no other sample of that series in the batch, but since #17296 floats are not tracked in typesInBatch, so the histogram at 300 stays in the same batch. The marker is then committed after it, rejected as out of order and dropped. It is still in the WAL, so the head and a replay disagree, and prometheus_tsdb_out_of_order_samples_total goes up. A float at 300 instead of a histogram goes wrong the same way.

This is what a remote-write receiver gets when a series goes stale and comes back within one request: the sender writes histogram staleness markers to its WAL as float StaleNaN (see storage/remote/queue_manager.go), and the receiver answers 204 and loses the marker. Scrapes append one sample per series per commit and are not affected.

The fix records a float staleness marker in typesInBatch as stStaleFloat when its series has no type in the batch yet, so any later sample of that series starts a new batch. Plain floats stay untracked.

TestHead_StaleMarkerBeforeLaterSampleInSameCommit covers integer and float histograms, appender V1 and V2, and a histogram or a float after the marker, checking the head before and after WAL replay. All 8 cases fail on main with [100 300] instead of [100 200 300]. I also checked it through NewWriteHandler with two v1 write requests against a real TSDB: 2 of 3 samples stored before, 3 of 3 after.

Release notes for end users (ALL commits must be considered).

Reviewers should verify clarity and quality.

[BUGFIX] TSDB: Do not drop a float staleness marker on a native histogram series when a later sample of the same series is appended in the same commit, as a remote-write receiver can. Regression in v3.7.0.

A float staleness marker that is the first sample of a native histogram
series in an append was dropped when the same append had a later sample
of that series. commitFloats converts the marker to a histogram marker
and commits it after the batch's histograms, which is only correct if
no other sample of the series is in the batch. Since floats are not
tracked in typesInBatch, the later sample stayed in the batch, so the
marker was committed after it and rejected as out of order, while
Commit returned nil and the WAL still held it.

Track such a marker as stStaleFloat, so any later sample of the series
starts a new batch.

Signed-off-by: Rohit Behera <[email protected]>
@r0h1tb
r0h1tb force-pushed the fix/tsdb-stale-marker-before-histogram branch from 9e20420 to 8600b74 Compare November 22, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant