Skip to content

storage/remote: migrate Remote Write 1.0 receiver to AppenderV2 - #19250

Closed
krajorama wants to merge 3 commits into
mainfrom
krajo/rw1-receiver-appenderv2
Closed

krajorama wants to merge 3 commits into
mainfrom
krajo/rw1-receiver-appenderv2

Conversation

@krajorama

Copy link
Copy Markdown
Member

Part of #17632.

Alternative to #19248. Same goal (migrate the Remote Write 1.0 receiver to AppenderV2) but without modifying the exported storage.AppenderV2 interface, so downstream AppenderV2 implementations are not forced to change.

What

The RW 1.0 receiver path (writeHandler.write) is ported from V1 storage.Appender to storage.AppenderV2. RW 1.0 carries exemplars as a per-series list appended through a standalone AppendExemplar call, which AppenderV2 (exemplars via AppendV2Options) does not offer.

Instead of adding methods to storage.AppenderV2, this introduces two optional capability interfaces, storage.ExemplarAppenderV2 and storage.MetadataUpdaterV2, discovered via a type assertion — the same idiom as storage.GetRef. The remote-write package composes them into the capability its receiver requires (receiverAppenderV2). Only Prometheus' own appenders on the RW path implement them:

  • tsdb head: AppendExemplar/UpdateMetadata moved to the shared headAppenderBase so both V1 and V2 appenders share one implementation; initAppenderV2 delegates.
  • tsdb agent: the two methods moved to the shared appenderBase.
  • fanoutAppenderV2: delegates only to appenders that also implement the optional capability.
  • remote-write timestampTrackerV2: counts exemplars, metadata no-op.
  • notReadyAppenderV2: returns ErrNotReady.
  • teststorage: records via the optional capabilities.

The Remote Write 2.x path (writeV2) still uses the V1 appendable and will be migrated separately. NewWriteHandler now takes both appendable and appendableV2; web/api/v1 passes both.

Why this shape

storage.AppenderV2 is implemented by downstream projects (e.g. Cortex/Mimir). Adding methods to it is a breaking change for them. Keeping exemplar/metadata as optional, assertion-discovered capabilities avoids that while still letting the receiver reuse the standalone-append shape.

Tests

  • RW 1.0 handler tests now exercise the AppenderV2 path (the mock appendable gained a V2 appender recording into the same slices, so existing assertions hold).
  • TestHeadAppenderV2_AppendExemplarAndUpdateMetadata verifies the head implements the optional capabilities and stores the exemplar (via ExemplarQuerier) and metadata.
  • teststorage's shared V2 appender test covers the optional methods (incl. .Then chaining).
NONE

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks solid, but why we need MetadataUpdater?

//
// As with the V1 MetadataUpdater, UpdateMetadata must be called after the
// corresponding sample Append for the same series.
type MetadataUpdaterV2 interface {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see v1 using this method. Do we need to expose it? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mimir won't use it either, but I don't know about other downstream projects, so the safest is to add it.

krajorama and others added 2 commits August 18, 2026 10:43
Part of the migration off the V1 storage.Appender interface (#17632).

The Remote Write 1.0 receiver path (writeHandler.write) is ported from the V1
storage.Appender to storage.AppenderV2. Exemplars in RW 1.0 arrive as a
per-series list and are appended through a standalone AppendExemplar call, which
AppenderV2 (exemplars via AppendV2Options) does not offer.

Rather than adding AppendExemplar/UpdateMetadata to storage.AppenderV2 - which
would force every downstream AppenderV2 implementation to implement them - this
introduces two optional capability interfaces, storage.ExemplarAppenderV2 and
storage.MetadataUpdaterV2, discovered via a type assertion like storage.GetRef.
The remote-write package composes them into the appender capability its receiver
requires (receiverAppenderV2). Only Prometheus' own appenders on the RW path
implement them:

- tsdb head: AppendExemplar/UpdateMetadata moved to the shared headAppenderBase
  so both V1 and V2 appenders share one implementation; initAppenderV2 delegates.
- tsdb agent: the two methods moved to the shared appenderBase.
- fanoutAppenderV2: delegates only to appenders that also implement the optional
  capability.
- remote-write timestampTrackerV2: counts exemplars, metadata no-op.
- notReadyAppenderV2: returns ErrNotReady.
- teststorage: records via the optional capabilities.

The Remote Write 2.x path (writeV2) still uses the V1 appendable and will be
migrated separately. NewWriteHandler now takes both appendable and appendableV2.

Signed-off-by: György Krajcsovits <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: György Krajcsovits <[email protected]>
It was unused.

Signed-off-by: György Krajcsovits <[email protected]>
@krajorama
krajorama force-pushed the krajo/rw1-receiver-appenderv2 branch from 48932ce to e5afe15 Compare August 18, 2026 09:04
appenderV2.AppendExemplar and appenderV2.UpdateMetadata called a bare
computeOrCheckRef instead of the Appendable method, breaking the build.

Signed-off-by: György Krajcsovits <[email protected]>
@krajorama

Copy link
Copy Markdown
Member Author

favor #19457 over this

@krajorama krajorama closed this Aug 28, 2026
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.

2 participants