Skip to content

feat(tsdb): allow using ST capable XOR chunks - set format on read#18026

Closed
krajorama wants to merge 2 commits into
feature/start-timefrom
krajo/st-opt-append-query
Closed

feat(tsdb): allow using ST capable XOR chunks - set format on read#18026
krajorama wants to merge 2 commits into
feature/start-timefrom
krajo/st-opt-append-query

Conversation

@krajorama

@krajorama krajorama commented Feb 5, 2026

Copy link
Copy Markdown
Member

Two big changes

  • Use the new XOROPTST chunk format optionally for appending samples
  • When compacting/querying chunks via the populateWithDelChunkSeriesIterator use the setting of the st-storage feature flag (or --st-storage flag for promtool) to decide what chunk encoding to use when re-coding chunks.

The second change is there to make sure we don't convert existing chunks to a new format accidentally.

Based on #17909.
Finishes #17791 for floats.

Which issue(s) does the PR fix:

Does this PR introduce a user-facing change?

NONE

Base automatically changed from krajo/st-in-xorchunk to feature/start-time February 6, 2026 18:28
@krajorama
krajorama marked this pull request as ready for review February 6, 2026 18:30
@krajorama
krajorama force-pushed the krajo/st-opt-append-query branch from 643cc12 to ac2cd89 Compare February 11, 2026 12:47
@krajorama

Copy link
Copy Markdown
Member Author

trivial rebase, no conflicts

@krajorama
krajorama force-pushed the krajo/st-opt-append-query branch from ac2cd89 to 33a08b3 Compare February 12, 2026 10:25
@krajorama
krajorama changed the base branch from feature/start-time to owilliams/st-wal February 12, 2026 10:25

@ywwg ywwg 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.

As you said, this is mostly adding bools and tests, with just a little uncontroversial logic changes. I have a couple questions, mostly around:

  • some of the code seems to imply that the st-storage-enabled setting could maybe change at run time, but I don't think we want that to be possible, so maybe those calls could be simplified? But I want to understand better
  • I don't quite understand the distinction between EncXOROptST and EncodingForFloatST and when one or the other is meant to be used.

Comment thread tsdb/chunkenc/chunk.go Outdated
Comment thread tsdb/block.go
Comment on lines +429 to +434
func (pb *Block) SetSTStorageEnabled(enabled bool) {
if cr, ok := pb.chunkr.(*chunks.Reader); ok {
cr.SetSTStorageEnabled(enabled)
}
}

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.

does this imply the setting could be changed at runtime, or is this only used during setup? I worry about keeping things consistent everywhere if the st storage setting could be changed while prometheus is already started up

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.

You cannot change feature flag in Prometheus on the fly, but this is for multi tenant derivatives like Cortex.

Comment thread tsdb/db.go
Comment on lines 818 to +822
block, err := OpenBlock(db.logger, filepath.Join(db.dir, blockID), nil, postingsDecoderFactory)
if err != nil {
return nil, err
}
block.SetSTStorageEnabled(db.stStorageEnabled)

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.

ok I guess this answers my question above. I guess, why is ststorage not a parameter on the openBlock call?

(one day I will refactor prometheus to use the .WithOption() pattern for object creation to avoid these long constructors)

Comment thread tsdb/db.go

db.mtx.RLock()
loadable, corrupted, err := openBlocks(db.logger, db.dir, db.blocks, db.chunkPool, db.opts.PostingsDecoderFactory)
loadable, corrupted, err := openBlocks(db.logger, db.dir, db.blocks, db.chunkPool, db.opts.PostingsDecoderFactory, db.opts.EnableSTStorage)

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.

like here it's an option on the open call...

Comment thread tsdb/head.go
// EnableSTStorage determines whether databases (WAL/WBL, tsdb,
// agent) should set a Start Time value per sample.
// Represents 'st-storage' feature flag.
EnableSTStorage atomic.Bool

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.

why did this become atomic?

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.

To be in line with the other settings that can be set per tenant.

Comment thread tsdb/head_append_v2_test.go Outdated
Base automatically changed from owilliams/st-wal to feature/start-time February 12, 2026 18:17
@krajorama

Copy link
Copy Markdown
Member Author

As you said, this is mostly adding bools and tests, with just a little uncontroversial logic changes. I have a couple questions, mostly around:

* some of the code seems to imply that the st-storage-enabled setting could maybe change at run time, but I don't think we want that to be possible, so maybe those calls could be simplified? But I want to understand better

I'm mindful of multi tenant implementations where you'd want this setting to be dynamic and also per DB (aka tenant).

* I don't quite understand the distinction between EncXOROptST and EncodingForFloatST and when one or the other is meant to be used.

You're right EncodingForFloatST is only for testing different encoding easily, I'll move it into it's own branch.

@krajorama
krajorama force-pushed the krajo/st-opt-append-query branch 2 times, most recently from 6a04151 to df77ed3 Compare February 16, 2026 08:43
Comment thread cmd/promtool/backfill.go
Comment thread scrape/manager.go Outdated
Comment thread scrape/scrape.go Outdated
ConvertClassicHistogramsToNHCB: sl.convertClassicHistToNHCB,
KeepClassicOnClassicAndNativeHistograms: sl.alwaysScrapeClassicHist,
OpenMetricsSkipSTSeries: sl.enableSTZeroIngestion,
OpenMetricsSkipSTSeries: sl.enableSTZeroIngestion || sl.enableSTStorage,

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.

Suggested change
OpenMetricsSkipSTSeries: sl.enableSTZeroIngestion || sl.enableSTStorage,
OpenMetricsSkipSTSeries: sl.enableSTZeroIngestion | | sl.parseST,

Comment thread scrape/scrape.go Outdated
Comment thread scrape/scrape_append_v2.go Outdated
Comment thread scrape/scrape_append_v2.go Outdated
@krajorama

Copy link
Copy Markdown
Member Author

This turned out to be a bit more complicated then the alternative #18013 . Putting it aside for now, we'll try the alternative.

@krajorama
krajorama marked this pull request as draft February 17, 2026 16:05
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Signed-off-by: György Krajcsovits <[email protected]>
@krajorama
krajorama force-pushed the krajo/st-opt-append-query branch from 67d4228 to 363e89b Compare February 17, 2026 16:26
@krajorama
krajorama changed the base branch from feature/start-time to bwplotka/scrape-parsest February 17, 2026 18:13
Base automatically changed from bwplotka/scrape-parsest to feature/start-time February 18, 2026 09:15
@krajorama

Copy link
Copy Markdown
Member Author

Alternative merged.

@krajorama krajorama closed this Feb 20, 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.

3 participants