common

package
v0.15.17-hotfix.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// MillisPerSecond is for millis per second
	MillisPerSecond = 1000
	// SecondsPerMinute is for seconds per minute
	SecondsPerMinute = 60
	// MillisPerMinute is for milliseconds per minute
	MillisPerMinute = MillisPerSecond * SecondsPerMinute
)
View Source
const (
	// FloatingPointFormat is the floating point format for naming
	FloatingPointFormat = "%.3f"
)

Variables

View Source
var (
	// ErrNegativeCount occurs when the request count is < 0.
	ErrNegativeCount = errors.NewInvalidParamsError(errors.New("n must be positive"))
	// ErrEmptySeriesList occurs when a function requires a series as input
	ErrEmptySeriesList = errors.NewInvalidParamsError(errors.New("empty series list"))
	// ErrInvalidIntervalFormat occurs when invalid interval string encountered
	ErrInvalidIntervalFormat = errors.NewInvalidParamsError(errors.New("invalid format"))
)

Functions

func Alias

func Alias(_ *Context, series ts.SeriesList, a string) (ts.SeriesList, error)

Alias takes one metric or a wildcard seriesList and a string in quotes. Prints the string instead of the metric name in the legend.

func AliasByMetric

func AliasByMetric(ctx *Context, series ts.SeriesList) (ts.SeriesList, error)

AliasByMetric takes a seriesList and applies an alias derived from the base metric name.

func AliasByNode

func AliasByNode(_ *Context, seriesList ts.SeriesList, nodes ...int) (ts.SeriesList, error)

AliasByNode renames a time series result according to a subset of the nodes in its hierarchy.

func AliasSub

func AliasSub(_ *Context, input ts.SeriesList, search, replace string) (ts.SeriesList, error)

AliasSub runs series names through a regex search/replace.

func Changed

func Changed(ctx *Context, seriesList ts.SeriesList, renamer SeriesRenamer) (ts.SeriesList, error)

Changed will output a 1 if the value changed or 0 if not

func CompareOutputsAndExpected

func CompareOutputsAndExpected(t *testing.T, step int, start time.Time, expected []TestSeries,
	actual []*ts.Series)

CompareOutputsAndExpected compares the actual output with the expected output.

func ConstantLine

func ConstantLine(ctx *Context, value float64) (*ts.Series, error)

ConstantLine draws a horizontal line at a specified value

func ConstantSeries

func ConstantSeries(ctx *Context, value float64) (*ts.Series, error)

ConstantSeries returns a new constant series with a granularity of one data point per second

func Count

func Count(ctx *Context, seriesList ts.SeriesList, renamer SeriesListRenamer) (ts.SeriesList, error)

Count draws a horizontal line representing the number of nodes found in the seriesList.

func ErrInvalidPercentile

func ErrInvalidPercentile(percentile float64) error

ErrInvalidPercentile is used when the percentile specified is incorrect

func FetchWithBootstrap

func FetchWithBootstrap(ctx *Context, seriesList ts.SeriesList, duration time.Duration) (ts.SeriesList, error)

FetchWithBootstrap requests the same data but with a bootstrap period at the beginning.

func GetPercentile

func GetPercentile(input []float64, percentile float64, interpolate bool) float64

GetPercentile computes the percentile cut off for an array of floats

func GreaterThan

func GreaterThan(v, threshold float64) bool

GreaterThan is a ThresholdComparator function for when a value is greater than a threshold

func Head(series ts.SeriesList, n int) (ts.SeriesList, error)

Head returns the first n elements of a series list or the entire list

func Identity

func Identity(ctx *Context, name string) (ts.SeriesList, error)

Identity returns datapoints where the value equals the timestamp of the datapoint.

func LessThan

func LessThan(v, threshold float64) bool

LessThan is a ThresholdComparator function for when a value is less than a threshold

func NPercentile

func NPercentile(ctx *Context, in ts.SeriesList, percentile float64, pn PercentileNamer) (ts.SeriesList, error)

NPercentile returns percentile-percent of each series in the seriesList.

func NewTestSeriesList

func NewTestSeriesList(ctx *Context, start time.Time, inputs []TestSeries, step int) []*ts.Series

NewTestSeriesList creates a test series and values from a set of inputs

func NewTestSeriesValues

func NewTestSeriesValues(ctx context.Context, millisPerStep int, values []float64) ts.Values

NewTestSeriesValues creates a new ts.Values with given step size and values.

func Normalize

func Normalize(ctx *Context, input ts.SeriesList) (ts.SeriesList, time.Time, time.Time, int, error)

Normalize normalizes all input series to the same start time, step size, and end time.

func ParseInterval

func ParseInterval(s string) (time.Duration, error)

ParseInterval parses an interval string and returns the corresponding duration.

func PerSecond

func PerSecond(ctx *Context, in ts.SeriesList, renamer SeriesRenamer) (ts.SeriesList, error)

