eventsim

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package eventsim enables deploying event simulation streams, by setting the "source" field in the stream spec to "eventsim".

Index

Constants

View Source
const (
	SourceTypeId                     = "eventsim"
	DefaultMaxFractionDigits         = 2
	DefaultSimResolutionMilliseconds = 5000
	EventGenTypeRandom               = "random"
	EventGenTypeSinusoid             = "sinusoid"
	TimestampLayoutIsoSeconds        = "2006-01-02T15:04:05Z"
	TimestampLayoutIsoMillis         = "2006-01-02T15:04:05.000Z"
	TimestampLayoutIsoMicros         = "2006-01-02T15:04:05.000000Z"
)

Variables

View Source
var DefaultCharset = []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")

Functions

func NewExtractorFactory

func NewExtractorFactory(charsets map[string][]rune) entity.ExtractorFactory

Types

type EventGeneration

type EventGeneration struct {
	Type          string `json:"type"`
	MinCount      int    `json:"minCount"`
	MaxCount      int    `json:"maxCount"`
	PeriodSeconds int    `json:"periodSeconds"`
	PeakTime      string `json:"peakTime"`
}

EventGeneration specifies how many events should be generated for each trigger.

"Type" can be one of the following:

"random"   --> random value between "MinCount" and "MaxCount"
"sinosoid" --> the number of events generated over time has a sine wave form with
               period specified in "PeriodSeconds", peak-to-peak amplitude in
               "MaxCount" - "MinCount", and the timestamp for a peak time in "PeakTime"
               (required layout: TimestampLayoutIsoSeconds). To achieve a less perfect
               wave, use the Jitter option with a specified randomized timestamp field.
""         --> If empty string (or json field omitted) a single event will be
               generated for each sim resolution trigger.

type EventSpec

type EventSpec struct {
	Fields []FieldSpec `json:"fields"`
}

EventSpec specifies the event schema

type ExtractorFactory

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

func (*ExtractorFactory) Close

func (ef *ExtractorFactory) Close(ctx context.Context) error

func (*ExtractorFactory) NewExtractor

func (ef *ExtractorFactory) NewExtractor(ctx context.Context, c entity.Config) (entity.Extractor, error)

func (*ExtractorFactory) SourceId

func (ef *ExtractorFactory) SourceId() string

type FieldFrequencyRange

type FieldFrequencyRange struct {
	Start int
	End   int
	Max   int
	Value any
}

FieldFrequencyRange is used for internal conversion of any provided dimensions that should be randomized with a given distribution.

type FieldFrequencyRanges added in v0.11.1

type FieldFrequencyRanges map[string][]FieldFrequencyRange

type FieldOverride added in v0.11.1

type FieldOverride struct {
	Disabled  bool `json:"disabled"` // convenience toggle for the override
	Condition struct {
		Field string `json:"field"`
		Value string `json:"value"`
	} `json:"condition"`
	Fields []FieldSpec `json:"fields"`
}

FieldOverride can be used to modify one or more generated fields if certain fields contains specific values. This could, for example, be used to temporarily produce outlier events for specific dimension/field values, having specific field values not following the normal EventSpec based pattern.

type FieldSpec

type FieldSpec struct {

	// Name of the field on sjson format (see github.com/tidwall/sjson)
	Field string `json:"field"`

	// One of the below options can be present in each field spec
	PredefinedValues []PredefinedValue `json:"predefinedValues"`
	RandomizedValue  *RandomizedValue  `json:"randomizedValue"`
	SetOfStrings     *SetOfStrings     `json:"setOfStrings"`
}

FieldSpec specifies how each field should be generated

func GenerateFieldsFromSetOfStringsSpec added in v0.9.0

func GenerateFieldsFromSetOfStringsSpec(fields []FieldSpec) (generatedFields []FieldSpec)

GenerateFieldsFromSetOfStringsSpec processes the provided field spec and returns a new field spec containing the generated set of predefined values as was required in the setOfFields part of the original input spec.

type PredefinedValue

type PredefinedValue struct {

	// Value can be any json scalar value (string, number, boolean, null)
	Value any `json:"value"`

	// FrequencyFactor specifies the probability of each provided pre-defined value
	// to be set. Any value can be used here, but obviously having the sum for all
	// items being 10 or 100 is the easiest for achieving expected distribution.
	FrequencyFactor int `json:"frequencyFactor"`
}

PredefinedValue enables a field to have one of many provided values set with a probability based on the FrequencyFactor.

type RandomizedValue

type RandomizedValue struct {

	// Type is mandatory and have the following supported values:
	//
	//     "int", "integer"
	//     "float"
	//     "string"
	//     "bool"
	//     "isoTimestampMilliseconds"
	//     "isoTimestampMicroseconds"
	//     "uuid"
	//
	// Any other value will lead to an error notification on the notify chan.
	//
	Type string `json:"type"`

	// Min and Max specifies the range of the randomized value
	Min float64 `json:"min"`
	Max float64 `json:"max"`

	// Charset is only applicable for "string" type and specifies which character set
	// to use for string generation. If omitted a default character set will be used.
	// If a value is provided here it needs to have a matching character set added as
	// part of factory creation input config.
	Charset string `json:"charset"`

	// MaxFractionDigits is only applicable for "float" type and specifies how many
	// fraction digits should be provided. If omitted DefaultMaxFractionDigits will
	// be used.
	MaxFractionDigits int `json:"maxFractionDigits"` // only applicable for float types

	// JitterMilliseconds is only applicable for the timestamp types and adds a +-delta
	// duration to the current timestamp, based on a random value from 0 to JitterMilliseconds.
	JitterMilliseconds int `json:"jitterMilliseconds"`
}

RandomizedValue generates a random value for a field.

type SetOfStrings added in v0.9.0

type SetOfStrings struct {
	Amount        int      `json:"amount"`
	Prefix        string   `json:"prefix"`
	FrequencyMin  int      `json:"frequencyMin"`
	FrequencyMax  int      `json:"frequencyMax"`
	ExcludeValues []string `json:"excludeValues"`
}

SetOfStrings generates a set of string values from which a random value will be assigned to the field. It has similar functionality as PredefinedValues but with two differences: 1) Convenient when the number of wanted predefined values becomes very high, e.g. simulating high cardinality dimensions. 2) It only supports string values.

The format of the generated strings is "<prefix>n" where 'n' is a number from 1 to "Amount".

If FrequencyMin and FrequencyMax is omitted or set to 0 (or with invalid values), all the generated string values will have equal frequency factor (weight) when being randomly chosen as the value for the field. Otherwise a random value will be given to the string value to make them occur in the events with different frequency, according to the specified frequency range.

Field values that should not be present in the generated events must be specified in the ExcludeValues slice.

type SourceSpec added in v0.6.3

type SourceSpec struct {
	// The trigger interval for each event generation execution. If set to 0 or omitted
	// in the spec, it will be set to DefaultSimResolutionMilliseconds.
	SimResolutionMilliseconds int `json:"simResolutionMilliseconds"`

	// Event schema and field generation specifications
	EventGeneration EventGeneration `json:"eventGeneration"`
	EventSpec       EventSpec       `json:"eventSpec"`
	Overrides       []FieldOverride `json:"overrides"`
}

SourceSpec specifies the schema of the source part of the stream spec

Jump to

Keyboard shortcuts

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