timeseries

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package timeseries provides types for building and aggregating time series data.

NOTE: This is the old time series implementation using string labels. Currently used for all time series queries except exemplar retrieval. Over time, we want to migrate to pkg/model/timeseriescompact which uses attribute table interning for better performance, and remove this package.

Index

Constants

View Source
const DefaultMaxExemplarsPerPoint = 1

DefaultMaxExemplarsPerPoint is the default maximum number of exemplars tracked per point. TODO: make it configurable via tenant limits.

Variables

This section is empty.

Functions

func MergeSeries

func MergeSeries(aggregation *typesv1.TimeSeriesAggregationType, series ...[]*typesv1.Series) []*typesv1.Series

func NewTimeSeriesMergeIterator

func NewTimeSeriesMergeIterator(series []*typesv1.Series) iter.Iterator[Value]

func RangeSeries

func RangeSeries(it iter.Iterator[Value], start, end, step int64, aggregation *typesv1.TimeSeriesAggregationType) []*typesv1.Series

RangeSeries aggregates profiles into series. Series contains points spaced by step from start to end. Profiles from the same step are aggregated into one point.

func TopSeries

func TopSeries(s []*typesv1.Series, k int) []*typesv1.Series

TopSeries returns the top k series by sum of values. If k is zero, all series are returned. Note that even if len(c) <= k or k == 0, the returned series are sorted by value in descending order and then lexicographically (in ascending order).

Types

type Aggregator

type Aggregator interface {
	Add(ts int64, point *Value)
	GetAndReset() *typesv1.Point
	IsEmpty() bool
	GetTimestamp() int64
}

func NewAggregator

func NewAggregator(aggregation *typesv1.TimeSeriesAggregationType) Aggregator

func NewAggregatorWithLimit

func NewAggregatorWithLimit(aggregation *typesv1.TimeSeriesAggregationType, maxExemplarsPerPoint int) Aggregator

type Builder

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

func NewBuilder

func NewBuilder(by ...string) *Builder

func (*Builder) Add

func (s *Builder) Add(fp model.Fingerprint, lbs phlaremodel.Labels, ts int64, value float64, annotations schemav1.Annotations, profileID string)

Add adds a data point with full labels. The series is grouped by the 'by' labels, but exemplars retain full labels.

func (*Builder) Build

func (s *Builder) Build() []*typesv1.Series

Build returns the time series without exemplars.

func (*Builder) BuildWithExemplars

func (s *Builder) BuildWithExemplars() []*typesv1.Series

BuildWithExemplars returns the time series with exemplars attached.

func (*Builder) ExemplarCount

func (s *Builder) ExemplarCount() int

ExemplarCount returns the number of raw exemplars added (before deduplication).

func (*Builder) Init

func (s *Builder) Init(by ...string)

type Iterator

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

func NewSeriesIterator

func NewSeriesIterator(lbs []*typesv1.LabelPair, points []*typesv1.Point) *Iterator

func (*Iterator) At

func (s *Iterator) At() Value

func (*Iterator) Close

func (s *Iterator) Close() error

func (*Iterator) Err

func (s *Iterator) Err() error

func (*Iterator) Next

func (s *Iterator) Next() bool

type Merger

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

func NewMerger

func NewMerger(sum bool) *Merger

NewMerger creates a new series merger. If sum is set, samples with matching timestamps are summed, otherwise duplicates are retained.

func (*Merger) IsEmpty

func (m *Merger) IsEmpty() bool

func (*Merger) MergeTimeSeries

func (m *Merger) MergeTimeSeries(s []*typesv1.Series)

func (*Merger) TimeSeries

func (m *Merger) TimeSeries() []*typesv1.Series

func (*Merger) Top

func (m *Merger) Top(n int) []*typesv1.Series

type Value

type Value struct {
	Ts          int64
	Lbs         []*typesv1.LabelPair
	LabelsHash  uint64
	Value       float64
	Annotations []*typesv1.ProfileAnnotation
	Exemplars   []*typesv1.Exemplar
}

func (Value) Labels

func (p Value) Labels() phlaremodel.Labels

func (Value) Timestamp

func (p Value) Timestamp() model.Time

Jump to

Keyboard shortcuts

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