PerSecond computes the derivative between consecutive values in the a time series, taking into account the time interval between the values. It skips missing values, and calculates the derivative between consecutive non-missing values.

func Range

func Range(ctx *Context, series ts.SeriesList, renamer SeriesListRenamer) (*ts.Series, error)

Range distills down a set of inputs into the range of the series.

func RemoveByPercentile

func RemoveByPercentile(
	ctx *Context,
	in ts.SeriesList,
	percentile float64,
	pn PercentileNamer,
	tc ThresholdComparator,
) (ts.SeriesList, error)

RemoveByPercentile removes all series above or below the given percentile, as determined by the PercentileComparator

func RemoveEmpty

func RemoveEmpty(ctx *Context, input ts.SeriesList) (ts.SeriesList, error)

RemoveEmpty removes all series that have NaN data

func SafeMax added in v0.15.14

func SafeMax(input []float64) (float64, int)

SafeMax returns the maximum value of the input slice the number of NaNs in the input.

func SafeMin added in v0.15.14

func SafeMin(input []float64) (float64, int)

SafeMin returns the minimum value of the input slice the number of NaNs in the input.

func SafeSort

func SafeSort(input []float64) int

SafeSort sorts the input slice and returns the number of NaNs in the input.

func SafeSum added in v0.15.14

func SafeSum(input []float64) (float64, int)

SafeSum returns the sum of the input slice the number of NaNs in the input.

func Stdev

func Stdev(ctx *Context, in ts.SeriesList, points int, windowTolerance float64, renamer RenamerWithNumPoints) (ts.SeriesList, error)

Stdev takes one metric or a wildcard seriesList followed by an integer N. Draw the standard deviation of all metrics passed for the past N datapoints. If the ratio of null points in the window is greater than windowTolerance, skip the calculation.

func Transform

func Transform(ctx *Context, in ts.SeriesList, t Transformer, renamer SeriesRenamer) (ts.SeriesList, error)

Transform applies a specified ValueTransform to all values in each series, renaming each series with the given SeriesRenamer.

Types

type ChildContextOptions

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

ChildContextOptions is a set of options to pass when creating a child context.

func NewChildContextOptions

func NewChildContextOptions() ChildContextOptions

NewChildContextOptions returns an initialized ChildContextOptions struct.

func (*ChildContextOptions) AdjustTimeRange

func (o *ChildContextOptions) AdjustTimeRange(
	shiftStart, shiftEnd, expandStart, expandEnd time.Duration,
)

AdjustTimeRange will adjust the child context's time range.

type Context

type Context struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Context is the parameters to a query evaluation.

func NewConsolidationTestSeries

func NewConsolidationTestSeries(start, end time.Time, duration time.Duration) (*Context, []*ts.Series)

NewConsolidationTestSeries returns multiple static series for consolidation

func NewContext

func NewContext(options ContextOptions) *Context

NewContext creates a new context.

func NewTestContext

func NewTestContext() *Context

NewTestContext creates a new test context.

func (*Context) AddAsyncTasks

func (c *Context) AddAsyncTasks(count int)

AddAsyncTasks adds tracked asynchronous task(s)

func (*Context) Close

func (c *Context) Close() error

Close closes the context

func (*Context) DoneAsyncTask

func (c *Context) DoneAsyncTask()

DoneAsyncTask marks a single tracked asynchronous task complete

func (*Context) NewChildContext

func (c *Context) NewChildContext(opts ChildContextOptions) *Context

NewChildContext creates a child context. Child contexts can have any of their parameters modified, but share the same underlying storage context.

func (*Context) RegisterCloser

func (c *Context) RegisterCloser(closer context.Closer)

RegisterCloser registers a new Closer with the context.

func (*Context) RequestContext

func (c *Context) RequestContext() ctx.Context

RequestContext will provide the wrapped request context. Used for calls to m3 storage wrapper.

func (*Context) SetRequestContext

func (c *Context) SetRequestContext(reqCtx ctx.Context)

SetRequestContext sets the given context as the request context for this execution context. This is used for calls to the m3 storage wrapper.

func (*Context) TracingEnabled

func (c *Context) TracingEnabled() bool

TracingEnabled checks whether tracing is enabled for this context.

type ContextOptions

type ContextOptions struct {
	Start   time.Time
	End     time.Time
	Engine  QueryEngine
	Timeout time.Duration
	Limit   int
}

ContextOptions provides the options to create the context with

type Engine

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

The Engine for running queries

func NewEngine

func NewEngine(storage storage.Storage) *Engine

NewEngine creates a new query engine

func (*Engine) FetchByQuery

func (e *Engine) FetchByQuery(
	ctx context.Context,
	query string,
	options storage.FetchOptions,
) (*storage.FetchResult, error)

func (*Engine) Storage added in v0.15.17

func (e *Engine) Storage() storage.Storage

type MovingFunctionStorage added in v0.15.13

type MovingFunctionStorage struct {
	StepMillis     int
	Bootstrap      []float64
	Values         []float64
	BootstrapStart time.Time
}

MovingFunctionStorage is a special test construct for all moving functions

func (*MovingFunctionStorage) FetchByPath added in v0.15.13

func (s *MovingFunctionStorage) FetchByPath(
	ctx context.Context,
	path string,
	opts storage.FetchOptions,
) (*storage.FetchResult, error)

FetchByPath builds a new series from the input path

func (*MovingFunctionStorage) FetchByQuery added in v0.15.13

func (s *MovingFunctionStorage) FetchByQuery(
	ctx context.Context,
	query string,
	opts storage.FetchOptions,
) (*storage.FetchResult, error)

FetchByQuery builds a new series from the input query

type PercentileNamer

type PercentileNamer func(name string, percentile float64) string

PercentileNamer formats a string with a percentile

type PredicateFn

type PredicateFn func(v float64) bool

PredicateFn is a predicate function.

type QueryEngine

type QueryEngine interface {

	// FetchByQuery retrieves one or more time series based on a query.
	FetchByQuery(
		ctx context.Context,
		query string,
		options storage.FetchOptions,
	) (*storage.FetchResult, error)

	// Storage returns the engine's storage object.
	Storage() storage.Storage
}

QueryEngine is the generic engine interface.

type RenamerWithNumPoints

type RenamerWithNumPoints func(series *ts.Series, points int) string

RenamerWithNumPoints is a signature for renaming a single series that is passed to Stdev

type SeriesListRenamer

type SeriesListRenamer func(series ts.SeriesList) string

SeriesListRenamer is a signature for renaming multiple series into a single name

type SeriesRenamer

type SeriesRenamer func(series *ts.Series) string

SeriesRenamer is a signature for renaming a single series

type TestSeries

type TestSeries struct {
	Name string
	Data []float64
}

TestSeries is used to create a tsdb.timeSeries

type ThresholdComparator

type ThresholdComparator func(v, threshold float64) bool

ThresholdComparator compares two floats for other comparison functions such as Percentile checks.

type TimeRangeAdjustment

type TimeRangeAdjustment struct {
	OriginalStart time.Time
	OriginalEnd   time.Time
	ShiftStart    time.Duration
	ShiftEnd      time.Duration
	ExpandStart   time.Duration
	ExpandEnd     time.Duration
}

TimeRangeAdjustment is an applied time range adjustment.

type Trace

type Trace struct {
	// ActivityName is the name of the activity being traced.
	ActivityName string

	// Duration is the amount of time it took to execute the activity.
	Duration time.Duration

	// Inputs are the number of timeseries processed by the trace.
	Inputs []TraceStats

	// Outputs is the number of timeseries returned by the trace.
	Outputs TraceStats
}

A Trace is tracing information about a function or fetch within a query.

type TraceStats

type TraceStats struct {
	NumSeries int // number of timeseries being acted on
}

TraceStats tracks the number of timeseries used by a trace.

type Tracer

type Tracer func(t Trace)

A Tracer is used to record a Trace.

type TransformFunc

type TransformFunc func(float64) float64

TransformFunc is used by Transform to apply a function to all values in a series.

func Derivative

func Derivative() TransformFunc

Derivative returns a function that computes the derivative among the values it has seen

func Filter

func Filter(fn PredicateFn) TransformFunc

Filter removes data that does not satisfy a given predicate.

func Integral

func Integral() TransformFunc

Integral returns a function that accumulates values it has seen

func IsNonNull

func IsNonNull() TransformFunc

IsNonNull replaces datapoints that are non-null with 1, and null values with 0. This is useful for understanding which series have data at a given point in time (i.e. to count which servers are alive).

func Logarithm

func Logarithm() TransformFunc

Logarithm takes one series or a series list, and draws the y-axis in logarithmic format. Only support base 10 logarithms.

func MaintainNaNTransformer

func MaintainNaNTransformer(f TransformFunc) TransformFunc

MaintainNaNTransformer only applies a given ValueTransformer to non-NaN values.

func NonNegativeDerivative

func NonNegativeDerivative(maxValue float64) TransformFunc

NonNegativeDerivative returns a function that computes the derivative among the values it has seen but ignores datapoints that trend down

func Offset

func Offset(factor float64) TransformFunc

Offset adds a value to each element of a series list.

func Scale

func Scale(scale float64) TransformFunc

Scale multiplies each element of a series list by a given value.

func TransformNull

func TransformNull(value float64) TransformFunc

TransformNull transforms all nulls in a series to a value.

type TransformFuncFactory

type TransformFuncFactory func() TransformFunc

TransformFuncFactory creates transformation functions

type Transformer

type Transformer interface {
	// Apply applies the transformation
	Apply(value float64) float64

	// Reset resets the state
	Reset()
}

Transformer transforms a value

func NewStatelessTransformer

func NewStatelessTransformer(fn TransformFunc) Transformer

NewStatelessTransformer creates a new stateless transformer

Jump to

Keyboard shortcuts

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