diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a51a35e12..d445028465 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ * FEATURE: vmagent: add `/ready` HTTP endpoint, which returns 200 OK status code when all the service discovery has been initialized. This may be useful during rolling upgrades. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/875 +* BUGFIX: properly calculate `topk_*` and `bottomk_*` functions from [MetricsQL](https://victoriametrics.github.io/MetricsQL.html) for time series with gaps. + See https://github.com/VictoriaMetrics/VictoriaMetrics/pull/883 + # [v1.45.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.45.0) diff --git a/app/vmselect/promql/aggr.go b/app/vmselect/promql/aggr.go index f30313df7d..5d6a71bf98 100644 --- a/app/vmselect/promql/aggr.go +++ b/app/vmselect/promql/aggr.go @@ -737,46 +737,30 @@ func getIntK(k float64, kMax int) int { } func minValue(values []float64) float64 { - if len(values) == 0 { - return nan + min := nan + for len(values) > 0 && math.IsNaN(min) { + min = values[0] + values = values[1:] } - aNumberFounded := false - var min float64 for _, v := range values { - if !math.IsNaN(v) && !aNumberFounded { - min = v - aNumberFounded = true - continue - } if !math.IsNaN(v) && v < min { min = v } } - if !aNumberFounded { - return nan - } return min } func maxValue(values []float64) float64 { - if len(values) == 0 { - return nan + max := nan + for len(values) > 0 && math.IsNaN(max) { + max = values[0] + values = values[1:] } - aNumberFounded := false - var max float64 for _, v := range values { - if !math.IsNaN(v) && !aNumberFounded { - max = v - aNumberFounded = true - continue - } if !math.IsNaN(v) && v > max { max = v } } - if !aNumberFounded { - return nan - } return max } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7a51a35e12..d445028465 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,9 @@ * FEATURE: vmagent: add `/ready` HTTP endpoint, which returns 200 OK status code when all the service discovery has been initialized. This may be useful during rolling upgrades. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/875 +* BUGFIX: properly calculate `topk_*` and `bottomk_*` functions from [MetricsQL](https://victoriametrics.github.io/MetricsQL.html) for time series with gaps. + See https://github.com/VictoriaMetrics/VictoriaMetrics/pull/883 + # [v1.45.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.45.0)