ringbuffer

package
v0.0.0-...-674b63a Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Empty

func Empty(b Buffer) bool

func UseStreamingRingBuffers

func UseStreamingRingBuffers(opts query.Options, selectRange int64) bool

Types

type Buffer

type Buffer interface {
	MaxT() int64
	Push(t int64, v Value)
	Reset(mint int64, evalt int64)
	Eval(ctx context.Context, _, _ float64) (float64, *histogram.FloatHistogram, bool, warnings.Warnings, error)
	SampleCount() int
}

Buffer owns sample admission for a range window. Reset establishes the window for an evaluation step, then Push decides whether each candidate belongs in that window.

type ExtendedRingBuffer

type ExtendedRingBuffer struct {
	*GenericRingBuffer
	// contains filtered or unexported fields
}

ExtendedRingBuffer retains the newest sample at or before the range start as a baseline for xrate, xincrease, and xdelta. Samples are normally offered to Push in timestamp order, but baseline insertion also preserves ordering when a prefetched sample arrives after an in-window sample.

func NewWithExtLookback

func NewWithExtLookback(
	ctx context.Context,
	size int,
	selectRange, offset, extLookback int64,
	call FunctionCall,
) *ExtendedRingBuffer

NewWithExtLookback creates a buffer for an extended range function. extLookback is the maximum age in milliseconds of a baseline relative to the range start.

func (*ExtendedRingBuffer) Eval

func (*ExtendedRingBuffer) Push

func (r *ExtendedRingBuffer) Push(t int64, v Value)

Push applies the same extended-window rule to samples supplied after Reset. It also records the earliest candidate observed for xincrease's initial-zero injection. This covers both the scanner's prefetched sample and samples read directly from its iterator.

func (*ExtendedRingBuffer) Reset

func (r *ExtendedRingBuffer) Reset(mint int64, evalt int64)

Reset applies the extended-window rule to samples retained from the previous evaluation step. It keeps the suffix after mint and, when one exists within extLookback, the newest baseline at or before mint.

type FunctionArgs

type FunctionArgs struct {
	Samples     []Sample
	StepTime    int64
	SelectRange int64
	Offset      int64
	// MetricAppearedTs is the earliest sample timestamp observed for an
	// extended range function. xincrease uses it to limit initial-zero injection.
	MetricAppearedTs int64

	// quantile_over_time and predict_linear use one, so we only use one here.
	ScalarPoint  float64
	ScalarPoint2 float64 // only for double_exponential_smoothing (trend factor)
}

type FunctionCall

func NewRangeVectorFunc

func NewRangeVectorFunc(name string) (FunctionCall, error)

type GenericRingBuffer

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

func New

func New(ctx context.Context, size int, selectRange, offset int64, call FunctionCall) *GenericRingBuffer

func (*GenericRingBuffer) Eval

func (*GenericRingBuffer) MaxT

func (r *GenericRingBuffer) MaxT() int64

MaxT returns the maximum timestamp of the ring buffer. If the ring buffer is empty, it returns math.MinInt64.

func (*GenericRingBuffer) Push

func (r *GenericRingBuffer) Push(t int64, v Value)

Push considers a sample for the current range.

func (*GenericRingBuffer) Reset

func (r *GenericRingBuffer) Reset(mint int64, evalt int64)

func (*GenericRingBuffer) SampleCount

func (r *GenericRingBuffer) SampleCount() int

type OverTimeBuffer

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

OverTimeBuffer is a Buffer which can calculate [agg]_over_time for a series in a streaming manner, calculating the value incrementally for each step where the sample is used.

func NewAvgOverTimeBuffer

func NewAvgOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func NewCountOverTimeBuffer

func NewCountOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func NewLastOverTimeBuffer

func NewLastOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func NewMaxOverTimeBuffer

func NewMaxOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func NewMinOverTimeBuffer

func NewMinOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func NewPresentOverTimeBuffer

func NewPresentOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func NewStdDevOverTimeBuffer

func NewStdDevOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func NewStdVarOverTimeBuffer

func NewStdVarOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func NewSumOverTimeBuffer

func NewSumOverTimeBuffer(opts query.Options, selectRange, offset int64) *OverTimeBuffer

func (*OverTimeBuffer) Eval

func (*OverTimeBuffer) MaxT

func (r *OverTimeBuffer) MaxT() int64

func (*OverTimeBuffer) Push

func (r *OverTimeBuffer) Push(t int64, v Value)

func (*OverTimeBuffer) Reset

func (r *OverTimeBuffer) Reset(mint int64, evalt int64)

func (*OverTimeBuffer) SampleCount

func (r *OverTimeBuffer) SampleCount() int

type RateBuffer

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

RateBuffer is a Buffer which can calculate rate, increase and delta for a series in a streaming manner, calculating the value incrementally for each step where the sample is used.

func NewRateBuffer

func NewRateBuffer(ctx context.Context, opts query.Options, isCounter, isRate bool, selectRange, offset int64) *RateBuffer

NewRateBuffer creates a new RateBuffer.

func (*RateBuffer) Eval

func (*RateBuffer) MaxT

func (r *RateBuffer) MaxT() int64

func (*RateBuffer) Push

func (r *RateBuffer) Push(t int64, v Value)

func (*RateBuffer) Reset

func (r *RateBuffer) Reset(mint int64, evalt int64)

func (*RateBuffer) SampleCount

func (r *RateBuffer) SampleCount() int

type Sample

type Sample struct {
	T int64
	V Value
}

type SamplesBuffer

type SamplesBuffer GenericRingBuffer

type Value

type Value struct {
	F float64
	H *histogram.FloatHistogram
}

Jump to

Keyboard shortcuts

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