record

package
v0.311.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 59

Documentation

Overview

Package record contains the various record types used for encoding various Head block data in the WAL and in-memory snapshot.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned if a looked up resource was not found. Duplicate ErrNotFound from head.go.

Functions

func DecodeFloatHistogram added in v0.46.0

func DecodeFloatHistogram(buf *encoding.Decbuf, fh *histogram.FloatHistogram)

DecodeFloatHistogram decodes a Histogram from a byte slice.

func DecodeHistogram added in v0.46.0

func DecodeHistogram(buf *encoding.Decbuf, h *histogram.Histogram)

DecodeHistogram decodes a Histogram from a byte slice.

func EncodeFloatHistogram added in v0.46.0

func EncodeFloatHistogram(buf *encoding.Encbuf, h *histogram.FloatHistogram)

EncodeFloatHistogram encodes the Float Histogram into a byte slice.

func EncodeHistogram added in v0.46.0

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

EncodeHistogram encodes a Histogram into a byte slice.

func EncodeLabels added in v0.38.0

func EncodeLabels(buf *encoding.Encbuf, lbls labels.Labels)

EncodeLabels encodes the contents of labels into buf.

func GetMetricType added in v0.38.0

func GetMetricType(t model.MetricType) uint8

func ToMetricType added in v0.50.0

func ToMetricType(m uint8) model.MetricType

Types

type BuffersPool added in v0.311.0

type BuffersPool struct {
	// contains filtered or unexported fields
}

BuffersPool offers pool of zero-ed record buffers.

func NewBuffersPool added in v0.311.0

func NewBuffersPool() *BuffersPool

NewBuffersPool returns a new BuffersPool object.

func (*BuffersPool) GetExemplars added in v0.311.0

func (p *BuffersPool) GetExemplars(capacity int) []RefExemplar

func (*BuffersPool) GetFloatHistograms added in v0.311.0

func (p *BuffersPool) GetFloatHistograms(capacity int) []RefFloatHistogramSample

func (*BuffersPool) GetHistograms added in v0.311.0

func (p *BuffersPool) GetHistograms(capacity int) []RefHistogramSample

func (*BuffersPool) GetMetadata added in v0.311.0

func (p *BuffersPool) GetMetadata(capacity int) []RefMetadata

func (*BuffersPool) GetRefSeries added in v0.311.0

func (p *BuffersPool) GetRefSeries(capacity int) []RefSeries

func (*BuffersPool) GetSamples added in v0.311.0

func (p *BuffersPool) GetSamples(capacity int) []RefSample

func (*BuffersPool) PutExemplars added in v0.311.0

func (p *BuffersPool) PutExemplars(b []RefExemplar)

func (*BuffersPool) PutFloatHistograms added in v0.311.0

func (p *BuffersPool) PutFloatHistograms(b []RefFloatHistogramSample)

func (*BuffersPool) PutHistograms added in v0.311.0

func (p *BuffersPool) PutHistograms(b []RefHistogramSample)

func (*BuffersPool) PutMetadata added in v0.311.0

func (p *BuffersPool) PutMetadata(b []RefMetadata)

func (*BuffersPool) PutRefSeries added in v0.311.0

func (p *BuffersPool) PutRefSeries(b []RefSeries)

func (*BuffersPool) PutSamples added in v0.311.0

func (p *BuffersPool) PutSamples(b []RefSample)

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes series, sample, metadata and tombstone records.

func NewDecoder added in v0.51.0

func NewDecoder(_ *labels.SymbolTable, logger *slog.Logger) Decoder

func (*Decoder) DecodeLabels added in v0.38.0

func (d *Decoder) DecodeLabels(dec *encoding.Decbuf) labels.Labels

DecodeLabels decodes one set of labels from buf.

func (*Decoder) Exemplars

func (d *Decoder) Exemplars(rec []byte, exemplars []RefExemplar) ([]RefExemplar, error)

func (*Decoder) ExemplarsFromBuffer

func (d *Decoder) ExemplarsFromBuffer(dec *encoding.Decbuf, exemplars []RefExemplar) ([]RefExemplar, error)

func (*Decoder) FloatHistogramSamples added in v0.42.0

func (d *Decoder) FloatHistogramSamples(rec []byte, histograms []RefFloatHistogramSample) ([]RefFloatHistogramSample, error)

func (*Decoder) HistogramSamples added in v0.40.0

func (d *Decoder) HistogramSamples(rec []byte, histograms []RefHistogramSample) ([]RefHistogramSample, error)

func (*Decoder) Metadata added in v0.38.0

func (*Decoder) Metadata(rec []byte, metadata []RefMetadata) ([]RefMetadata, error)

Metadata appends metadata in rec to the given slice.

func (*Decoder) MmapMarkers added in v0.39.0

func (*Decoder) MmapMarkers(rec []byte, markers []RefMmapMarker) ([]RefMmapMarker, error)

func (*Decoder) Samples

func (d *Decoder) Samples(rec []byte, samples []RefSample) ([]RefSample, error)

Samples appends samples in rec to the given slice.

func (*Decoder) Series

func (d *Decoder) Series(rec []byte, series []RefSeries) ([]RefSeries, error)

Series appends series in rec to the given slice.

func (*Decoder) Tombstones

func (*Decoder) Tombstones(rec []byte, tstones []tombstones.Stone) ([]tombstones.Stone, error)

Tombstones appends tombstones in rec to the given slice.

func (*Decoder) Type

func (*Decoder) Type(rec []byte) Type

Type returns the type of the record. Returns RecordUnknown if no valid record type is found.

type Encoder

type Encoder struct {
	// EnableSTStorage enables the SamplesV2 encoding, which is more efficient
	// than V1 and supports start time per sample.
	EnableSTStorage bool
}

Encoder encodes series, sample, and tombstones records. The zero value is ready to use.

func (*Encoder) CustomBucketsFloatHistogramSamples added in v0.302.0

func (*Encoder) CustomBucketsFloatHistogramSamples(histograms []RefFloatHistogramSample, b []byte) []byte

CustomBucketsFloatHistogramSamples encodes given float histograms as custom bucket float histograms.

func (*Encoder) CustomBucketsHistogramSamples added in v0.302.0

func (*Encoder) CustomBucketsHistogramSamples(histograms []RefHistogramSample, b []byte) []byte

CustomBucketsHistogramSamples encodes given histograms as custom bucket histograms.

func (*Encoder) EncodeExemplarsIntoBuffer

func (*Encoder) EncodeExemplarsIntoBuffer(exemplars []RefExemplar, buf *encoding.Encbuf)

func (*Encoder) Exemplars

func (e *Encoder) Exemplars(exemplars []RefExemplar, b []byte) []byte

func (*Encoder) FloatHistogramSamples added in v0.42.0

func (*Encoder) FloatHistogramSamples(histograms []RefFloatHistogramSample, b []byte) ([]byte, []RefFloatHistogramSample)

FloatHistogramSamples encode exponential float histograms while returning all the excluded custom bucket float histograms. Callers can encode the returned custom bucket float histograms via CustomBucketsFloatHistogramSamples.

func (*Encoder) HistogramSamples added in v0.40.0

func (*Encoder) HistogramSamples(histograms []RefHistogramSample, b []byte) ([]byte, []RefHistogramSample)

HistogramSamples encode exponential histograms while returning all the excluded custom bucket histograms. Callers can encode the returned custom bucket histograms via CustomBucketsHistogramSamples.

func (*Encoder) Metadata added in v0.38.0

func (*Encoder) Metadata(metadata []RefMetadata, b []byte) []byte

Metadata appends the encoded metadata to b and returns the resulting slice.

func (*Encoder) MmapMarkers added in v0.39.0

func (*Encoder) MmapMarkers(markers []RefMmapMarker, b []byte) []byte

func (*Encoder) Samples

func (e *Encoder) Samples(samples []RefSample, b []byte) []byte

Samples appends the encoded samples to b and returns the resulting slice. Depending on the ST existence it either writes Samples or SamplesWithST record.

func (*Encoder) Series

func (*Encoder) Series(series []RefSeries, b []byte) []byte

Series appends the encoded series to b and returns the resulting slice.

func (*Encoder) Tombstones

func (*Encoder) Tombstones(tstones []tombstones.Stone, b []byte) []byte

Tombstones appends the encoded tombstones to b and returns the resulting slice.

type MetricType added in v0.38.0

type MetricType uint8

MetricType represents the type of a series.

const (
	UnknownMT       MetricType = 0
	Counter         MetricType = 1
	Gauge           MetricType = 2
	HistogramSample MetricType = 3
	GaugeHistogram  MetricType = 4
	Summary         MetricType = 5
	Info            MetricType = 6
	Stateset        MetricType = 7
)

type RefExemplar

type RefExemplar struct {
	Ref    chunks.HeadSeriesRef
	T      int64
	V      float64
	Labels labels.Labels
}

RefExemplar is an exemplar with the labels, timestamp, value the exemplar was collected/observed with, and a reference to a series.

type RefFloatHistogramSample added in v0.42.0

type RefFloatHistogramSample struct {
	Ref chunks.HeadSeriesRef
	T   int64
	FH  *histogram.FloatHistogram
}

RefFloatHistogramSample is a float histogram. TODO(owilliams): Add support for ST.

type RefHistogramSample added in v0.40.0

type RefHistogramSample struct {
	Ref chunks.HeadSeriesRef
	T   int64
	H   *histogram.Histogram
}

RefHistogramSample is a histogram. TODO(owilliams): Add support for ST.

type RefMetadata added in v0.38.0

type RefMetadata struct {
	Ref  chunks.HeadSeriesRef
	Type uint8
	Unit string
	Help string
}

RefMetadata is the metadata associated with a series ID.

type RefMmapMarker added in v0.39.0

type RefMmapMarker struct {
	Ref     chunks.HeadSeriesRef
	MmapRef chunks.ChunkDiskMapperRef
}

RefMmapMarker marks that the all the samples of the given series until now have been m-mapped to disk.

type RefSample

type RefSample struct {
	Ref   chunks.HeadSeriesRef
	ST, T int64
	V     float64
}

RefSample is a timestamp/st/value struct associated with a reference to a series. TODO(beorn7): Perhaps make this "polymorphic", including histogram and float-histogram pointers? Then get rid of RefHistogramSample.

type RefSeries

type RefSeries struct {
	Ref    chunks.HeadSeriesRef
	Labels labels.Labels
}

RefSeries is the series labels with the series ID.

type Type

type Type uint8

Type represents the data type of a record.

const (
	// Unknown is returned for unrecognised WAL record types.
	Unknown Type = 255
	// Series is used to match WAL records of type Series.
	Series Type = 1
	// Samples is used to match WAL records of type Samples.
	Samples Type = 2
	// Tombstones is used to match WAL records of type Tombstones.
	Tombstones Type = 3
	// Exemplars is used to match WAL records of type Exemplars.
	Exemplars Type = 4
	// MmapMarkers is used to match OOO WBL records of type MmapMarkers.
	MmapMarkers Type = 5
	// Metadata is used to match WAL records of type Metadata.
	Metadata Type = 6
	// HistogramSamples is used to match WAL records of type Histograms.
	HistogramSamples Type = 7
	// FloatHistogramSamples is used to match WAL records of type Float Histograms.
	FloatHistogramSamples Type = 8
	// CustomBucketsHistogramSamples is used to match WAL records of type Histogram with custom buckets.
	CustomBucketsHistogramSamples Type = 9
	// CustomBucketsFloatHistogramSamples is used to match WAL records of type Float Histogram with custom buckets.
	CustomBucketsFloatHistogramSamples Type = 10
	// SamplesV2 is an enhanced sample record with an encoding scheme that allows storing float samples with timestamp and an optional ST per sample.
	SamplesV2 Type = 11
)

func (Type) String added in v0.38.0

func (rt Type) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL