generator

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyGens = fmt.Errorf("no Generators")

ErrEmptyGens represents that there are no Generators

View Source
var ErrGenOver = fmt.Errorf("the last point reached")

ErrGenOver shows the generation is over

View Source
var ErrNewCounter = fmt.Errorf("value and deviation are meaningless")

ErrNewCounter means that the value and the deviation are meaningless

View Source
var ErrNotImplemented = fmt.Errorf("generator type is not implemented")

ErrNotImplemented represents the generator is not implemented yet

View Source
var ErrProbabilityStart = fmt.Errorf("Probability start is uncorrect")

ErrProbabilityStart is uncorrect

View Source
var ErrWrongType error = fmt.Errorf("type is not valid")

ErrWrongType represents the bad generator type name

Functions

This section is empty.

Types

type Const

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

Const represents generator for constant values. When deviation is set, each value is calculated around the first value

func NewConst

func NewConst(name string, start, stop, step uint, randomizeStart bool, value, deviation float64, probabilityStart uint8) (*Const, error)

NewConst returns new generator for constant points. Possibly it can randomize values around constant.

func (*Const) Deviation

func (b *Const) Deviation() float64

Deviation returns the generator's deviation

func (*Const) Name

func (b *Const) Name() string

Name returns the metric name

func (*Const) Next

func (c *Const) Next() error

Next sets value and time for the next point

func (*Const) Point

func (b *Const) Point() []byte

Point returns the metric in carbon format, e.g. 'metric.name 123.33 1234567890\n'

func (*Const) RandomizeStart

func (b *Const) RandomizeStart(randomizeStart bool)

func (*Const) SetStop

func (b *Const) SetStop(stop uint)

SetStop sets stop to a given value

func (*Const) Step

func (b *Const) Step() uint

Step returns the generator step

func (*Const) Stop

func (b *Const) Stop() uint

Stop returns value of stop field for the generator

func (*Const) Time

func (b *Const) Time() uint

Time returns the generator current time

func (*Const) Type

func (b *Const) Type() Type

Type returns the generator type

func (*Const) TypeName

func (b *Const) TypeName() string

TypeName returns the name for generator type

func (*Const) Value

func (b *Const) Value() float64

Value returns the generator step

func (*Const) WithDeviation

func (b *Const) WithDeviation(deviation float64) *base

WithDeviation deviation for the generator

func (*Const) WithName

func (b *Const) WithName(name string) *base

WithName sets the metric name for generator

func (*Const) WithStep

func (b *Const) WithStep(step uint) *base

WithStep sets the step for the generator

func (*Const) WriteTo

func (b *Const) WriteTo(w io.Writer) (int64, error)

type Counter

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

Counter represents generator for growing-up metrics

func NewCounter

func NewCounter(name string, start, stop, step uint, randomizeStart bool, value, deviation float64, probabilityStart uint8) (*Counter, error)

NewCounter returns new generator for growing points. Starting value is an increment as well. Possibly it can randomize values around increment. When deviation is set, it the next value won't be less then previous.

func (*Counter) Deviation

func (b *Counter) Deviation() float64

Deviation returns the generator's deviation

func (*Counter) Name

func (b *Counter) Name() string

Name returns the metric name

func (*Counter) Next

func (c *Counter) Next() error

Next sets value and time for the next point

func (*Counter) Point

func (b *Counter) Point() []byte

Point returns the metric in carbon format, e.g. 'metric.name 123.33 1234567890\n'

func (*Counter) RandomizeStart

func (b *Counter) RandomizeStart(randomizeStart bool)

func (*Counter) SetStop

func (b *Counter) SetStop(stop uint)

SetStop sets stop to a given value

func (*Counter) Step

func (b *Counter) Step() uint

Step returns the generator step

func (*Counter) Stop

func (b *Counter) Stop() uint

Stop returns value of stop field for the generator

func (*Counter) Time

func (b *Counter) Time() uint

Time returns the generator current time

func (*Counter) Type

func (b *Counter) Type() Type

Type returns the generator type

func (*Counter) TypeName

func (b *Counter) TypeName() string

TypeName returns the name for generator type

func (*Counter) Value

func (b *Counter) Value() float64

Value returns the generator step

func (*Counter) WithDeviation

func (b *Counter) WithDeviation(deviation float64) *base

WithDeviation deviation for the generator

func (*Counter) WithName

func (b *Counter) WithName(name string) *base

WithName sets the metric name for generator

func (*Counter) WithStep

func (b *Counter) WithStep(step uint) *base

WithStep sets the step for the generator

func (*Counter) WriteTo

func (b *Counter) WriteTo(w io.Writer) (int64, error)

type Generator

type Generator interface {
	// Next calculates next value of generator and returns ErrGenOver when the latest point is reached
	Next() error
	// Point returns the metric in carbon format, e.g. 'metric.name 123.33 1234567890\n'
	Point() []byte
	// SetStop sets the stop field for the Generator
	SetStop(stop uint)
	// Stop returns the current value for the stop field
	Stop() uint
	// WriteTo writes the point []byte representation to a given io.Writer
	WriteTo(io.Writer) (int64, error)
}

Generator represents

func New

func New(typeName, name string, start, stop, step uint, randomizeStart bool, value, deviation float64, probabilityStart uint8) (Generator, error)

New returns new Generator for given parameters

type Generators

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

Generators is a slice of Generator. Next() and Point() works accordingly

func NewExpand

func NewExpand(typeName, expandableName string, start, stop, step uint, randomizeStart bool, value, deviation float64, probabilityStrat uint8) (Generators, error)

NewExpand expands name as shell expansion (e.g. metric.name{1..3} will produce 3 metrics metric.name1, metric.name2 and metric.name3) and creates slice of Generator with names.

func (*Generators) List

func (gg *Generators) List() []Generator

List returns the list of []Generator

func (*Generators) Next

func (gg *Generators) Next() error

Next iterates over each element and calls Next. If any of calls returns an error, it breaks

func (*Generators) Point

func (gg *Generators) Point() []byte

Point returns []byte representation of all generator Point() calls

func (*Generators) Randomized

func (gg *Generators) Randomized() bool

Randomized shows if expanded generators have randomized start timestamp

func (*Generators) SetList

func (gg *Generators) SetList(gens []Generator)

SetList replaces existing []Generator with a given one

func (*Generators) SetStop

func (gg *Generators) SetStop(stop uint)

SetStop invokes the according method for each Generagor

func (*Generators) Step

func (gg *Generators) Step() uint

Step returns the common step for Generators

func (*Generators) WriteAllTo

func (gg *Generators) WriteAllTo(w io.Writer) (int64, error)

WriteAllTo writes all points for Generators to io.Writer

func (*Generators) WriteAllToWithContext

func (gg *Generators) WriteAllToWithContext(ctx context.Context, w io.Writer) (int64, error)

WriteAllToWithContext writes all points, but may be stopped by the passing a struct to a stop channel

func (*Generators) WriteTo

func (gg *Generators) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes point's []byte representation to io.Writer

type Probability added in v0.3.0

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

type Random

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

Random works like Const, but each next value is calculated like value±deviation

func NewRandom

func NewRandom(name string, start, stop, step uint, randomizeStart bool, value, deviation float64, probabilityStart uint8) (*Random, error)

NewRandom returns new generator for growing points. Without deviation it behaves like constant.

func (*Random) Deviation

func (b *Random) Deviation() float64

Deviation returns the generator's deviation

func (*Random) Name

func (b *Random) Name() string

Name returns the metric name

func (*Random) Next

func (r *Random) Next() error

Next sets value and time for the next point

func (*Random) Point

func (b *Random) Point() []byte

Point returns the metric in carbon format, e.g. 'metric.name 123.33 1234567890\n'

func (*Random) RandomizeStart

func (b *Random) RandomizeStart(randomizeStart bool)

func (*Random) SetStop

func (b *Random) SetStop(stop uint)

SetStop sets stop to a given value

func (*Random) Step

func (b *Random) Step() uint

Step returns the generator step

func (*Random) Stop

func (b *Random) Stop() uint

Stop returns value of stop field for the generator

func (*Random) Time

func (b *Random) Time() uint

Time returns the generator current time

func (*Random) Type

func (b *Random) Type() Type

Type returns the generator type

func (*Random) TypeName

func (b *Random) TypeName() string

TypeName returns the name for generator type

func (*Random) Value

func (b *Random) Value() float64

Value returns the generator step

func (*Random) WithDeviation

func (b *Random) WithDeviation(deviation float64) *base

WithDeviation deviation for the generator

func (*Random) WithName

func (b *Random) WithName(name string) *base

WithName sets the metric name for generator

func (*Random) WithStep

func (b *Random) WithStep(step uint) *base

WithStep sets the step for the generator

func (*Random) WriteTo

func (b *Random) WriteTo(w io.Writer) (int64, error)

type Type

type Type uint8

Type represents the generator type

const (
	// UndefinedType is the default value
	UndefinedType Type = iota
	// ConstType represent metrics with constant values
	ConstType
	// CounterType represents metrics with growing values
	CounterType
	// RandomType represents metrics with random values
	RandomType
)

func GetType

func GetType(typeName string) (Type, error)

GetType returns the Type by name or rises ErrWrongType error if name is invalid

Jump to

Keyboard shortcuts

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