common

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ErrScaleIsZero = "scale cannot be 0"
View Source
const (
	// Use case choices (make sure to update TestGetConfig if adding a new one)
	UseCaseIoT = "iot"
)

Variables

View Source
var UseCaseChoices = []string{
	UseCaseIoT,
}

Functions

func RandomByteStringSliceChoice

func RandomByteStringSliceChoice(s [][]byte) []byte

RandomByteStringSliceChoice returns a random byte string slice from the provided slice of byte string slices.

func RandomInt64SliceChoice

func RandomInt64SliceChoice(s []int64) int64

RandomInt64SliceChoice returns a random int64 from an int64 slice.

func RandomStringSliceChoice

func RandomStringSliceChoice(s []string) string

RandomStringSliceChoice returns a random string from the provided slice of string slices.

Types

type BaseConfig

type BaseConfig struct {
	Format string `yaml:"format,omitempty" mapstructure:"format,omitempty"`
	Use    string `yaml:"use-case" mapstructure:"use-case"`

	Scale uint64

	TimeStart string `yaml:"timestamp-start" mapstructure:"timestamp-start"`
	TimeEnd   string `yaml:"timestamp-end" mapstructure:"timestamp-end"`

	Seed  int64
	Debug int    `yaml:"debug,omitempty" mapstructure:"debug,omitempty"`
	File  string `yaml:"file,omitempty" mapstructure:"file,omitempty"`
}

BaseConfig is a data struct that includes the common flags or configuration options shared across different types of Generators. These include things like the data format (i.e., which database system is this for), a PRNG seed, etc.

func (*BaseConfig) AddToFlagSet

func (c *BaseConfig) AddToFlagSet(fs *pflag.FlagSet)

func (*BaseConfig) Validate

func (c *BaseConfig) Validate() error

type BaseSimulator

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

BaseSimulator generates data similar to truck readings.

func (*BaseSimulator) Fields

func (s *BaseSimulator) Fields() map[string][]string

Fields returns all the simulated measurements for the device.

func (*BaseSimulator) Finished

func (s *BaseSimulator) Finished() bool

Finished tells whether we have simulated all the necessary points.

func (*BaseSimulator) Headers

func (s *BaseSimulator) Headers() *GeneratedDataHeaders

func (*BaseSimulator) Next

func (s *BaseSimulator) Next(p *data.Point) bool

Next advances a Point to the next state in the generator.

func (*BaseSimulator) TagKeys

func (s *BaseSimulator) TagKeys() []string

TagKeys returns all the tag keys for the device.

func (*BaseSimulator) TagTypes

func (s *BaseSimulator) TagTypes() []string

TagTypes returns the type for each tag, extracted from the generated values.

type BaseSimulatorConfig

type BaseSimulatorConfig struct {
	// Start is the beginning time for the Simulator
	Start time.Time
	// End is the ending time for the Simulator
	End time.Time
	// InitGeneratorScale is the number of Generators to start with in the first reporting period
	InitGeneratorScale uint64
	// GeneratorScale is the total number of Generators to have in the last reporting period
	GeneratorScale uint64
	// GeneratorConstructor is the function used to create a new Generator given an id number and start time
	GeneratorConstructor func(i int, start time.Time) Generator
}

BaseSimulatorConfig is used to create a BaseSimulator.

func (*BaseSimulatorConfig) NewSimulator

func (sc *BaseSimulatorConfig) NewSimulator(interval time.Duration, limit uint64) Simulator

NewSimulator produces a Simulator that conforms to the given config over the specified interval.

type ClampedRandomWalkDistribution

type ClampedRandomWalkDistribution struct {
	Step Distribution
	Min  float64
	Max  float64

	State float64 // optional
}

ClampedRandomWalkDistribution is a stateful random walk, with minimum and maximum bounds. Initialize it with a Min, Max, and an underlying distribution, which is used to compute the new step value.

func CWD

func CWD(step Distribution, min, max, state float64) *ClampedRandomWalkDistribution

CWD returns a new ClampedRandomWalkDistribution based on a given distribution and optional starting state

func (*ClampedRandomWalkDistribution) Advance

func (d *ClampedRandomWalkDistribution) Advance()

Advance computes the next value of this distribution and stores it.

func (*ClampedRandomWalkDistribution) Get

Get returns the last computed value for this distribution.

type ConstantDistribution

type ConstantDistribution struct {
	State float64
}

ConstantDistribution is a stateful distribution that always returns the same value

