Repository navigation
tsdb/chunkenc: take a generic Appender as the prev parameter - #18857
Merged
Merged
Conversation
The chunkenc.Appender interface's AppendHistogram and AppendFloatHistogram methods used to require a typed previous appender (*HistogramAppender or *FloatHistogramAppender). Callers were forced to type-assert s.app to that concrete type before each call, discarding it (and the cross-chunk counter-reset signal it carries) whenever the actual concrete type didn't match -- for example when a chunk used a different histogram encoding. Change the signature to accept the generic chunkenc.Appender interface and move the concrete-type check inside each implementation, onto the code path that actually needs the previous appender's state (the new-chunk branch where setCounterResetHeader runs). The check goes through small private interfaces -- histogramAppendable and floatHistogramAppendable -- so any appender type that exposes the appropriate appendable() method can serve as prev, and types that don't (xor, xor2, or a histogram appender on the opposite-kind code path) are silently ignored. This prepares the ground for #18609, which introduces *HistogramSTAppender and *FloatHistogramSTAppender. Both embed their non-ST counterparts and will satisfy the new interfaces automatically, so they can be passed as prev without a special case in the caller. Callers in tsdb/head_append.go and tsdb/ooo_head.go are simplified accordingly. The Appender consumers in storage/series.go and tsdb/querier.go were already passing nil and continue to do so unchanged. Signed-off-by: György Krajcsovits <[email protected]>
krajorama
force-pushed
the
chunkenc/generic-appender-prev
branch
from
June 8, 2026 11:00
9ab4029 to
51d2458
Compare
krajorama
marked this pull request as ready for review
June 8, 2026 11:00
krajorama
requested review from
a team,
bwplotka,
codesome and
jesusvazquez
as code owners
June 8, 2026 11:00
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.
Summary
Today the
chunkenc.Appenderinterface'sAppendHistogramandAppendFloatHistogrammethods take a typed previous appender (*HistogramAppender/*FloatHistogramAppender). Callers must type-asserts.appto that concrete type before every call, and silently discard the cross-chunk counter-reset signal whenever the running chunk happens to be a different concrete histogram-appender type.This PR changes the parameter to the generic
chunkenc.Appenderinterface and moves the concrete type check inside each implementation, onto the code path that actually needs the previous appender's state (the new-chunk branch insetCounterResetHeader). The type check goes through two new private interfaces (histogramAppendable,floatHistogramAppendable); any appender that exposes the rightappendable()method satisfies them, and any appender that doesn't is silently ignored.The cost of the type assertion is paid only on the new-chunk branch — i.e. once per chunk boundary, not per sample.
Motivation
Preparation for #18609, which introduces
*HistogramSTAppenderand*FloatHistogramSTAppender. Both embed their non-ST counterparts, so they automatically satisfy the new internal interfaces and can be handed off asprevwithout any caller-side knowledge of the ST variant.It also removes a small foot-gun: the current
prev, _ := s.app.(*chunkenc.HistogramAppender)discards the cross-chunk reset signal whenevers.appis any other concrete type (e.g. an xor chunk that's about to be followed by a histogram chunk, or — once #18609 lands — a*HistogramSTAppender).Diff shape
tsdb/chunkenc/appendable.go(new):histogramAppendable/floatHistogramAppendableinterfaces.tsdb/chunkenc/chunk.go:Appender.AppendHistogram/AppendFloatHistogramtakeprev Appender.tsdb/chunkenc/{histogram,float_histogram}.go: the new-chunk branch type-asserts to the appropriate appendable interface.tsdb/chunkenc/{xor,xor2,histogram,float_histogram}.go: panic stubs for cross-kind appends updated to the new signature.tsdb/{head_append,ooo_head}.go: drop the pre-call type assertion; passs.app(orprevApp) through aschunkenc.Appender.storage/series.goandtsdb/querier.goalready passnilforprevand are unaffected.Test plan
go build ./...go vet ./tsdb/...go test ./tsdb/...— all packages green (full suite, no-short).tsdb/ooo_head.gofor the ST chunk types (follow-up).Coded with Claude Opus 4.7.