Documentation ¶
Overview ¶
Package latency supports exporting latency stats (avg/max/min) of a set of time windows as metadata.
Index ¶
- Constants
- Variables
- 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, prefix []string) []string
- type Latency
- type Metadata
- 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 ¶
var Now = time.Now
Now is a stub for testing.
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.
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) UpdateLast ¶
UpdateLast is the same as UpdateReset except that it doesn't require a window to meet the initial window size requirement to update its stats. UpdateLast is expected to be called at most once at the end of the life of Latency to force updating the windows that haven't received latency stats long enough to generate even a single update. For a long lasting Latency, there is no need to call UpdateLast.
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 // ComputeFunc defines how to calculate latency for the timestamp provided // to Compute. If unspecified, the latency is calculated as now.Sub(ts). ComputeFunc func(ts, now time.Time) time.Duration }
Options contains the options for creating a Latency.