MCPcopy
hub / github.com/prometheus/prometheus / histogramSamplesV2

Method histogramSamplesV2

tsdb/record/record.go:1120–1149  ·  view source on GitHub ↗

histogramSamplesV2 encodes the given histogram samples.

(histograms []RefHistogramSample, b []byte)

Source from the content-addressed store, hash-verified

1118
1119// histogramSamplesV2 encodes the given histogram samples.
1120func (*Encoder) histogramSamplesV2(histograms []RefHistogramSample, b []byte) []byte {
1121 buf := encoding.Encbuf{B: b}
1122 buf.PutByte(byte(HistogramSamplesV2))
1123
1124 if len(histograms) == 0 {
1125 return buf.Get()
1126 }
1127
1128 var first, prev *RefHistogramSample
1129 for _, h := range histograms {
1130 if first == nil {
1131 first = &h
1132 buf.PutVarint64(int64(first.Ref))
1133 buf.PutVarint64(first.T)
1134 buf.PutVarint64(first.ST)
1135 prev = first
1136 EncodeHistogram(&buf, h.H)
1137 continue
1138 }
1139
1140 buf.PutVarint64(int64(h.Ref) - int64(prev.Ref))
1141 buf.PutVarint64(h.T - first.T)
1142
1143 writeSTMarker(&buf, h.ST, first.ST, prev.ST)
1144 EncodeHistogram(&buf, h.H)
1145 prev = &h
1146 }
1147
1148 return buf.Get()
1149}
1150
1151// CustomBucketsHistogramSamples appends the encoded custom-bucket histogram
1152// samples to b and returns the resulting slice.

Callers 2

HistogramSamplesMethod · 0.95

Calls 5

PutByteMethod · 0.95
GetMethod · 0.95
PutVarint64Method · 0.95
EncodeHistogramFunction · 0.85
writeSTMarkerFunction · 0.85

Tested by

no test coverage detected