digest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package digest contains metrics handling model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventTypeStrings

func EventTypeStrings() []string

EventTypeStrings returns a slice of all String values of the enum

func LevelStrings

func LevelStrings() []string

LevelStrings returns a slice of all String values of the enum

func MetricTypeStrings

func MetricTypeStrings() []string

MetricTypeStrings returns a slice of all String values of the enum

func StateStrings

func StateStrings() []string

StateStrings returns a slice of all String values of the enum

func Unit

func Unit(value float64) (int, int)

Unit returns unit and precision for displaying a given value.

func ValueTypeStrings

func ValueTypeStrings() []string

ValueTypeStrings returns a slice of all String values of the enum

Types

type Aggregate

type Aggregate map[string]float64

Aggregate contains aggregated values by aggregation name.

type Aggregates

type Aggregates map[string]Aggregate

Aggregates contains aggregetes by metric name.

func (Aggregates) Time

func (a Aggregates) Time() time.Time

Time returns "value" aggregate for "time" metric.

type ConfigData

type ConfigData map[string]interface{}

ConfigData holds "config" event data.

type Digest

type Digest struct {
	Config     map[string]interface{}
	Param      ParamData
	Metrics    Metrics
	Cumulative Aggregates
	Snapshot   Aggregates
	Start      time.Time
	Stop       time.Time
	Thresholds *Thresholds
	EventType  EventType
	State      State
	Playback   bool
}

Digest is the metrics digest data model.

func (*Digest) Duration

func (d *Digest) Duration() time.Duration

Duration returns test run time intervall as duration.

func (*Digest) FindMetric

func (d *Digest) FindMetric(metric string) (*Metric, bool)

FindMetric finds parent metric's metadata by metric name.

func (*Digest) GetMetric

func (d *Digest) GetMetric(metric string) (*Metric, bool)

GetMetric returns metric metadata by metric name (exact match).

func (*Digest) GetState

func (d *Digest) GetState() State

GetState returns state or StateWaiting if digest is nil.

func (*Digest) Period

func (d *Digest) Period() time.Duration

Period returns period parameter as duration.

func (*Digest) ProgressLabel

func (d *Digest) ProgressLabel() string

ProgressLabel return elapsed / total value as string.

func (*Digest) ProgressPercent

func (d *Digest) ProgressPercent() float64

ProgressPercent return percent value of elapsed time.

func (*Digest) Time

func (d *Digest) Time() time.Time

Time returns the latest "time" metric value from event stream.

func (*Digest) TimeLeft

func (d *Digest) TimeLeft() time.Duration

TimeLeft returns the remaining time as duration.

func (*Digest) TimePassed

func (d *Digest) TimePassed() time.Duration

TimePassed returns elapsed time as duration.

type Digester

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

Digester is the metrics handling model.

func NewDigester

func NewDigester() *Digester

NewDigester returns new Digester instance.

func (*Digester) Collect

func (d *Digester) Collect(metric string, aggregate string)

Collect registers metric name and aggregate name pair to collect series.

func (*Digester) Digest

func (d *Digester) Digest() *Digest

Digest returns the latest update result.

func (*Digester) Serie

func (d *Digester) Serie(metric string, aggregate string) []float64

Serie returns data series for a given metric and aggregate name.

func (*Digester) Update

func (d *Digester) Update(event *Event) *Digest

Update process new event and returns a digest data.

type Event

