MCPcopy
hub / github.com/prometheus/prometheus / samplesV2

Method samplesV2

tsdb/record/record.go:971–1000  ·  view source on GitHub ↗

samplesV2 appends the encoded samples to b and returns the resulting slice using a more efficient per-sample delta encoding and allows for ST storage.

(samples []RefSample, b []byte)

Source from the content-addressed store, hash-verified

969// using a more efficient per-sample delta encoding and allows for ST
970// storage.
971func (*Encoder) samplesV2(samples []RefSample, b []byte) []byte {
972 buf := encoding.Encbuf{B: b}
973 buf.PutByte(byte(SamplesV2))
974
975 if len(samples) == 0 {
976 return buf.Get()
977 }
978
979 // Store first ref, timestamp, ST, and value.
980 first := samples[0]
981 buf.PutVarint64(int64(first.Ref))
982 buf.PutVarint64(first.T)
983 buf.PutVarint64(first.ST)
984 buf.PutBE64(math.Float64bits(first.V))
985
986 // Subsequent values are delta to the immediate previous values, and in the
987 // case of start timestamp, use the marker byte to indicate what the value should
988 // be if it's one of the trivial cases.
989 for i := 1; i < len(samples); i++ {
990 s := samples[i]
991 prev := samples[i-1]
992
993 buf.PutVarint64(int64(s.Ref) - int64(prev.Ref))
994 buf.PutVarint64(s.T - first.T)
995
996 writeSTMarker(&buf, s.ST, first.ST, prev.ST)
997 buf.PutBE64(math.Float64bits(s.V))
998 }
999 return buf.Get()
1000}
1001
1002func writeSTMarker(buf *encoding.Encbuf, st, firstST, prevST int64) {
1003 switch st {

Callers 1

SamplesMethod · 0.95

Calls 5

PutByteMethod · 0.95
GetMethod · 0.95
PutVarint64Method · 0.95
PutBE64Method · 0.95
writeSTMarkerFunction · 0.85

Tested by

no test coverage detected