Package teststat provides helpers for testing metrics backends.
Internal call graph ▹
Internal call graph ▾
In the call graph viewer below, each node is a function belonging to this package and its children are the functions it calls—perhaps dynamically.
The root nodes are the entry points of the package: functions that may be called from outside the package. There may be non-exported or anonymous functions among them if they are called dynamically from another package.
Click a node to visit that function's source code.
From there you can visit its callers by
clicking its declaring
Functions may be omitted if they were determined to be unreachable in the particular programs or tests that were analyzed.
var ( // Count is the number of observations. Count = 12345 // Mean is the center of the normal distribution of observations. Mean = 500 // Stdev of the normal distribution of observations. Stdev = 25 )
func ExpectedObservationsLessThan(bucket int64) int64
ExpectedObservationsLessThan returns the number of observations that should have a value less than or equal to the given value, given a normal distribution of observations described by Count, Mean, and Stdev.
func LastLine(w io.WriterTo, regex string) func() float64
LastLine expects a regex whose first capture group can be parsed as a float64. It will dump the WriterTo and parse each line, expecting to find a match. It returns the final captured float.
func PopulateNormalHistogram ¶
func PopulateNormalHistogram(h metrics.Histogram, seed int)
PopulateNormalHistogram makes a series of normal random observations into the histogram. The number of observations is determined by Count. The randomness is determined by Mean, Stdev, and the seed parameter.
This is a low-level function, exported only for metrics that don't perform dynamic quantile computation, like a Prometheus Histogram (c.f. Summary). In most cases, you don't need to use this function, and can use TestHistogram instead.
func Quantiles(w io.WriterTo, regex string, buckets int) func() (float64, float64, float64, float64)
Quantiles expects a regex whose first capture group can be parsed as a float64. It will dump the WriterTo and parse each line, expecting to find a match. It observes all captured floats into a generic.Histogram with the given number of buckets, and returns the 50th, 90th, 95th, and 99th quantiles from that histogram.
func SumLines(w io.WriterTo, regex string) func() float64
SumLines expects a regex whose first capture group can be parsed as a float64. It will dump the WriterTo and parse each line, expecting to find a match. It returns the sum of all captured floats.
func TestCounter ¶
func TestCounter(counter metrics.Counter, value func() float64) error
TestCounter puts some deltas through the counter, and then calls the value func to check that the counter has the correct final value.
func TestGauge(gauge metrics.Gauge, value func() float64) error
TestGauge puts some values through the gauge, and then calls the value func to check that the gauge has the correct final value.
func TestHistogram ¶
func TestHistogram(histogram metrics.Histogram, quantiles func() (p50, p90, p95, p99 float64), tolerance float64) error
TestHistogram puts some observations through the histogram, and then calls the quantiles func to checks that the histogram has computed the correct quantiles within some tolerance