MCPcopy
hub / github.com/prometheus/prometheus / TestHeadAppender_STStorage_ChunkEncoding

Function TestHeadAppender_STStorage_ChunkEncoding

tsdb/head_test.go:8289–8356  ·  view source on GitHub ↗

TestHeadAppender_STStorage_ChunkEncoding verifies that the correct chunk encoding is used based on EnableSTStorage setting.

(t *testing.T)

Source from the content-addressed store, hash-verified

8287// TestHeadAppender_STStorage_ChunkEncoding verifies that the correct chunk encoding
8288// is used based on EnableSTStorage setting.
8289func TestHeadAppender_STStorage_ChunkEncoding(t *testing.T) {
8290 samples := []struct {
8291 st int64
8292 ts int64
8293 fSample float64
8294 }{
8295 {st: 10, ts: 100, fSample: 1.0},
8296 {st: 20, ts: 200, fSample: 2.0},
8297 }
8298
8299 for _, enableST := range []bool{false, true} {
8300 t.Run(fmt.Sprintf("EnableSTStorage=%t", enableST), func(t *testing.T) {
8301 opts := newTestHeadDefaultOptions(DefaultBlockDuration, false)
8302 opts.EnableSTStorage.Store(enableST)
8303 if enableST {
8304 opts.FloatChunkEncoding.Store(uint32(chunkenc.EncXOR2))
8305 } else {
8306 opts.FloatChunkEncoding.Store(uint32(chunkenc.EncXOR))
8307 }
8308 h, _ := newTestHeadWithOptions(t, compression.None, opts)
8309
8310 lbls := labels.FromStrings("foo", "bar")
8311 a := h.Appender(context.Background())
8312 for _, s := range samples {
8313 _, err := a.AppendSTZeroSample(0, lbls, s.ts, s.st)
8314 require.NoError(t, err)
8315 _, err = a.Append(0, lbls, s.ts, s.fSample)
8316 require.NoError(t, err)
8317 }
8318 require.NoError(t, a.Commit())
8319
8320 ctx := context.Background()
8321 idxReader, err := h.Index()
8322 require.NoError(t, err)
8323 defer idxReader.Close()
8324
8325 chkReader, err := h.Chunks()
8326 require.NoError(t, err)
8327 defer chkReader.Close()
8328
8329 p, err := idxReader.Postings(ctx, "foo", "bar")
8330 require.NoError(t, err)
8331
8332 var lblBuilder labels.ScratchBuilder
8333 require.True(t, p.Next())
8334 sRef := p.At()
8335
8336 var chkMetas []chunks.Meta
8337 require.NoError(t, idxReader.Series(sRef, &lblBuilder, &chkMetas))
8338 require.NotEmpty(t, chkMetas)
8339
8340 for _, meta := range chkMetas {
8341 chk, iterable, err := chkReader.ChunkOrIterable(meta)
8342 require.NoError(t, err)
8343 require.Nil(t, iterable)
8344
8345 encoding := chk.Encoding()
8346 if enableST {

Callers

nothing calls this directly

Calls 15

FromStringsFunction · 0.92
newTestHeadWithOptionsFunction · 0.85
RunMethod · 0.65
StoreMethod · 0.65
AppenderMethod · 0.65
AppendSTZeroSampleMethod · 0.65
AppendMethod · 0.65
CommitMethod · 0.65
IndexMethod · 0.65
CloseMethod · 0.65
ChunksMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…