In-Storage & WAL Coupling - #4
Draft
dashpole wants to merge 3 commits into
Draft
Conversation
Implement compound WAL records and full pipeline coupling between samples and exemplars for issue prometheus#17857 (Option A): - Define compound record types (RefSampleV2, RefHistogramSampleV2, RefFloatHistogramSampleV2, RefCustomBucketsHistogramSampleV2) in tsdb/record. - Implement zero-allocation exemplar skipping decoders for replay efficiency. - Update HeadAppenderV2 to commit compound WAL records while dual-writing to in-memory ExemplarStorage to preserve PromQL query invariants. - Update WAL Watcher to stream compound records directly to QueueManager, populating PRW 2.0 TimeSeries with attached exemplars and PRW 1.0 conversions. - Add comprehensive test coverage verifying mixed WAL replay, rollback semantics, PRW 2.0/1.0 exemplar attachment, and zero-allocation decoding.
…fer pooling, and decoder header fix
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.
Why is this change necessary?
Possible fix for prometheus#17857
In Remote Write 2.0 (PRW 2.0), the specification mandates:
Historically, Prometheus has treated exemplars as a series-level attribute rather than a sample-level attribute.
headAppenderV2.Commit()writes float/histogram samples and exemplars to separate WAL records (record.Samplesvs.record.Exemplars). When the WAL Watcher tails the WAL and pushes them into Remote Write shard queues, they are processed as independent series items. For PRW 2.0, this causes standalone exemplar records to be emitted aswritev2.TimeSeriescontaining exemplars with 0 samples and 0 histograms, directly violating the PRW 2.0 specification and causing failures in PRW 2.0 receivers (e.g. OpenTelemetry Collector, Mimir, Google Cloud Managed Prometheus).What does this PR do?
This PR implements Option A: End-to-End Per-Sample Association (In-Storage & WAL Coupling):
Compound WAL Records (
tsdb/record):RefSampleV2,RefHistogramSampleV2,RefFloatHistogramSampleV2, andRefCustomBucketsHistogramSampleV2.record.SamplesV2 (10),record.HistogramSamplesV2 (11),record.FloatHistogramSamplesV2 (12), andrecord.CustomBucketsHistogramSamplesV2 (13).skipExemplars) used during recovery/fast replay when exemplars are not needed.Head Appender & TSDB Dual-Write (
tsdb/head_append_v2.go,tsdb/head_wal.go):headAppenderV2.Appendto package attached exemplars into compound batches and commit compound WAL records./api/v1/query_exemplarsvia dual-write to in-memoryh.exemplars(CircularExemplarStorage).ExemplarStorageduring Head WAL replay recovery.WAL Watcher & Remote Write Pipeline (
tsdb/wlog/watcher.go,storage/remote/queue_manager.go):QueueManager.sendExemplars=falseor during non-tailing replay.populateV2TimeSeriesmaps attached exemplars directly to the metric'swritev2.TimeSeriesobject, guaranteeing 0 empty/standalone exemplar series.prompb.WriteRequest).Verification & Testing
go test -v -race ./tsdb/record/... ./tsdb/... ./tsdb/wlog/... ./storage/remote/...(All PASS)BenchmarkRecord/DecodeSamplesV2_ZeroAllocStripping: 0 allocs/opExemplarQuerierassertions after replay.