parent
7f32a5d0d6
commit
02e032884a
|
@ -192,7 +192,7 @@ bucket. Otherwise, the upper bound of the lowest bucket is returned
|
||||||
for quantiles located in the lowest bucket.
|
for quantiles located in the lowest bucket.
|
||||||
|
|
||||||
If `b` has 0 observations, `NaN` is returned. If `b` contains fewer than two buckets,
|
If `b` has 0 observations, `NaN` is returned. If `b` contains fewer than two buckets,
|
||||||
`NaN` is returned. For φ < 0, `-Inf` is returned. For φ > 1, `+Inf` is returned.
|
`NaN` is returned. For φ < 0, `-Inf` is returned. For φ > 1, `+Inf` is returned. For φ = `NaN`, `NaN` is returned.
|
||||||
|
|
||||||
## `holt_winters()`
|
## `holt_winters()`
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ vector. `by` and `without` are only used to bucket the input vector.
|
||||||
`quantile` calculates the φ-quantile, the value that ranks at number φ*N among
|
`quantile` calculates the φ-quantile, the value that ranks at number φ*N among
|
||||||
the N metric values of the dimensions aggregated over. φ is provided as the
|
the N metric values of the dimensions aggregated over. φ is provided as the
|
||||||
aggregation parameter. For example, `quantile(0.5, ...)` calculates the median,
|
aggregation parameter. For example, `quantile(0.5, ...)` calculates the median,
|
||||||
`quantile(0.95, ...)` the 95th percentile.
|
`quantile(0.95, ...)` the 95th percentile. For φ = `NaN`, `NaN` is returned.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|
|
@ -34,18 +34,3 @@ func TestEvaluations(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOne(t *testing.T) {
|
|
||||||
files, err := filepath.Glob("testdata/nan.test")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
for _, fn := range files {
|
|
||||||
t.Run(fn, func(t *testing.T) {
|
|
||||||
test, err := newTestFromFile(t, fn)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NoError(t, test.Run())
|
|
||||||
|
|
||||||
test.Close()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -67,11 +67,13 @@ type metricWithBuckets struct {
|
||||||
//
|
//
|
||||||
// If the highest bucket is not +Inf, NaN is returned.
|
// If the highest bucket is not +Inf, NaN is returned.
|
||||||
//
|
//
|
||||||
|
// If q==NaN, NaN is returned.
|
||||||
|
//
|
||||||
// If q<0, -Inf is returned.
|
// If q<0, -Inf is returned.
|
||||||
//
|
//
|
||||||
// If q>1, +Inf is returned.
|
// If q>1, +Inf is returned.
|
||||||
func bucketQuantile(q float64, buckets buckets) float64 {
|
func bucketQuantile(q float64, buckets buckets) float64 {
|
||||||
if math.IsNaN(q){
|
if math.IsNaN(q) {
|
||||||
return math.NaN()
|
return math.NaN()
|
||||||
}
|
}
|
||||||
if q < 0 {
|
if q < 0 {
|
||||||
|
@ -184,11 +186,12 @@ func ensureMonotonic(buckets buckets) {
|
||||||
// quantile calculates the given quantile of a vector of samples.
|
// quantile calculates the given quantile of a vector of samples.
|
||||||
//
|
//
|
||||||
// The Vector will be sorted.
|
// The Vector will be sorted.
|
||||||
// If 'values' has zero elements or 'q' == NaN, NaN is returned.
|
// If 'values' has zero elements
|
||||||
|
// If q==NaN, NaN is returned.
|
||||||
// If q<0, -Inf is returned.
|
// If q<0, -Inf is returned.
|
||||||
// If q>1, +Inf is returned.
|
// If q>1, +Inf is returned.
|
||||||
func quantile(q float64, values vectorByValueHeap) float64 {
|
func quantile(q float64, values vectorByValueHeap) float64 {
|
||||||
if len(values) == 0 || q == math.NaN() {
|
if len(values) == 0 || math.IsNaN(q) {
|
||||||
return math.NaN()
|
return math.NaN()
|
||||||
}
|
}
|
||||||
if q < 0 {
|
if q < 0 {
|
||||||
|
|
|
@ -60,6 +60,11 @@ eval instant at 50m histogram_quantile(1.01, testhistogram_bucket)
|
||||||
{start="positive"} +Inf
|
{start="positive"} +Inf
|
||||||
{start="negative"} +Inf
|
{start="negative"} +Inf
|
||||||
|
|
||||||
|
# Quantile invalid.
|
||||||
|
eval instant at 50m histogram_quantile(NaN, testhistogram_bucket)
|
||||||
|
{start="positive"} NaN
|
||||||
|
{start="negative"} NaN
|
||||||
|
|
||||||
# Quantile value in lowest bucket, which is positive.
|
# Quantile value in lowest bucket, which is positive.
|
||||||
eval instant at 50m histogram_quantile(0, testhistogram_bucket{start="positive"})
|
eval instant at 50m histogram_quantile(0, testhistogram_bucket{start="positive"})
|
||||||
{start="positive"} 0
|
{start="positive"} 0
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
# Two histograms with 4 buckets each (x_sum and x_count not included,
|
|
||||||
# only buckets). Lowest bucket for one histogram < 0, for the other >
|
|
||||||
# 0. They have the same name, just separated by label. Not useful in
|
|
||||||
# practice, but can happen (if clients change bucketing), and the
|
|
||||||
# server has to cope with it.
|
|
||||||
|
|
||||||
# Test histogram.
|
|
||||||
load 5m
|
|
||||||
testhistogram_bucket{le="0.1", start="positive"} 0+5x10
|
|
||||||
testhistogram_bucket{le=".2", start="positive"} 0+7x10
|
|
||||||
testhistogram_bucket{le="1e0", start="positive"} 0+11x10
|
|
||||||
testhistogram_bucket{le="+Inf", start="positive"} 0+12x10
|
|
||||||
testhistogram_bucket{le="-.2", start="negative"} 0+1x10
|
|
||||||
testhistogram_bucket{le="-0.1", start="negative"} 0+2x10
|
|
||||||
testhistogram_bucket{le="0.3", start="negative"} 0+2x10
|
|
||||||
testhistogram_bucket{le="+Inf", start="negative"} 0+3x10
|
|
||||||
|
|
||||||
|
|
||||||
# Quantile value in lowest bucket, which is positive.
|
|
||||||
eval instant at 50m histogram_quantile(NaN, testhistogram_bucket{start="positive"})
|
|
||||||
{start="positive"} 0
|
|
Loading…
Reference in New Issue