mirror of
https://github.com/prometheus/prometheus
synced 2025-01-13 10:22:46 +00:00
Merge pull request #10295 from jyz0309/add-NaN-case
PromQL: Define and document behavior of quantile and histogram_quantile with φ=NaN
This commit is contained in:
commit
0ce1546097
@ -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`.
|
||||
|
@ -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. For φ < 0, `-Inf` is returned. For φ > 1, `+Inf` is returned.
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -67,10 +67,15 @@ 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) {
|
||||
return math.NaN()
|
||||
}
|
||||
if q < 0 {
|
||||
return math.Inf(-1)
|
||||
}
|
||||
@ -182,10 +187,11 @@ func ensureMonotonic(buckets buckets) {
|
||||
//
|
||||
// The Vector will be sorted.
|
||||
// If 'values' has zero elements, NaN is returned.
|
||||
// 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 {
|
||||
if len(values) == 0 || math.IsNaN(q) {
|
||||
return math.NaN()
|
||||
}
|
||||
if q < 0 {
|
||||
|
5
promql/testdata/aggregators.test
vendored
5
promql/testdata/aggregators.test
vendored
@ -399,6 +399,11 @@ eval instant at 1m quantile without(point)((scalar(foo)), data)
|
||||
{test="three samples"} 1.6
|
||||
{test="uneven samples"} 2.8
|
||||
|
||||
eval instant at 1m quantile without(point)(NaN, data)
|
||||
{test="two samples"} NaN
|
||||
{test="three samples"} NaN
|
||||
{test="uneven samples"} NaN
|
||||
|
||||
# Tests for group.
|
||||
clear
|
||||
|
||||
|
5
promql/testdata/histograms.test
vendored
5
promql/testdata/histograms.test
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user