Documentation ¶
Index ¶
- Variables
- func Avg(a, b float64, count int) float64
- func EnablePooling(valueBuckets, consolidationBuckets []xpool.Bucket)
- func Gcd(a, b int64) int64
- func Last(a, b float64, count int) float64
- func Lcm(a, b int64) int64
- func Max(a, b float64, count int) float64
- func Min(a, b float64, count int) float64
- func Mul(a, b float64, count int) float64
- func NumSteps(start, end time.Time, millisPerStep int) int
- func Sum(a, b float64, count int) float64
- type AggregationFunc
- type ConsolidatedValue
- type ConsolidatedValuesByStartTime
- type Consolidation
- type ConsolidationApproach
- type ConsolidationFunc
- type CustomStatistics
- type Datapoint
- type Datapoints
- type DatapointsByTimestamp
- type Direction
- type FinalizeOption
- type MutableSeries
- type MutableValues
- type PostConsolidationFunc
- type Series
- func (b *Series) AllNaN() bool
- func (b *Series) CalcStatistics() stats.Statistics
- func (b *Series) ConsolidationFunc() ConsolidationFunc
- func (b *Series) Contains(t time.Time) bool
- func (b *Series) DerivedSeries(startTime time.Time, vals Values) *Series
- func (b *Series) Duration() time.Duration
- func (b *Series) EndTime() time.Time
- func (b *Series) EndTimeForStep(n int) time.Time
- func (b *Series) IntersectAndResize(start, end time.Time, millisPerStep int, stepAggregator ConsolidationFunc) (*Series, error)
- func (b *Series) IsConsolidationFuncSet() bool
- func (b *Series) Len() int
- func (b *Series) MillisPerStep() int
- func (b *Series) Name() string
- func (b *Series) RenamedTo(name string) *Series
- func (b *Series) Resolution() time.Duration
- func (b *Series) SafeAvg() float64
- func (b *Series) SafeLastValue() float64
- func (b *Series) SafeMax() float64
- func (b *Series) SafeMin() float64
- func (b *Series) SafeStdDev() float64
- func (b *Series) SafeSum() float64
- func (b *Series) SafeValues() []float64
- func (b *Series) SetConsolidationFunc(cf ConsolidationFunc)
- func (b *Series) Shift(shift time.Duration) *Series
- func (b *Series) Slice(begin, end int) (*Series, error)
- func (b *Series) StartTime() time.Time
- func (b *Series) StartTimeForStep(n int) time.Time
- func (b *Series) StepAtTime(t time.Time) int
- func (b *Series) ValueAt(i int) float64
- func (b *Series) ValueAtTime(t time.Time) float64
- type SeriesByName
- type SeriesList
- type SeriesReducer
- type SeriesReducerApproach
- type Values
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRangeIsInvalid is returned when attempting to slice Series with invalid range // endpoints (begin is beyond end). ErrRangeIsInvalid = errors.New("requested range is invalid") )
Functions ¶
func EnablePooling ¶
EnablePooling enables pooling.
Types ¶
type AggregationFunc ¶
An AggregationFunc combines two data values at a given point.
type ConsolidatedValue ¶
type ConsolidatedValue struct { // StartTime is the start time of the time window covered by this // consolidation StartTime time.Time // EndTime is the end time of the time window covered by this // consolidation EndTime time.Time // Values is the statistics for that consolidated time window Values stats.Statistics }
ConsolidatedValue represents a time window of consolidated data
type ConsolidatedValuesByStartTime ¶
type ConsolidatedValuesByStartTime []ConsolidatedValue
ConsolidatedValuesByStartTime is a sortable interface for consolidated values
func (ConsolidatedValuesByStartTime) Len ¶
func (p ConsolidatedValuesByStartTime) Len() int
Len is the length of the values
func (ConsolidatedValuesByStartTime) Less ¶
func (p ConsolidatedValuesByStartTime) Less(i, j int) bool
Less compares two values by start time
func (ConsolidatedValuesByStartTime) Swap ¶
func (p ConsolidatedValuesByStartTime) Swap(i, j int)
Swap swaps two values
type Consolidation ¶
type Consolidation interface { // AddDatapoint adds an individual datapoint to the consolidation. AddDatapoint(timestamp time.Time, value float64) // AddDatapoints adds a set of datapoints to the consolidation. AddDatapoints(datapoints []Datapoint) // AddSeries adds the datapoints for each series to the consolidation. The // stepAggregationFunc is used to combine values from the series if the series // has a smaller step size than the consolidation. For example, an application // might want to produce a consolidation which is a minimum of the input timeseries, // but where the values in smaller timeseries units are summed together to // produce the value to which the consolidation applies. // To put it in another way, stepAggregationFunc is used for the series to resize itself // rather than for the consolidation AddSeries(series *Series, stepAggregationFunc ConsolidationFunc) // BuildSeries returns the consolidated Series and optionally finalizes // the consolidation returning it to the pool BuildSeries(id string, finalize FinalizeOption) *Series // Finalize returns the consolidation to the pool Finalize() }
A Consolidation produces a Series whose values are the result of applying a consolidation function to all of the datapoints that fall within each step. It can used to quantize raw datapoints into a given resolution, for example, or to aggregate multiple timeseries at the same or smaller resolutions.
func NewConsolidation ¶
func NewConsolidation( ctx context.Context, start, end time.Time, millisPerStep int, cf ConsolidationFunc, ) Consolidation
NewConsolidation creates a new consolidation window.
type ConsolidationApproach ¶
type ConsolidationApproach string
ConsolidationApproach defines an approach to consolidating multiple datapoints
const ( ConsolidationAvg ConsolidationApproach = "avg" ConsolidationMin ConsolidationApproach = "min" ConsolidationMax ConsolidationApproach = "max" ConsolidationSum ConsolidationApproach = "sum" ConsolidationAverage ConsolidationApproach = "average" // just an alias to avg but for backward-compatibility )
The standard set of consolidation functions
func (ConsolidationApproach) Func ¶
func (ca ConsolidationApproach) Func() ConsolidationFunc
Func returns the ConsolidationFunc implementing the ConsolidationApproach
func (ConsolidationApproach) SafeFunc ¶
func (ca ConsolidationApproach) SafeFunc() (ConsolidationFunc, bool)
SafeFunc returns a boolean indicating whether this is a valid consolidation approach, and if so, the corresponding ConsolidationFunc.
type ConsolidationFunc ¶
A ConsolidationFunc consolidates values at a given point in time. It takes the current consolidated value, the new value to add to the consolidation, and a count of the number of values that have already been consolidated.
type CustomStatistics ¶
type CustomStatistics interface {
CalcStatistics() stats.Statistics
}
CustomStatistics are for values that do custom statistics calculations
type Datapoint ¶
A Datapoint is a single data value reported at a given time
func (Datapoint) ValueIsNaN ¶
ValueIsNaN returns true iff underlying value is NaN
type Datapoints ¶
type Datapoints []Datapoint
Datapoints is a list of datapoints that implement the stats.Values interface.
func (Datapoints) AllNaN ¶
func (d Datapoints) AllNaN() bool
AllNaN returns true if all the values are NaN
func (Datapoints) ValueAt ¶
func (d Datapoints) ValueAt(n int) float64
ValueAt returns the value at the nth element.
type DatapointsByTimestamp ¶
type DatapointsByTimestamp []Datapoint
DatapointsByTimestamp is a sortable interface for datapoints
func (DatapointsByTimestamp) Len ¶
func (p DatapointsByTimestamp) Len() int
Len is the length of the datapoints
func (DatapointsByTimestamp) Less ¶
func (p DatapointsByTimestamp) Less(i, j int) bool
Less compares two datapoints by timestamp
func (DatapointsByTimestamp) Swap ¶
func (p DatapointsByTimestamp) Swap(i, j int)
Swap swaps two datapoints
type FinalizeOption ¶
type FinalizeOption int
FinalizeOption specifies the option to finalize or avoid finalizing
const ( // NoFinalize will avoid finalizing the subject NoFinalize FinalizeOption = iota // Finalize will finalize the subject Finalize )
type MutableSeries ¶
type MutableSeries struct {
Series
}
A MutableSeries is a Series that allows updates
func NewMutableSeries ¶
func NewMutableSeries( ctx context.Context, name string, startTime time.Time, vals MutableValues) *MutableSeries
NewMutableSeries returns a new mutable Series at the given start time and backed by the provided storage
func (*MutableSeries) SetValueAt ¶
func (b *MutableSeries) SetValueAt(i int, v float64)
SetValueAt sets the value at the given step
func (*MutableSeries) SetValueAtTime ¶
func (b *MutableSeries) SetValueAtTime(t time.Time, v float64)
SetValueAtTime sets the value at the step containing the given time
type MutableValues ¶
type MutableValues interface { Values // Resets the values Reset() // Sets the value at the given entry SetValueAt(n int, v float64) }
MutableValues is the interface for values that can be updated
func NewValues ¶
func NewValues(ctx context.Context, millisPerStep, numSteps int) MutableValues
NewValues returns MutableValues supporting the given number of values at the requested granularity. The values start off as NaN
func NewZeroValues ¶
func NewZeroValues(ctx context.Context, millisPerStep, numSteps int) MutableValues
NewZeroValues returns a MutableValues supporting the given number of values at the requested granularity. The values start off initialized at 0
type PostConsolidationFunc ¶
PostConsolidationFunc is a function that takes a tuple of time and value after consolidation.
type Series ¶
type Series struct { // The Specification is the path that was used to generate this timeseries, // typically either the query, or the function stack used to transform // specific results. Specification string // contains filtered or unexported fields }
A Series is the public interface to a block of timeseries values. Each block has a start time, a logical number of steps, and a step size indicating the number of milliseconds represented by each point.
func LTTB ¶
LTTB down-samples the data to contain only threshold number of points that have the same visual shape as the original data. Inspired from https://github.com/dgryski/go-lttb which is based on https://skemman.is/bitstream/1946/15343/3/SS_MSthesis.pdf
func NewSeries ¶
NewSeries creates a new Series at a given start time, backed by the provided values
func SortSeries ¶
func SortSeries(in []*Series, sr SeriesReducer, dir Direction) ([]*Series, error)
SortSeries applies a given SeriesReducer to each series in the input list and sorts based on the assigned value
func (*Series) CalcStatistics ¶
func (b *Series) CalcStatistics() stats.Statistics
CalcStatistics calculates a standard aggregation across the block values
func (*Series) ConsolidationFunc ¶
func (b *Series) ConsolidationFunc() ConsolidationFunc
ConsolidationFunc returns the consolidation function for the series, or the averaging function is none specified.
func (*Series) DerivedSeries ¶
DerivedSeries returns a series derived from the current series with different datapoints
func (*Series) EndTimeForStep ¶
EndTimeForStep returns the time at which the given step end
func (*Series) IntersectAndResize ¶
func (b *Series) IntersectAndResize(start, end time.Time, millisPerStep int, stepAggregator ConsolidationFunc) (*Series, error)
IntersectAndResize returns a new time series with a different millisPerStep that spans the intersection of the underlying timeseries and the provided start and end time parameters
func (*Series) IsConsolidationFuncSet ¶
IsConsolidationFuncSet if the consolidationFunc is set
func (*Series) MillisPerStep ¶
MillisPerStep returns the number of milliseconds per step
func (*Series) RenamedTo ¶
RenamedTo returns a new timeseries with the same values but a different name
func (*Series) Resolution ¶
Resolution returns resolution per step
func (*Series) SafeLastValue ¶
SafeLastValue returns the last datapoint of a series that's not an NaN.
func (*Series) SafeStdDev ¶
SafeStdDev returns the standard deviation of the values of a series, excluding NaNs.
func (*Series) SafeValues ¶
SafeValues returns all non-NaN values in the series.
func (*Series) SetConsolidationFunc ¶
func (b *Series) SetConsolidationFunc(cf ConsolidationFunc)
SetConsolidationFunc sets the consolidation function for the series
func (*Series) Shift ¶
Shift returns a new timeseries with the same values but a different startTime
func (*Series) Slice ¶
Slice returns a new Series composed from a subset of values in the original Series
func (*Series) StartTimeForStep ¶
StartTimeForStep returns the time at which the given step starts
func (*Series) StepAtTime ¶
StepAtTime returns the step within the block containing the given time
type SeriesByName ¶
type SeriesByName []*Series
SeriesByName implements sort.Interface for sorting collections of series by name
func (SeriesByName) Len ¶
func (a SeriesByName) Len() int
Len returns the length of the series collection
func (SeriesByName) Less ¶
func (a SeriesByName) Less(i, j int) bool
Less determines if a series is ordered before another series by name
func (SeriesByName) Swap ¶
func (a SeriesByName) Swap(i, j int)
Swap swaps two series in the collection
type SeriesList ¶
type SeriesList struct { // Values is the list of series. Values []*Series // SortApplied specifies whether a specific sort order has been applied. SortApplied bool // Metadata contains any additional metadata indicating information about // series execution. Metadata block.ResultMetadata }
A SeriesList is a list of series.
func NewSeriesList ¶ added in v0.14.0
func NewSeriesList() SeriesList
NewSeriesList creates a blank series list.
func NewSeriesListWithSeries ¶ added in v0.14.0
func NewSeriesListWithSeries(values ...*Series) SeriesList
NewSeriesListWithSeries creates a series list with the given series and default metadata.
type SeriesReducer ¶
SeriesReducer reduces a series to a single value.
type SeriesReducerApproach ¶
type SeriesReducerApproach string
SeriesReducerApproach defines an approach to reduce a series to a single value.
const ( SeriesReducerAvg SeriesReducerApproach = "avg" SeriesReducerSum SeriesReducerApproach = "total" SeriesReducerMin SeriesReducerApproach = "min" SeriesReducerMax SeriesReducerApproach = "max" SeriesReducerStdDev SeriesReducerApproach = "stddev" SeriesReducerLast SeriesReducerApproach = "last" )
The standard set of reducers
func (SeriesReducerApproach) Reducer ¶
func (sa SeriesReducerApproach) Reducer() SeriesReducer
Reducer returns the SeriesReducer implementing the SeriesReducerApproach.
func (SeriesReducerApproach) SafeReducer ¶
func (sa SeriesReducerApproach) SafeReducer() (SeriesReducer, bool)
SafeReducer returns a boolean indicating whether it is a valid reducer, and if so, the SeriesReducer implementing the SeriesReducerApproach.
type Values ¶
type Values interface { stats.Values // The number of millisseconds represented by each index MillisPerStep() int // Slice of data values in a range Slice(begin, end int) Values // AllNaN returns true if the values are all NaN AllNaN() bool }
Values holds the values for a timeseries. It provides a minimal interface for storing and retrieving values in the series, with Series providing a more convenient interface for applications to build on top of. Values objects are not specific to a given time, allowing them to be pre-allocated, pooled, and re-used across multiple Series. There are multiple implementations of Values so that we can optimize storage based on the density of the series.