func (*ConstantDistribution) Advance

func (d *ConstantDistribution) Advance()

Advance does nothing in a constant distribution

func (*ConstantDistribution) Get

func (d *ConstantDistribution) Get() float64

Get returns the last computed value for this distribution.

type DataGeneratorConfig

type DataGeneratorConfig struct {
	BaseConfig            `yaml:"base"`
	Limit                 uint64        `yaml:"max-data-points" mapstructure:"max-data-points"`
	InitialScale          uint64        `yaml:"initial-scale" mapstructure:"initial-scale" `
	LogInterval           time.Duration `yaml:"log-interval" mapstructure:"log-interval"`
	InterleavedGroupID    uint          `yaml:"interleaved-generation-group-id" mapstructure:"interleaved-generation-group-id"`
	InterleavedNumGroups  uint          `yaml:"interleaved-generation-groups" mapstructure:"interleaved-generation-groups"`
	MaxMetricCountPerHost uint64        `yaml:"max-metric-count" mapstructure:"max-metric-count"`
}

DataGeneratorConfig is the GeneratorConfig that should be used with a DataGenerator. It includes all the fields from a BaseConfig, as well as some options that are specific to generating the data for database write operations, such as the initial scale and how spaced apart data points should be in time.

func (*DataGeneratorConfig) AddToFlagSet

func (c *DataGeneratorConfig) AddToFlagSet(fs *pflag.FlagSet)

func (*DataGeneratorConfig) Validate

func (c *DataGeneratorConfig) Validate() error

Validate checks that the values of the DataGeneratorConfig are reasonable.

type Distribution

type Distribution interface {
	Advance()
	Get() float64 // should be idempotent
}

Distribution provides an interface to model a statistical distribution.

type FloatPrecision

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

FloatPrecision is a distribution wrapper which specifies the float value precision of the underlying distribution.

func FP

func FP(step Distribution, precision int) *FloatPrecision

FP creates a new FloatPrecision distribution wrapper with a given distribution and precision value. Precision value is clamped to [0,5] to avoid floating point calculation errors.

func (*FloatPrecision) Advance

func (f *FloatPrecision) Advance()

Advance calls the underlying distribution Advance method.

func (*FloatPrecision) Get

func (f *FloatPrecision) Get() float64

Get returns the value from the underlying distribution with adjusted float value precision.

type GeneratedDataHeaders

type GeneratedDataHeaders struct {
	TagTypes  []string
	TagKeys   []string
	FieldKeys map[string][]string
}

type Generator

type Generator interface {
	Measurements() []SimulatedMeasurement
	Tags() []Tag
	TickAll(d time.Duration)
}

Generator is a single entity which generates data from its respective measurements.

type GeneratorConfig

type GeneratorConfig interface {
	// AddToFlagSet adds all the config options to a FlagSet, for easy use with CLIs
	AddToFlagSet(fs *pflag.FlagSet)
	// Validate checks that configuration is valid and ready to be consumed by a Generator
	Validate() error
}

GeneratorConfig is an interface that defines a configuration that is used by Generators to govern their behavior. The interface methods provide a way to use the GeneratorConfig with the command-line via flag.FlagSet and a method to validate the config is actually valid.

type LabeledDistributionMaker

type LabeledDistributionMaker struct {
	Label             []byte
	DistributionMaker func() Distribution
}

LabeledDistributionMaker combines a distribution maker with a label.

type LazyDistribution

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

LazyDistribution is a distribution that can change it's value only if a "motivation" distribution provides a value above a specified threshold. Otherwise it remains the same.

func LD

func LD(motive, dist Distribution, threshold float64) *LazyDistribution

LD returns a new LazyDistribution that returns a new value from "dist", if the "motavation" distribution, fires above the threshold.

func (*LazyDistribution) Advance

func (d *LazyDistribution) Advance()

Advance computes the next value of this distribution.

func (*LazyDistribution) Get

func (d *LazyDistribution) Get() float64

Get returns the last computed value for this distribution.

type MonotonicRandomWalkDistribution

type MonotonicRandomWalkDistribution struct {
	Step  Distribution
	State float64
}

MonotonicRandomWalkDistribution is a stateful random walk that only increases. Initialize it with a Start and an underlying distribution, which is used to compute the new step value. The sign of any value of the u.d. is always made positive.

func MWD

MWD creates a new MonotonicRandomWalkDistribution with a given distribution and initial state

