Signed-off-by: jyz0309 <45495947@qq.com>
This commit is contained in:
jyz0309 2022-02-13 21:59:03 +08:00
parent 7f32a5d0d6
commit 02e032884a
6 changed files with 14 additions and 42 deletions

View File

@ -192,7 +192,7 @@ bucket. Otherwise, the upper bound of the lowest bucket is returned
for quantiles located in the lowest bucket.
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()`
@ -456,4 +456,4 @@ The following are useful for converting between degrees and radians:
- `deg(v instant-vector)`: converts radians to degrees for all elements in `v`.
- `pi()`: returns pi.
- `rad(v instant-vector)`: converts degrees to radians for all elements in `v`.
- `rad(v instant-vector)`: converts degrees to radians for all elements in `v`.

View File

@ -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
the N metric values of the dimensions aggregated over. φ is provided as the
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:

View File

@ -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()
})
}
}

View File

@ -67,11 +67,13 @@ type metricWithBuckets struct {
//
// If the highest bucket is not +Inf, NaN is returned.
//
// If q==NaN, NaN is returned.
//
// If q<0, -Inf is returned.
//
// If q>1, +Inf is returned.
func bucketQuantile(q float64, buckets buckets) float64 {
if math.IsNaN(q){
if math.IsNaN(q) {
return math.NaN()
}
if q < 0 {
@ -184,11 +186,12 @@ func ensureMonotonic(buckets buckets) {
// quantile calculates the given quantile of a vector of samples.
//
// 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>1, +Inf is returned.
func quantile(q float64, values vectorByValueHeap) float64 {
if len(values) == 0 || q == math.NaN() {
if len(values) == 0 || math.IsNaN(q) {
return math.NaN()
}
if q < 0 {

View File

@ -60,6 +60,11 @@ eval instant at 50m histogram_quantile(1.01, testhistogram_bucket)
{start="positive"} +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.
eval instant at 50m histogram_quantile(0, testhistogram_bucket{start="positive"})
{start="positive"} 0

View File

@ -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