MCPcopy Index your code
hub / github.com/prometheus/prometheus / samplesV2

Method samplesV2

tsdb/record/record.go:376–419  ·  view source on GitHub ↗

samplesV2 appends samples in rec to the given slice using the V2 algorithm, which is more efficient and supports ST (See Encoder.samplesV2 definition).

(dec *encoding.Decbuf, samples []RefSample)

Source from the content-addressed store, hash-verified

374// samplesV2 appends samples in rec to the given slice using the V2 algorithm,
375// which is more efficient and supports ST (See Encoder.samplesV2 definition).
376func (*Decoder) samplesV2(dec *encoding.Decbuf, samples []RefSample) ([]RefSample, error) {
377 if dec.Len() == 0 {
378 return samples, nil
379 }
380 // Allow 1 byte for each varint and 8 for the value; the output slice must be at least that big.
381 if minSize := dec.Len() / (1 + 1 + 8); cap(samples) < minSize {
382 samples = make([]RefSample, 0, minSize)
383 }
384 var firstT, firstST int64
385 for len(dec.B) > 0 && dec.Err() == nil {
386 var prev RefSample
387 var ref, t, st int64
388 var val uint64
389
390 if len(samples) == 0 {
391 ref = dec.Varint64()
392 firstT = dec.Varint64()
393 t = firstT
394 st = dec.Varint64()
395 firstST = st
396 } else {
397 prev = samples[len(samples)-1]
398 ref = int64(prev.Ref) + dec.Varint64()
399 t = firstT + dec.Varint64()
400 st = readSTMarker(dec, prev.ST, firstST)
401 }
402
403 val = dec.Be64()
404 samples = append(samples, RefSample{
405 Ref: chunks.HeadSeriesRef(ref),
406 ST: st,
407 T: t,
408 V: math.Float64frombits(val),
409 })
410 }
411
412 if dec.Err() != nil {
413 return nil, fmt.Errorf("decode error after %d samples: %w", len(samples), dec.Err())
414 }
415 if len(dec.B) > 0 {
416 return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
417 }
418 return samples, nil
419}
420
421func readSTMarker(buf *encoding.Decbuf, prevST, firstST int64) int64 {
422 stMarker := buf.Byte()

Callers 1

SamplesMethod · 0.95

Calls 6

HeadSeriesRefTypeAlias · 0.92
readSTMarkerFunction · 0.85
Varint64Method · 0.80
Be64Method · 0.80
LenMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected