v2

package
v0.0.0-...-e5fe545 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

README

V2 File Format

The V2 file format uses a simple binary format based on efficiency and not on backwards compatibility or future compatibility. If there is a need for changes it should be created a separate version.

The library benc was chosen because it was the lowest level library that offered buffer reuse, unsafe string usage and still had reasonable checks for out of bounds, and issues. This makes it more performant that mus and msgp format for example. The source of narrowing down serialization libaries came from https://alecthomas.github.io/go_serialization_benchmarks/.

Tested with mus,gencode,benc,bepod,mmsgp, and fastape. Benc hit the sweetspot on usage, nice api with reasonable checks.

The underlying format stores a type byte metric or metadata, specific metadata for each time and then the raw byte array of the protobuf bytes. This means it does not need to fully deserialize the data.

Documentation

Overview

Copied from prometheus.

Index

Constants

View Source
const PrometheusExemplar = uint8(2)
View Source
const PrometheusMetadata = uint8(3)
View Source
const PrometheusMetric = uint8(1)

Variables

This section is empty.

Functions

func FromFloatHistogram

func FromFloatHistogram(timestamp int64, fh *histogram.FloatHistogram) prompb.Histogram

FromFloatHistogram returns remote Histogram from the float Histogram.

func FromIntHistogram

func FromIntHistogram(timestamp int64, h *histogram.Histogram) prompb.Histogram

FromIntHistogram returns remote Histogram from the integer Histogram.

func FromMetadataType

FromMetadataType transforms a Prometheus metricType into prompb metricType. Since the former is a string we need to transform it to an enum.

Types

type Format

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

Format describe the v2 data format.

func NewFormat

func NewFormat() *Format

func (*Format) AddPrometheusMetadata

func (s *Format) AddPrometheusMetadata(name string, unit string, help string, pType string) error

func (*Format) AddPrometheusMetric

func (s *Format) AddPrometheusMetric(ts int64, value float64, lbls labels.Labels, h *histogram.Histogram, fh *histogram.FloatHistogram, externalLabels map[string]string) error

AddPrometheusMetric marshals a prometheus metric to its prombpb.TimeSeries representation and writes it to the buffer.

func (*Format) Marshal

func (s *Format) Marshal(handle func(map[string]string, []byte) error) error

func (*Format) Unmarshal

func (s *Format) Unmarshal(meta map[string]string, buf []byte) (items []types.Datum, err error)

type Metadata

type Metadata struct {
	Buf []byte
}

Struct - Metadata

func (Metadata) Bytes

func (m Metadata) Bytes() []byte

func (Metadata) FileFormat

func (m Metadata) FileFormat() types.FileFormat

func (Metadata) Free

func (m Metadata) Free()

func (Metadata) IsMeta

func (m Metadata) IsMeta() bool

func (*Metadata) Marshal

func (metadata *Metadata) Marshal(b []byte)

Marshal - metadata

func (*Metadata) MarshalPlain

func (metadata *Metadata) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - metadata

func (*Metadata) Size

func (metadata *Metadata) Size() int

Size - metadata

func (*Metadata) SizePlain

func (metadata *Metadata) SizePlain() (s int)

SizePlain - metadata

func (Metadata) Type

func (m Metadata) Type() types.Type

func (*Metadata) Unmarshal

func (metadata *Metadata) Unmarshal(b []byte) (n int, err error)

Unmarshal - metadata

func (*Metadata) UnmarshalPlain

func (metadata *Metadata) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - metadata

type Metric

type Metric struct {
	Timestampmsvalue int64
	Hashvalue        uint64
	IsHistogramvalue bool
	Buf              []byte
}

Struct - Metric

func (Metric) Bytes

func (m Metric) Bytes() []byte

Bytes represents the underlying data and should not be handled aside from Build* functions that understand the Type.

func (Metric) FileFormat

func (m Metric) FileFormat() types.FileFormat

func (*Metric) Free

func (m *Metric) Free()

func (Metric) Hash

func (m Metric) Hash() uint64

func (Metric) IsHistogram

func (m Metric) IsHistogram() bool

func (*Metric) Marshal

func (metric *Metric) Marshal(b []byte)

Marshal - metric

func (*Metric) MarshalPlain

func (metric *Metric) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - metric

func (*Metric) Size

func (metric *Metric) Size() int

Size - metric

func (*Metric) SizePlain

func (metric *Metric) SizePlain() (s int)

SizePlain - metric

func (Metric) TimeStampMS

func (m Metric) TimeStampMS() int64

func (Metric) Type

func (m Metric) Type() types.Type

func (*Metric) Unmarshal

func (metric *Metric) Unmarshal(b []byte) (n int, err error)

Unmarshal - metric

func (*Metric) UnmarshalPlain

func (metric *Metric) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - metric

Jump to

Keyboard shortcuts

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