Documentation ¶
Overview ¶
Package latency supports exporting latency stats (avg/max/min) of a set of time windows as metadata.
Index ¶
- Constants
- func CompactDurationString(d time.Duration) string
- func MetadataName(w time.Duration, typ StatType) string
- func ParseWindows(tds []string, metaUpdatePeriod time.Duration) ([]time.Duration, error)
- func Path(w time.Duration, typ StatType) []string
- func RegisterMetadata(windowSizes []time.Duration)
- type Latency
- type Options
- type StatType
Constants ¶
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" )
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 ¶
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 ¶
MetadataName returns the metadata name for the latency statistics of window w and type typ.
func ParseWindows ¶
ParseWindows parses the time durations of latency windows and verify they are multiples of the metadata update period.
func RegisterMetadata ¶
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 ¶
New returns a Latency object supporting latency stats for time windows specified in windowSizes.
func (*Latency) Compute ¶
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 ¶
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.