Skip to content

storage/remote: pass RW 2.0 exemplars and metadata via AppendV2Options - #19252

Closed
krajorama wants to merge 1 commit into
krajo/rw2-receiver-appenderv2from
krajo/rw2-receiver-opts
Closed

krajorama wants to merge 1 commit into
krajo/rw2-receiver-appenderv2from
krajo/rw2-receiver-opts

Conversation

@krajorama

Copy link
Copy Markdown
Member

Part of #17632. Stacked on top of #19251 — base branch is krajo/rw2-receiver-appenderv2, so review only the top commit here.

What

#19251 ported the RW 2.x receiver to AppenderV2 but still appended exemplars and metadata through the standalone AppendExemplar / UpdateMetadata calls. This takes advantage of the combined AppenderV2.Append: for each received series, exemplars (sorted by timestamp, as the interface requires) and metadata are attached to the first sample/histogram append via AppendV2Options, and the remaining appends of the series carry empty options.

Consequences

  • Exemplar stats/errors now come back as storage.AppendPartialError from that first Append. X-Prometheus-Remote-Write-Written-Exemplars is derived from it (appended = provided − errored); out-of-order exemplars still map to 400, other exemplar errors remain a no-op — preserving prior behaviour.
  • Metadata is best-effort within Append and no longer reports an error, so the samplesAppendedWithoutMetadata increment is dropped from the RW 2.x path. The metric stays registered and is still used by the RW 1.0 path. No test asserts it.
  • remoteWriteAppenderV2.UpdateMetadata is removed (no longer used).

Edge case

Exemplars/metadata attach to the first sample/histogram, so if that first append is rejected (e.g. an out-of-order first sample) they are dropped with it; previously exemplars were appended in a separate pass. This only affects that specific case.

Tests

The mock's V2 appender now records opts.Exemplars/opts.Metadata and returns partial errors, so the existing V2-message assertions hold. Added a case exercising metadata stored via AppendV2Options — metadata storage was previously not covered by the handler test.

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.

Interesting, I'd opt for a different logic

// the combined AppenderV2.Append. AppendV2Options.Exemplars must be sorted by
// timestamp.
var exemplars []exemplar.Exemplar
for _, ep := range ts.Exemplars {

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.

This is tricky given #19250 (comment) gap.

(Technically we should if Exemplar > 0 AND no sample and no histogram - we should likely write to standalone Exemplar for now. Then if it's related to sample/histogram we should either write to (A1) all(or (A2) first if we don't trust dedup logic) OR (B) change proto to have a new Exemplar field per sample so this logic is explicit.

}
exemplars = append(exemplars, e)
}
slices.SortStableFunc(exemplars, func(a, b exemplar.Exemplar) int { return cmp.Compare(a.Ts, b.Ts) })

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.

We could also consider requiring this from protocol perspective

}
// firstOpts returns opts for the first sample/histogram of the series and
// empty options for the rest, so exemplars and metadata are attached once.
firstOpts := func() storage.AppendV2Options {

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.

again, metadata should be safe to be attached again

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.

also in practice we shouldn't see penalty (we always send 1 sample)

Part of the migration off the V1 storage.Appender interface (#17632).
Builds on the Remote Write 2.x AppenderV2 migration.

The previous step ported writeV2 to AppenderV2 but still appended exemplars and
metadata through the standalone AppendExemplar / UpdateMetadata calls. This takes
advantage of the combined AppenderV2.Append: for each received series, the
exemplars (sorted by timestamp, as the interface requires) and metadata are
attached to the first sample or histogram append via AppendV2Options, and the
remaining appends of the series carry empty options.

Consequences:

- Exemplar results now come back as storage.AppendPartialError from that first
  Append. The X-Prometheus-Remote-Write-Written-Exemplars count is derived from
  it (appended = provided - errored), out-of-order exemplars still map to a 400,
  and other exemplar errors remain a no-op, preserving the previous behaviour.
- Metadata is best-effort within Append and no longer reports an error, so the
  samplesAppendedWithoutMetadata increment is dropped from the RW 2.x path (the
  metric stays registered and is still used by the RW 1.0 path). No test asserts
  this metric.
- remoteWriteAppenderV2.UpdateMetadata is removed as it is no longer used.

Note: exemplars/metadata are attached to the first sample/histogram, so if that
first append is rejected (e.g. an out-of-order first sample) they are dropped
with it; previously exemplars were appended in a separate pass. This only
affects that edge case.

A new test case exercises metadata stored via AppendV2Options (metadata storage
was previously not covered by the handler test).

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]>
@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