MCPcopy
hub / github.com/prometheus/prometheus / floatHistogramSamplesV1

Method floatHistogramSamplesV1

tsdb/record/record.go:717–760  ·  view source on GitHub ↗

floatHistogramSamplesV1 decodes V1 float-histogram records (BE64 baseRef/baseTime, varint deltas).

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

Source from the content-addressed store, hash-verified

715
716// floatHistogramSamplesV1 decodes V1 float-histogram records (BE64 baseRef/baseTime, varint deltas).
717func (d *Decoder) floatHistogramSamplesV1(dec *encoding.Decbuf, histograms []RefFloatHistogramSample) ([]RefFloatHistogramSample, error) {
718 if dec.Len() == 0 {
719 return histograms, nil
720 }
721 var (
722 baseRef = dec.Be64()
723 baseTime = dec.Be64int64()
724 )
725 for len(dec.B) > 0 && dec.Err() == nil {
726 dref := dec.Varint64()
727 dtime := dec.Varint64()
728
729 rh := RefFloatHistogramSample{
730 Ref: chunks.HeadSeriesRef(baseRef + uint64(dref)),
731 T: baseTime + dtime,
732 FH: &histogram.FloatHistogram{},
733 }
734
735 DecodeFloatHistogram(dec, rh.FH)
736
737 if !histogram.IsKnownSchema(rh.FH.Schema) {
738 d.logger.Warn("skipping histogram with unknown schema in WAL record", "schema", rh.FH.Schema, "timestamp", rh.T)
739 continue
740 }
741 if rh.FH.Schema > histogram.ExponentialSchemaMax && rh.FH.Schema <= histogram.ExponentialSchemaMaxReserved {
742 // This is a very slow path, but it should only happen if the
743 // record is from a newer Prometheus version that supports higher
744 // resolution.
745 if err := rh.FH.ReduceResolution(histogram.ExponentialSchemaMax); err != nil {
746 return nil, fmt.Errorf("error reducing resolution of histogram #%d: %w", len(histograms)+1, err)
747 }
748 }
749
750 histograms = append(histograms, rh)
751 }
752
753 if dec.Err() != nil {
754 return nil, fmt.Errorf("decode error after %d histograms: %w", len(histograms), dec.Err())
755 }
756 if len(dec.B) > 0 {
757 return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B))
758 }
759 return histograms, nil
760}
761
762// floatHistogramSamplesV2 decodes V2 float-histogram records.
763func (d *Decoder) floatHistogramSamplesV2(dec *encoding.Decbuf, histograms []RefFloatHistogramSample) ([]RefFloatHistogramSample, error) {

Callers 1

FloatHistogramSamplesMethod · 0.95

Calls 9

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

Tested by

no test coverage detected