latency

package
v0.0.0-...-33825f2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package latency supports exporting latency stats (avg/max/min) of a set of time windows as metadata.

Index

Constants

View Source
const (
	// ElemLatency is the container of all latency metadata about a target.
	ElemLatency = "latency"
	// ElemWindow contains latency metadatas (avg, max, min) of a particular
	// window size.
	ElemWindow = "window"
	// ElemAvg is the average latency during a time window.
	ElemAvg = "avg"
	// ElemMax is the maximum latency during a time window.
	ElemMax = "max"
	// ElemMin is the minimum latency during a time window.
	ElemMin = "min"
)
View Source
const (
	// Avg is the average latency of a time window.
	Avg = StatType(iota)
	// Max is the maximum latency of a time window.
	Max
	// Min is the minimum latency of a time window.
	Min
)

Variables

This section is empty.

Functions

func CompactDurationString

func CompactDurationString(d time.Duration) string

CompactDurationString returns a compact string for a time window d. It removes unnecessary suffixes like "0m0s" and "0s" from the Golang fmt.Sprint generated string of a time.Duration.

func MetadataName

func MetadataName(w time.Duration, typ StatType) string

MetadataName returns the metadata name for the latency statistics of window w and type typ.

func ParseWindows

func ParseWindows(tds []string, metaUpdatePeriod time.Duration) ([]time.Duration, error)

ParseWindows parses the time durations of latency windows and verify they are multiples of the metadata update period.

func Path

func Path(w time.Duration, typ StatType) []string

Path returns the metadata path for the latency statistics of window w and type typ.

func RegisterMetadata

func RegisterMetadata(windowSizes []time.Duration)

RegisterMetadata registers latency stats metadata for time windows specified in windowSizes. RegisterMetadata is not thread-safe and should be called before any metadata.Metadata is instantiated.

Types

type Latency

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

Latency supports calculating and exporting latency stats for a specified set of time windows.

func New

func New(windowSizes []time.Duration, opts *Options) *Latency

New returns a Latency object supporting latency stats for time windows specified in windowSizes.

func (*Latency) Compute

func (l *Latency) Compute(ts time.Time)

Compute calculates the time difference between now and ts (the timestamp of an update) and updates the latency stats saved in Latency.

func (*Latency) UpdateReset

func (l *Latency) UpdateReset(m *metadata.Metadata)

UpdateReset use the latencies saved during the last interval to update the latency stats of all the supported time windows. And then it updates the corresponding stats in Metadata m. UpdateReset is expected to be called periodically at a fixed interval (e.g. 2s) of which the time windows should be multiples of this interval.

type Options

type Options struct {
	// Precision for the avg stats. If unspecified, the precision is nanoseconds.
	// The exported latency stats are always in nanoseconds no matter what
	// precision is set here. Setting precision at a more coarse time duration
	// than nanosecond is to avoid overflowing of int64 for the accumulated time
	// durations needed to calculate averages. The precision of the Max and Min
	// stats are not affected by this setting.
	AvgPrecision time.Duration
}

Options contains the options for creating a Latency.

type StatType

type StatType int

StatType is the type of latency statistics supported for a time window.

func (StatType) String

func (st StatType) String() string

String returns the string representation of the StatType.

Jump to

Keyboard shortcuts

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