Repository navigation
Conversation
c8fbef3 to
89ef560
Compare
7b881d7 to
3dc06b2
Compare
|
|
||
| allSamplesSoFar := rs.AllSamples() | ||
| var ref storage.SeriesRef | ||
| // Attach metadata to the first sample/histogram append of the series only; if that |
There was a problem hiding this comment.
I think we attach to all which is likely fine - (cause we typically have a single sample) - and if we update for multiple it's deduped. Comment is lying ?
There was a problem hiding this comment.
There's a line later to clear the whole options struct, so the comment is correct. On the other hand it makes little sense to actually do this now without exemplars. Removing the reset.
Port the RW 1.0 receiver path (writeHandler.write) from V1 storage.Appender to storage.AppenderV2. Since AppenderV2 makes AppendExemplars mandatory, the receiver can call it directly (batched, one call per series) without any capability-detection dance. Metadata is unused by RW 1.0's per-series path, so no metadata plumbing is added. NewWriteHandler now also takes an appendableV2; the Remote Write 2.x path (writeV2) still uses the V1 appendable until it is migrated separately. Part of #17632. Signed-off-by: György Krajcsovits <[email protected]>
Port the Remote Write 2.x receiver path (writeHandler.writeV2 / appendV2) from V1 storage.Appender to storage.AppenderV2, matching the RW 1.0 path. - Start timestamps are now passed directly as the AppenderV2.Append st parameter; the appender owns ST zero-sample injection, so the explicit AppendSTZeroSample / AppendHistogramSTZeroSample calls (and the handleHistogramZeroSample helper) are removed. The receiver still gates on ingestSTZeroSample, preserving prior behaviour. - Metadata is attached via AppendV2Options.Metadata on the first sample/histogram append of each series; if that append is rejected, metadata is dropped with it. It is best-effort: Append no longer reports metadata errors, so samplesAppendedWithoutMetadata is no longer incremented on this path (the metric stays registered and is still used by the RW 1.0 path). - Exemplars are collected per series, sorted by timestamp, and appended in one batched AppendExemplars call instead of a per-exemplar loop. Out-of-order exemplars still map to a 400; other exemplar errors remain a no-op, preserving prior behaviour. With both RW 1.0 and 2.x on AppenderV2, the V1 appendable is no longer used by the receiver: NewWriteHandler drops its storage.Appendable parameter and the now-dead remoteWriteAppender wrapper is removed. Part of #17632. Signed-off-by: György Krajcsovits <[email protected]>
Match the errors.AsType convention adopted for AppendPartialError detection elsewhere in the codebase now that go.mod requires Go 1.26. Signed-off-by: György Krajcsovits <[email protected]>
Previously metadata was only attached to the first sample/histogram Append of a series, cleared to empty options right after (success or failure). If that first append was rejected (e.g. out-of-order), the whole request silently dropped metadata for that series, even if a later sample/histogram in the same request succeeded. Attach it on every append instead. AppenderV2 implementations already persist a metadata WAL record only when it actually changed (see head_append_v2.go's metaChanged check), so this costs a cheap comparison per extra sample and closes the drop-on-first-reject gap for free. Signed-off-by: György Krajcsovits <[email protected]>
Signed-off-by: György Krajcsovits <[email protected]>
401f988 to
90b9063
Compare
| } | ||
| if !opts.Metadata.IsEmpty() { | ||
| // Metadata is best-effort within Append; errors are not surfaced to the caller. | ||
| _, _ = a.asV1().UpdateMetadata(ref, l, opts.Metadata) |
| } | ||
| // AppendExemplars requires exemplars sorted by timestamp. | ||
| slices.SortFunc(exemplars, exemplar.Compare) | ||
| if _, err := app.AppendExemplars(ref, ls, exemplars); err != nil { |
There was a problem hiding this comment.
In PRW 1.0, if a series only has native histograms and exemplars without float samples, ref is 0 and the series does not exist yet in TSDB Head, causing AppendExemplars to fail and silently drop them. Should we run appendV1Histograms before AppendExemplars like appendV2 does?
| } | ||
|
|
||
| func (h *writeHandler) appendV2(app storage.Appender, req *writev2.Request, rs *remoteapi.WriteResponseStats) (samplesWithoutMetadata, errHTTPCode int, err error) { | ||
| func (h *writeHandler) appendV2(app *remoteWriteAppenderV2, req *writev2.Request, rs *remoteapi.WriteResponseStats) (samplesWithoutMetadata, errHTTPCode int, err error) { |
There was a problem hiding this comment.
Could this accept storage.AppenderV2 instead of *remoteWriteAppenderV2 to match appendV1Samples and appendV1Histograms?
| func (h *writeHandler) appendV2(app *remoteWriteAppenderV2, req *writev2.Request, rs *remoteapi.WriteResponseStats) (samplesWithoutMetadata, errHTTPCode int, err error) { | |
| func (h *writeHandler) appendV2(app storage.AppenderV2, req *writev2.Request, rs *remoteapi.WriteResponseStats) (samplesWithoutMetadata, errHTTPCode int, err error) { |
| // of the series; implementations only persist a metadata WAL record when it changed. | ||
| opts := storage.AOptions{} | ||
| if h.appendMetadata { | ||
| opts.Metadata = m |
There was a problem hiding this comment.
In Head (headAppenderV2.Append), metaChanged checks s.meta, which is only updated on commit. For any new series or metadata change with multiple samples in a request, every sample evaluates metaChanged == true, acquiring the lock and writing duplicate metadata WAL records. Maybe clear opts.Metadata once an append succeeds so subsequent samples in the series skip it?
| } | ||
|
|
||
| ref, err = app.Append(ref, ls, s.GetTimestamp(), s.GetValue()) | ||
| ref, err = app.Append(ref, ls, st, s.GetTimestamp(), s.GetValue(), nil, nil, opts) |
There was a problem hiding this comment.
If an append fails with an out-of-order or duplicate error, app.Append returns (0, err), resetting ref to 0 for subsequent samples and exemplars in the series. Maybe only update ref on success?
| if pErr, ok := errors.AsType[*storage.AppendPartialError](err); ok { | ||
| appended -= len(pErr.ExemplarErrors) | ||
| for _, eErr := range pErr.ExemplarErrors { | ||
| if errors.Is(eErr, storage.ErrOutOfOrderExemplar) { |
There was a problem hiding this comment.
ErrOutOfBounds from AppendExemplars falls through to the error log and is dropped without failing the request. Should we also check errors.Is(eErr, storage.ErrOutOfBounds) here so out-of-bounds exemplars return 400 bad request like samples and histograms do?
| if err := fh.ReduceResolution(histogram.ExponentialSchemaMax); err != nil { | ||
| return 0, err | ||
| } | ||
| ref, err := app.AppenderV2.AppendExemplars(ref, ls, valid) |
There was a problem hiding this comment.
If all exemplars were in the future (len(valid) == 0), delegating to AppendExemplars causes Head to return (0, nil) which clobbers ref to 0. Maybe return early if len(valid) == 0?
| expectedCode: http.StatusNoContent, | ||
| enableTypeAndUnitLabels: false, | ||
| appendMetadata: true, | ||
| expectedLabels: labels.FromStrings("__name__", "test_metric_wal", "instance", "localhost"), |
There was a problem hiding this comment.
Because expectedLabels is set, this test case hits the early return at line 805 and skips the appendable.metadata assertions at lines 862-867. We should assert appendable.metadata here so metadata storage via opts.Metadata is actually verified.
|
Closed in favor of #19812 |
Part of #17632. Stacked on top of #19455 (mandatory, batched
AppendExemplars) — base branch iskrajo/appenderv2-mandatory-exemplars.What
Both Remote Write receiver paths are ported from V1
storage.Appendertostorage.AppenderV2:writeHandler.write(RW 1.0)writeHandler.writeV2/appendV2(RW 2.x)This was originally split into two stacked PRs (#19457 for RW 1.0, #19459 for RW 2.x) because RW 2.x's exemplars didn't have an obvious home under the old, optional
ExemplarAppenderV2capability design. Since #19455 madeAppendExemplarsmandatory and batched, that reason to split no longer applies, so both migrations are combined here. #19459 is superseded by this PR.RW 1.0 (
write)Since
AppendExemplarsis mandatory onAppenderV2, the receiver just callsapp.AppendExemplars(ref, ls, exemplars)directly — no capability-bundle interface, no type assertion, no "does this appender support exemplars" error path. Metadata is untouched: RW 1.0's per-series path never calledUpdateMetadataeven before this change (confirmed by inspection), so there's nothing to wire up.RW 2.x (
writeV2/appendV2)AppenderV2.Appendstparameter; the appender owns ST zero-sample injection, so the explicitAppendSTZeroSample/AppendHistogramSTZeroSamplecalls (and thehandleHistogramZeroSamplehelper) are removed. The receiver still gates oningestSTZeroSample, preserving prior behaviour.AppendV2Options.Metadataon every sample/histogram append of a series (not just the first) — it's best-effort andAppendno longer reports metadata errors, sosamplesAppendedWithoutMetadatais no longer incremented on this path (the metric stays registered and is still used by the RW 1.0 path).AppenderV2implementations (e.g. TSDB head) only persist a metadata WAL record when it actually changed, so attaching it on every append instead of just the first is a cheap no-op in the common case, and closes a gap where a rejected first sample would otherwise silently drop metadata for the whole series in that request.AppendExemplars's contract), and appended in one batchedAppendExemplarscall instead of a per-exemplar loop. Out-of-order exemplars still map to a 400; other exemplar errors remain a no-op — preserving prior behaviour.Both paths
With both RW 1.0 and 2.x on
AppenderV2, the V1 appendable is no longer used by the receiver at all:NewWriteHandlerdrops itsstorage.Appendableparameter entirely, and the now-deadremoteWriteAppenderwrapper is removed.Also includes a small
errors.As→errors.AsTypemodernization to match the Go 1.26 baselinemainpicked up during rebase.Tests
mockAppenderV2.Appendmirrors what a realAppenderV2implementation does internally: it injects the ST zero-sample (via the existing V1 mock methods) whenst != 0, and records metadata viaopts.Metadatawhen present — both best-effort, matching production semantics.AppendV2Options(appendMetadata: true), which wasn't previously covered — the existing table only tested the disabled case.mockAppendablegained anAppenderV2method reusing the existing V1 recording/error-injection methods (AppendHistogram,AppendExemplar,Commit,Rollback) since their signatures are compatible, so existing assertions on the mock's recorded slices hold unchanged.