func (*MonotonicRandomWalkDistribution) Advance

func (d *MonotonicRandomWalkDistribution) Advance()

Advance computes the next value of this distribution and stores it.

func (*MonotonicRandomWalkDistribution) Get

Get returns the last computed value for this distribution.

type NormalDistribution

type NormalDistribution struct {
	Mean   float64
	StdDev float64
	// contains filtered or unexported fields
}

NormalDistribution models a normal distribution (stateless).

func ND

func ND(mean, stddev float64) *NormalDistribution

ND creates a new normal distribution with the given mean/stddev

func (*NormalDistribution) Advance

func (d *NormalDistribution) Advance()

Advance advances this distribution. Since the distribution is stateless, this just overwrites the internal cache value.

func (*NormalDistribution) Get

func (d *NormalDistribution) Get() float64

Get returns the last computed value for this distribution.

type RandomWalkDistribution

type RandomWalkDistribution struct {
	Step Distribution

	State float64 // optional
}

RandomWalkDistribution is a stateful random walk. Initialize it with an underlying distribution, which is used to compute the new step value.

func WD

WD creates a new RandomWalkDistribution based on a given distribution and starting state

func (*RandomWalkDistribution) Advance

func (d *RandomWalkDistribution) Advance()

Advance computes the next value of this distribution and stores it.

func (*RandomWalkDistribution) Get

Get returns the last computed value for this distribution.

type SimulatedMeasurement

type SimulatedMeasurement interface {
	Tick(time.Duration)
	ToPoint(*data.Point)
}

SimulatedMeasurement simulates one measurement (e.g. Redis for DevOps).

type Simulator

type Simulator interface {
	Finished() bool
	Next(*data.Point) bool
	Fields() map[string][]string
	TagKeys() []string
	TagTypes() []string
	Headers() *GeneratedDataHeaders
}

Simulator simulates a use case.

type SimulatorConfig

type SimulatorConfig interface {
	NewSimulator(time.Duration, uint64) Simulator
}

SimulatorConfig is an interface to create a Simulator from a time.Duration.

type SubsystemMeasurement

type SubsystemMeasurement struct {
	Timestamp     time.Time
	Distributions []Distribution
}

SubsystemMeasurement represents a collection of measurement distributions and a start time.

func NewSubsystemMeasurement

func NewSubsystemMeasurement(start time.Time, numDistributions int) *SubsystemMeasurement

NewSubsystemMeasurement creates a new SubsystemMeasurement with provided start time and number of distributions.

func NewSubsystemMeasurementWithDistributionMakers

func NewSubsystemMeasurementWithDistributionMakers(start time.Time, makers []LabeledDistributionMaker) *SubsystemMeasurement

NewSubsystemMeasurementWithDistributionMakers creates a new SubsystemMeasurement with start time and distribution makers which are used to create the necessary distributions.

func (*SubsystemMeasurement) Tick

func (m *SubsystemMeasurement) Tick(d time.Duration)

Tick advances all the distributions for the SubsystemMeasurement.

func (*SubsystemMeasurement) ToPoint

func (m *SubsystemMeasurement) ToPoint(p *data.Point, measurementName []byte, labels []LabeledDistributionMaker)

ToPoint fills the provided serialize.Point with measurements from the SubsystemMeasurement.

func (*SubsystemMeasurement) ToPointAllInt64

func (m *SubsystemMeasurement) ToPointAllInt64(p *data.Point, measurementName []byte, labels []LabeledDistributionMaker)

ToPointAllInt64 fills in a serialize.Point with a given measurementName and all vales from the distributions stored as int64. The labels for each field are given by the supplied []LabeledDistributionMaker, assuming that the distributions are in the same order.

type Tag

type Tag struct {
	Key   []byte
	Value interface{}
}

Tag is a key-value pair of information which is used to tag a generator

type UniformDistribution

type UniformDistribution struct {
	Low  float64
	High float64
	// contains filtered or unexported fields
}

UniformDistribution models a uniform distribution (stateless).

func UD

func UD(low, high float64) *UniformDistribution

UD creates a new uniform distribution with the given range

func (*UniformDistribution) Advance

func (d *UniformDistribution) Advance()

Advance advances this distribution. Since the distribution is stateless, this just overwrites the internal cache value.

func (*UniformDistribution) Get

func (d *UniformDistribution) Get() float64

Get returns the last computed value for this distribution.

Jump to

Keyboard shortcuts

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