MCPcopy
hub / github.com/prometheus/prometheus / histogramSamplesV1

Method histogramSamplesV1

tsdb/record/record.go:1085–1117  ·  view source on GitHub ↗
(histograms []RefHistogramSample, b []byte)

Source from the content-addressed store, hash-verified

1083}
1084
1085func (*Encoder) histogramSamplesV1(histograms []RefHistogramSample, b []byte) ([]byte, []RefHistogramSample) {
1086 buf := encoding.Encbuf{B: b}
1087 buf.PutByte(byte(HistogramSamples))
1088
1089 if len(histograms) == 0 {
1090 return buf.Get(), nil
1091 }
1092 var customBucketHistograms []RefHistogramSample
1093
1094 // Store base timestamp and base reference number of first histogram.
1095 // All histograms encode their timestamp and ref as delta to those.
1096 first := histograms[0]
1097 buf.PutBE64(uint64(first.Ref))
1098 buf.PutBE64int64(first.T)
1099
1100 for _, h := range histograms {
1101 if h.H.UsesCustomBuckets() {
1102 customBucketHistograms = append(customBucketHistograms, h)
1103 continue
1104 }
1105 buf.PutVarint64(int64(h.Ref) - int64(first.Ref))
1106 buf.PutVarint64(h.T - first.T)
1107
1108 EncodeHistogram(&buf, h.H)
1109 }
1110
1111 // Reset buffer if only custom bucket histograms existed in list of histogram samples.
1112 if len(histograms) == len(customBucketHistograms) {
1113 buf.Reset()
1114 }
1115
1116 return buf.Get(), customBucketHistograms
1117}
1118
1119// histogramSamplesV2 encodes the given histogram samples.
1120func (*Encoder) histogramSamplesV2(histograms []RefHistogramSample, b []byte) []byte {

Callers 1

HistogramSamplesMethod · 0.95

Calls 8

PutByteMethod · 0.95
GetMethod · 0.95
PutBE64Method · 0.95
PutBE64int64Method · 0.95
PutVarint64Method · 0.95
ResetMethod · 0.95
EncodeHistogramFunction · 0.85
UsesCustomBucketsMethod · 0.45

Tested by

no test coverage detected