MCPcopy
hub / github.com/prometheus/prometheus / EncodeHistogram

Function EncodeHistogram

tsdb/record/record.go:1186–1224  ·  view source on GitHub ↗

EncodeHistogram encodes a Histogram into a byte slice. Handles both regular and custom bucket histograms.

(buf *encoding.Encbuf, h *histogram.Histogram)

Source from the content-addressed store, hash-verified

1184// EncodeHistogram encodes a Histogram into a byte slice. Handles both
1185// regular and custom bucket histograms.
1186func EncodeHistogram(buf *encoding.Encbuf, h *histogram.Histogram) {
1187 buf.PutByte(byte(h.CounterResetHint))
1188
1189 buf.PutVarint64(int64(h.Schema))
1190 buf.PutBE64(math.Float64bits(h.ZeroThreshold))
1191
1192 buf.PutUvarint64(h.ZeroCount)
1193 buf.PutUvarint64(h.Count)
1194 buf.PutBE64(math.Float64bits(h.Sum))
1195
1196 buf.PutUvarint(len(h.PositiveSpans))
1197 for _, s := range h.PositiveSpans {
1198 buf.PutVarint64(int64(s.Offset))
1199 buf.PutUvarint32(s.Length)
1200 }
1201
1202 buf.PutUvarint(len(h.NegativeSpans))
1203 for _, s := range h.NegativeSpans {
1204 buf.PutVarint64(int64(s.Offset))
1205 buf.PutUvarint32(s.Length)
1206 }
1207
1208 buf.PutUvarint(len(h.PositiveBuckets))
1209 for _, b := range h.PositiveBuckets {
1210 buf.PutVarint64(b)
1211 }
1212
1213 buf.PutUvarint(len(h.NegativeBuckets))
1214 for _, b := range h.NegativeBuckets {
1215 buf.PutVarint64(b)
1216 }
1217
1218 if histogram.IsCustomBucketsSchema(h.Schema) {
1219 buf.PutUvarint(len(h.CustomValues))
1220 for _, v := range h.CustomValues {
1221 buf.PutBEFloat64(v)
1222 }
1223 }
1224}
1225
1226// FloatHistogramSamples encodes exponential float histogram samples.
1227func (e *Encoder) FloatHistogramSamples(histograms []RefFloatHistogramSample, b []byte) ([]byte, []RefFloatHistogramSample) {

Callers 4

histogramSamplesV1Method · 0.85
histogramSamplesV2Method · 0.85

Calls 8

IsCustomBucketsSchemaFunction · 0.92
PutByteMethod · 0.80
PutVarint64Method · 0.80
PutBE64Method · 0.80
PutUvarint64Method · 0.80
PutUvarintMethod · 0.80
PutUvarint32Method · 0.80
PutBEFloat64Method · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…