Documentation ¶
Index ¶
- Variables
- func GetBoolSlice(size int) []bool
- func GetFPointSlice(size int) []promql.FPoint
- func GetFloatSlice(size int) []float64
- func GetHPointSlice(size int) []promql.HPoint
- func GetMatrix(size int) promql.Matrix
- func GetVector(size int) promql.Vector
- func PutBoolSlice(s []bool)
- func PutFPointSlice(s []promql.FPoint)
- func PutFloatSlice(s []float64)
- func PutHPointSlice(s []promql.HPoint)
- func PutMatrix(m promql.Matrix)
- func PutSeriesMetadataSlice(s []SeriesMetadata)
- func PutVector(v promql.Vector)
- type Aggregation
- type BinaryOperation
- type InstantVectorOperator
- type InstantVectorSelector
- type InstantVectorSeriesData
- type Operator
- type RangeVectorFunction
- type RangeVectorOperator
- type RangeVectorSelector
- func (m *RangeVectorSelector) Close()
- func (m *RangeVectorSelector) NextSeries(ctx context.Context) error
- func (m *RangeVectorSelector) NextStepSamples(floats *RingBuffer) (RangeVectorStepData, error)
- func (m *RangeVectorSelector) Range() time.Duration
- func (m *RangeVectorSelector) SeriesMetadata(ctx context.Context) ([]SeriesMetadata, error)
- func (m *RangeVectorSelector) StepCount() int
- type RangeVectorStepData
- type RingBuffer
- func (b *RingBuffer) Append(p promql.FPoint)
- func (b *RingBuffer) Close()
- func (b *RingBuffer) CopyPoints(maxT int64) []promql.FPoint
- func (b *RingBuffer) DiscardPointsBefore(t int64)
- func (b *RingBuffer) First() promql.FPoint
- func (b *RingBuffer) ForEach(f func(p promql.FPoint))
- func (b *RingBuffer) LastAtOrBefore(maxT int64) (promql.FPoint, bool)
- func (b *RingBuffer) Reset()
- func (b *RingBuffer) UnsafePoints(maxT int64) (head []promql.FPoint, tail []promql.FPoint)
- type Selector
- type SeriesMetadata
Constants ¶
This section is empty.
Variables ¶
var EOS = errors.New("operator stream exhausted") //nolint:revive
Functions ¶
func GetBoolSlice ¶
func GetFPointSlice ¶
func GetFloatSlice ¶
func GetHPointSlice ¶
func PutBoolSlice ¶
func PutBoolSlice(s []bool)
func PutFPointSlice ¶
func PutFloatSlice ¶
func PutFloatSlice(s []float64)
func PutHPointSlice ¶
func PutSeriesMetadataSlice ¶
func PutSeriesMetadataSlice(s []SeriesMetadata)
Types ¶
type Aggregation ¶
type Aggregation struct { Inner InstantVectorOperator Start time.Time End time.Time Interval time.Duration Grouping []string // contains filtered or unexported fields }
func (*Aggregation) Close ¶
func (a *Aggregation) Close()
func (*Aggregation) NextSeries ¶
func (a *Aggregation) NextSeries(ctx context.Context) (InstantVectorSeriesData, error)
func (*Aggregation) SeriesMetadata ¶
func (a *Aggregation) SeriesMetadata(ctx context.Context) ([]SeriesMetadata, error)
type BinaryOperation ¶
type BinaryOperation struct { Left InstantVectorOperator Right InstantVectorOperator Op parser.ItemType VectorMatching parser.VectorMatching // contains filtered or unexported fields }
BinaryOperation represents a binary operation between instant vectors such as "<expr> + <expr>" or "<expr> - <expr>".
func NewBinaryOperation ¶
func NewBinaryOperation(left InstantVectorOperator, right InstantVectorOperator, vectorMatching parser.VectorMatching, op parser.ItemType) (*BinaryOperation, error)
func (*BinaryOperation) Close ¶
func (b *BinaryOperation) Close()
func (*BinaryOperation) NextSeries ¶
func (b *BinaryOperation) NextSeries(ctx context.Context) (InstantVectorSeriesData, error)
func (*BinaryOperation) SeriesMetadata ¶
func (b *BinaryOperation) SeriesMetadata(ctx context.Context) ([]SeriesMetadata, error)
SeriesMetadata returns the series expected to be produced by this operator.
Note that it is possible that this method returns a series which will not have any points, as the list of possible output series is generated based solely on the series labels, not their data.
For example, if this operator is for a range query with the expression "left_metric + right_metric", but left_metric has points at T=0 and T=1 in the query range, and right_metric has points at T=2 and T=3 in the query range, then SeriesMetadata will return a series, but NextSeries will return no points for that series.
If this affects many series in the query, this may cause consuming operators to be less efficient, but in practice this rarely happens.
(The alternative would be to compute the entire result here in SeriesMetadata and only return the series that contain points, but that would mean we'd need to hold the entire result in memory at once, which we want to avoid.)
type InstantVectorOperator ¶
type InstantVectorOperator interface { Operator // NextSeries returns the next series from this operator, or EOS if no more series are available. // SeriesMetadata must be called exactly once before calling NextSeries. // The returned InstantVectorSeriesData can be modified by the caller or returned to a pool. // The returned InstantVectorSeriesData can contain no points. NextSeries(ctx context.Context) (InstantVectorSeriesData, error) }
InstantVectorOperator represents all operators that produce instant vectors.
type InstantVectorSelector ¶
type InstantVectorSelector struct { Selector *Selector // contains filtered or unexported fields }
func (*InstantVectorSelector) Close ¶
func (v *InstantVectorSelector) Close()
func (*InstantVectorSelector) NextSeries ¶
func (v *InstantVectorSelector) NextSeries(ctx context.Context) (InstantVectorSeriesData, error)
func (*InstantVectorSelector) SeriesMetadata ¶
func (v *InstantVectorSelector) SeriesMetadata(ctx context.Context) ([]SeriesMetadata, error)
type InstantVectorSeriesData ¶
type InstantVectorSeriesData struct { // Floats contains floating point samples for this series. // Samples must be sorted in timestamp order, earliest timestamps first. // Samples must not have duplicate timestamps. Floats []promql.FPoint // Histograms contains histogram samples for this series. // Samples must be sorted in timestamp order, earliest timestamps first. // Samples must not have duplicate timestamps. Histograms []promql.HPoint }
type Operator ¶
type Operator interface { // SeriesMetadata returns a list of all series that will be returned by this operator. // The returned []SeriesMetadata can be modified by the caller or returned to a pool. // SeriesMetadata may return series in any order, but the same order must be used by both SeriesMetadata and NextSeries. // SeriesMetadata should be called no more than once. SeriesMetadata(ctx context.Context) ([]SeriesMetadata, error) // Close frees all resources associated with this operator. // Calling SeriesMetadata or NextSeries after calling Close may result in unpredictable behaviour, corruption or crashes. // It must be safe to call Close at any time, including if SeriesMetadata or NextSeries have returned an error. Close() }
Operator represents all operators.
type RangeVectorFunction ¶
type RangeVectorFunction struct { Inner RangeVectorOperator // contains filtered or unexported fields }
RangeVectorFunction performs a rate calculation over a range vector.
func (*RangeVectorFunction) Close ¶
func (m *RangeVectorFunction) Close()
func (*RangeVectorFunction) NextSeries ¶
func (m *RangeVectorFunction) NextSeries(ctx context.Context) (InstantVectorSeriesData, error)
func (*RangeVectorFunction) SeriesMetadata ¶
func (m *RangeVectorFunction) SeriesMetadata(ctx context.Context) ([]SeriesMetadata, error)
type RangeVectorOperator ¶
type RangeVectorOperator interface { Operator // StepCount returns the number of time steps produced for each series by this operator. // StepCount must only be called after calling SeriesMetadata. StepCount() int // Range returns the time range selected by this operator at each time step. // // For example, if this operator represents the selector "some_metric[5m]", Range returns 5 minutes. Range() time.Duration // NextSeries advances to the next series produced by this operator, or EOS if no more series are available. // SeriesMetadata must be called exactly once before calling NextSeries. NextSeries(ctx context.Context) error // NextStepSamples populates the provided RingBuffer with the samples for the next time step for the // current series and returns the timestamps of the next time step, or returns EOS if no more time // steps are available. // The provided RingBuffer is expected to only contain points for the current series, and the same // RingBuffer should be passed to subsequent NextStepSamples calls for the same series. // The provided RingBuffer may be populated with points beyond the end of the expected time range, and // callers should compare returned points' timestamps to the returned RangeVectorStepData.RangeEnd. // Next must be called at least once before calling NextStepSamples. NextStepSamples(floats *RingBuffer) (RangeVectorStepData, error) }
RangeVectorOperator represents all operators that produce range vectors.
type RangeVectorSelector ¶
type RangeVectorSelector struct { Selector *Selector // contains filtered or unexported fields }
func (*RangeVectorSelector) Close ¶
func (m *RangeVectorSelector) Close()
func (*RangeVectorSelector) NextSeries ¶
func (m *RangeVectorSelector) NextSeries(ctx context.Context) error
func (*RangeVectorSelector) NextStepSamples ¶
func (m *RangeVectorSelector) NextStepSamples(floats *RingBuffer) (RangeVectorStepData, error)
func (*RangeVectorSelector) Range ¶
func (m *RangeVectorSelector) Range() time.Duration
func (*RangeVectorSelector) SeriesMetadata ¶
func (m *RangeVectorSelector) SeriesMetadata(ctx context.Context) ([]SeriesMetadata, error)
func (*RangeVectorSelector) StepCount ¶
func (m *RangeVectorSelector) StepCount() int
type RangeVectorStepData ¶
type RangeVectorStepData struct { // StepT is the timestamp of this time step. StepT int64 // RangeStart is the beginning of the time range selected by this time step. // RangeStart is inclusive (ie. points with timestamp >= RangeStart are included in the range). RangeStart int64 // RangeEnd is the end of the time range selected by this time step. // RangeEnd is the same as StepT except when the @ modifier or offsets are used, in which case // RangeEnd reflects the time of the underlying points, and StepT is the timestamp of the point // produced by the query. // RangeEnd is inclusive (ie. points with timestamp <= RangeEnd are included in the range). RangeEnd int64 }
RangeVectorStepData contains the timestamps associated with a single time step produced by a RangeVectorOperator.
All values are in milliseconds since the Unix epoch.
For example, if the operator represents the selector "some_metric[5m]", and this time step is for 2024-05-02T00:00:00Z, then:
- StepT is 1714608000000 (2024-05-02T00:00:00Z)
- RangeStart is 1714607700000 (2024-05-01T23:55:00Z)
- RangeEnd is 1714608000000 (2024-05-02T00:00:00Z)
If the operator represents the selector "some_metric[5m] @ 1712016000", and this time step is for 2024-05-02T00:00:00Z, then:
- StepT is 1714608000000 (2024-05-02T00:00:00Z)
- RangeStart is 1712015700000 (2024-04-01T23:55:00Z)
- RangeEnd is 1712016000000 (2024-04-02T00:00:00Z)
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
func (*RingBuffer) Append ¶
func (b *RingBuffer) Append(p promql.FPoint)
Append adds p to this buffer, expanding it if required. If this buffer is non-empty, p.T must be greater than or equal to the timestamp of the last point in the buffer.
func (*RingBuffer) Close ¶
func (b *RingBuffer) Close()
Close releases any resources associated with this buffer.
func (*RingBuffer) CopyPoints ¶
func (b *RingBuffer) CopyPoints(maxT int64) []promql.FPoint
CopyPoints returns a single slice of the points in this buffer, including only points with timestamp less than or equal to maxT. Callers may modify the values in the returned slice, and should return the slice to the pool by calling PutFPointSlice when it is no longer needed. Calling UnsafePoints is more efficient than calling CopyPoints, as CopyPoints will create a new slice and copy all points into the slice, whereas UnsafePoints returns a view into the internal state of this buffer.
func (*RingBuffer) DiscardPointsBefore ¶
func (b *RingBuffer) DiscardPointsBefore(t int64)
DiscardPointsBefore discards all points in this buffer with timestamp less than t.
func (*RingBuffer) First ¶
func (b *RingBuffer) First() promql.FPoint
First returns the first point in this buffer. It panics if the buffer is empty.
func (*RingBuffer) ForEach ¶
func (b *RingBuffer) ForEach(f func(p promql.FPoint))
ForEach calls f for each point in this buffer.
func (*RingBuffer) LastAtOrBefore ¶
func (b *RingBuffer) LastAtOrBefore(maxT int64) (promql.FPoint, bool)
LastAtOrBefore returns the last point in this buffer with timestamp less than or equal to maxT. It returns false if there is no point satisfying this requirement.
func (*RingBuffer) UnsafePoints ¶
UnsafePoints returns slices of the points in this buffer, including only points with timestamp less than or equal to maxT. Either or both slice could be empty. Callers must not modify the values in the returned slices or return them to a pool. Calling UnsafePoints is more efficient than calling CopyPoints, as CopyPoints will create a new slice and copy all points into the slice, whereas UnsafePoints returns a view into the internal state of this buffer. The returned slices are no longer valid if this buffer is modified (eg. a point is added, or the buffer is reset or closed).
FIXME: the fact we have to expose this is a bit gross, but the overhead of calling a function with ForEach is terrible. Perhaps we can use range-over function iterators (https://golang.ir/wiki/RangefuncExperiment) once this is not experimental?
type Selector ¶
type Selector struct { Queryable storage.Queryable Start int64 // Milliseconds since Unix epoch End int64 // Milliseconds since Unix epoch Timestamp *int64 // Milliseconds since Unix epoch, only set if selector uses @ modifier (eg. metric{...} @ 123) Interval int64 // In milliseconds Matchers []*labels.Matcher // Set for instant vector selectors, otherwise 0. LookbackDelta time.Duration // Set for range vector selectors, otherwise 0. Range time.Duration // contains filtered or unexported fields }
func (*Selector) SeriesMetadata ¶
func (s *Selector) SeriesMetadata(ctx context.Context) ([]SeriesMetadata, error)
type SeriesMetadata ¶
func GetSeriesMetadataSlice ¶
func GetSeriesMetadataSlice(size int) []SeriesMetadata