type Event struct {
	Type EventType   `json:"event,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

Event describes an SSE event.

type EventType

type EventType int

EventType defines the type of the SSE event.

const (
	EventTypeConfig     EventType = iota // EventTypeConfig mean "config" SSE event.
	EventTypeParam                       // EventTypeParam mean "param" SSE event.
	EventTypeMetric                      // EventTypeMetric mean "metric" SSE event.
	EventTypeSnapshot                    // EventTypeSnapshot mean "snapshot" SSE event.
	EventTypeCumulative                  // EventTypeCumulative mean "cumulative" SSE event.
	EventTypeStart                       // EventTypeStart mean "start" SSE event.
	EventTypeStop                        // EventTypeStop mean "stop" SSE event.
	EventTypeConnect                     // EventTypeConnect mean SSE channel connected.
	EventTypeDisconnect                  // EventTypeDisconnect mean SSE channel disconnected.
)

func EventTypeString

func EventTypeString(s string) (EventType, error)

EventTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func EventTypeValues

func EventTypeValues() []EventType

EventTypeValues returns all values of the enum

func (EventType) IsAEventType

func (i EventType) IsAEventType() bool

IsAEventType returns "true" if the value is listed in the enum definition. "false" otherwise

func (EventType) MarshalJSON

func (i EventType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for EventType

func (EventType) MarshalText

func (i EventType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for EventType

func (EventType) String

func (i EventType) String() string

func (*EventType) UnmarshalJSON

func (i *EventType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for EventType

func (*EventType) UnmarshalText

func (i *EventType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for EventType

type Failure

type Failure struct {
	Metric     string
	Thresholds []string
}

Failure holds thresholds failure parameters.

type Level

type Level int

Level defines log and alert levels.

const (
	None    Level = iota // None means regular.
	Info                 // Info means informational.
	Ready                // Ready means everything is ok.
	Notice               // Notice means something happened.
	Warning              // Warning means possible problem.
	Error                // Error means error happened.
)

func LevelString

func LevelString(s string) (Level, error)

LevelString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func LevelValues

func LevelValues() []Level

LevelValues returns all values of the enum

func (Level) IsALevel

func (i Level) IsALevel() bool

IsALevel returns "true" if the value is listed in the enum definition. "false" otherwise

func (Level) MarshalText

func (i Level) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Level

func (Level) String

func (i Level) String() string

func (*Level) UnmarshalText

func (i *Level) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Level

type Metric

type Metric struct {
	Name     string     `json:"name,omitempty"`
	Type     MetricType `json:"type,omitempty"`
	Contains ValueType  `json:"contains,omitempty"`
	Tainted  bool       `json:"tainted,omitempty"`
}

Metric holds metric metadata.

type MetricType

type MetricType int

A MetricType specifies the type of a metric.

const (
	MetricTypeCounter MetricType = iota // A counter that sums its data points
	MetricTypeGauge                     // A gauge that displays the latest value
	MetricTypeTrend                     // A trend, min/max/avg/med are interesting
	MetricTypeRate                      // A rate, displays % of values that aren't 0
)

Possible values for MetricType.

func MetricTypeString

func MetricTypeString(s string) (MetricType, error)

MetricTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func MetricTypeValues

func MetricTypeValues() []MetricType

MetricTypeValues returns all values of the enum

func (MetricType) Aggregates

func (md MetricType) Aggregates() []string

Aggregates returns aggregate names for a given metric type.

func (MetricType) IsAMetricType

func (i MetricType) IsAMetricType() bool

IsAMetricType returns "true" if the value is listed in the enum definition. "false" otherwise

func (MetricType) MarshalJSON

func (i MetricType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for MetricType

func (MetricType) MarshalText

func (i MetricType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for MetricType

func (MetricType) String

func (i MetricType) String() string

func (*MetricType) UnmarshalJSON

func (i *MetricType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for MetricType

func (*MetricType) UnmarshalText

func (i *MetricType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for MetricType

type Metrics

type Metrics map[string]*Metric

Metrics contains metric by name.

func (Metrics) Find

func (mets Metrics) Find(name string) (*Metric, bool)

Find finds metric (or parent metric in case of submetric) by name.

type ParamData

type ParamData struct {
	Thresholds map[string][]string `json:"thresholds,omitempty"`
	Scenarios  []string            `json:"scenarios,omitempty"`
	EndOffset  int64               `json:"endOffset,omitempty"`
	Period     int64               `json:"period,omitempty"`
	Tags       []string            `json:"tags,omitempty"`
}

ParamData holds "param" event data.

type Peaks

type Peaks map[string]float64

Peaks contains peak rate values by metric name.

type State

type State int

State defines the SSE stream/connection states.

const (
	StateWaiting   State = iota // StateWaiting means waiting for data.
	StateConnected              // StateConnected means SSE stream connected.
	StatePreparing              // StatePreparing means parems event received but test not stasrted yet.
	StateStarting               // StateStarting means test started but no data available yet.
	StateDetached               // StateDetached means SSE stream disconnected.
	StateRunning                // StateRunning means test is running.
	StateFinished               // StateFinished means test execution is finished.
)

func StateString

func StateString(s string) (State, error)

StateString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func StateValues

func StateValues() []State

StateValues returns all values of the enum

func (State) IsAState

func (i State) IsAState() bool

IsAState returns "true" if the value is listed in the enum definition. "false" otherwise

func (State) MarshalJSON

func (i State) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for State

func (State) MarshalText

func (i State) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for State

func (State) String

func (i State) String() string

func (*State) UnmarshalJSON

func (i *State) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for State

func (*State) UnmarshalText

func (i *State) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for State

type Thresholds

type Thresholds struct {
	Result   Level
	Details  map[string]map[string]Level
	Brief    map[string]Level
	Source   map[string][]string
	Failures []*Failure
}

Thresholds holds all the result of the thresholds checks.

type ValueType

type ValueType int

ValueType holds the type of values a metric contains.

const (
	ValueTypeDefault ValueType = iota // Values are presented as-is
	ValueTypeTime                     // Values are time durations (milliseconds)
	ValueTypeData                     // Values are data amounts (bytes)
)

Possible values for ValueType.

func ValueTypeString

func ValueTypeString(s string) (ValueType, error)

ValueTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ValueTypeValues

func ValueTypeValues() []ValueType

ValueTypeValues returns all values of the enum

func (ValueType) Format

func (vt ValueType) Format(value float64) string

Format formats value for a given value type.

func (ValueType) IsAValueType

func (i ValueType) IsAValueType() bool

IsAValueType returns "true" if the value is listed in the enum definition. "false" otherwise

func (ValueType) MarshalJSON

func (i ValueType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ValueType

func (ValueType) MarshalText

func (i ValueType) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for ValueType

func (ValueType) String

func (i ValueType) String() string

func (*ValueType) UnmarshalJSON

func (i *ValueType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ValueType

func (*ValueType) UnmarshalText

func (i *ValueType) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for ValueType

Jump to

Keyboard shortcuts

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