MCPcopy
hub / github.com/prometheus/prometheus / floatHistogramSamplesV2

Method floatHistogramSamplesV2

tsdb/record/record.go:763–817  ·  view source on GitHub ↗

floatHistogramSamplesV2 decodes V2 float-histogram records.

(dec *encoding.Decbuf, histograms []RefFloatHistogramSample)

Source from the content-addressed store, hash-verified

761
762// floatHistogramSamplesV2 decodes V2 float-histogram records.
763func (d *Decoder) floatHistogramSamplesV2(dec *encoding.Decbuf, histograms []RefFloatHistogramSample) ([]RefFloatHistogramSample, error) {
764 if dec.Len() == 0 {
765 return histograms, nil
766 }
767 firstRef := chunks.HeadSeriesRef(dec.Varint64())
768 firstT := dec.Varint64()
769 firstST := dec.Varint64()
770 var prevRef chunks.HeadSeriesRef
771 var prevST int64
772 hasPrev := false
773
774 for len(dec.B) > 0 && dec.Err() == nil {
775 var ref, t, st int64
776 if !hasPrev {
777 ref, t, st = int64(firstRef), firstT, firstST
778 hasPrev = true
779 } else {
780 ref = int64(prevRef) + dec.Varint64()
781 t = firstT + dec.Varint64()
782 st = readSTMarker(dec, prevST, firstST)
783 }
784
785 rfh := RefFloatHistogramSample{
786 Ref: chunks.HeadSeriesRef(ref),
787 ST: st,
788 T: t,
789 FH: &histogram.FloatHistogram{},
790 }
791 prevRef, prevST = rfh.Ref, rfh.ST
792 DecodeFloatHistogram(dec, rfh.FH)
793
794 if !histogram.IsKnownSchema(rfh.FH.Schema) {
795 d.logger.Warn("skipping histogram with unknown schema in WAL record", "schema", rfh.FH.Schema, "timestamp", rfh.T)
796 continue
797 }
798 if rfh.FH.Schema > histogram.ExponentialSchemaMax && rfh.FH.Schema <= histogram.ExponentialSchemaMaxReserved {
799 // This is a very slow path, but it should only happen if the
800 // record is from a newer Prometheus version that supports higher
801 // resolution.
802 if err := rfh.FH.ReduceResolution(histogram.ExponentialSchemaMax); err != nil {
803 return nil, fmt.Errorf("error reducing resolution of histogram #%d: %w", len(histograms)+1, err)
804 }
805 }
806
807 histograms = append(histograms, rfh)
808 }
809
810 if dec.Err() != nil {
811 return nil, fmt.Errorf("decode error after %d histograms: %w", len(histograms), dec.Err())
812 }
813 if len(dec.B) > 0 {
814 return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
815 }
816 return histograms, nil
817}
818
819// DecodeFloatHistogram decodes a FloatHistogram from buf.
820func DecodeFloatHistogram(buf *encoding.Decbuf, fh *histogram.FloatHistogram) {

Callers 1

FloatHistogramSamplesMethod · 0.95

Calls 8

HeadSeriesRefTypeAlias · 0.92
IsKnownSchemaFunction · 0.92
readSTMarkerFunction · 0.85
DecodeFloatHistogramFunction · 0.85
Varint64Method · 0.80
LenMethod · 0.65
ErrMethod · 0.65
ReduceResolutionMethod · 0.45

Tested by

no test coverage detected