Files
traces/pkg/traceql/engine_metrics_functions.go
a94f156c58 feat: Traceql metric sum_over_time (#4786)
* added sum_over_time to language

* rename evaluator

* refactor overtime functions

* added documentation

* fix compensation

* fix test due to floating point discrepancy

* changelog

* fix expr.y

* linting

* Update docs/sources/tempo/traceql/metrics-queries/_index.md

Co-authored-by: Ruslan Mikhailov <[email protected]>

* Update docs/sources/tempo/traceql/metrics-queries/functions.md

Co-authored-by: Martin Disibio <[email protected]>

* add function

---------

Co-authored-by: Ruslan Mikhailov <[email protected]>
Co-authored-by: Martin Disibio <[email protected]>
2025-03-05 10:01:54 +01:00

35 lines
743 B
Go

package traceql
import "math"
func sumOverTime() func(curr float64, n float64) (res float64) {
var comp float64 // Kahan compensation
return func(sum, inc float64) (res float64) {
if math.IsNaN(sum) {
return inc
}
y := inc - comp
sum, c := kahanSumInc(y, sum, 0) // Compensation is applied on every step, hence we pass 0 to reset it
comp = c
return sum
}
}
func minOverTime() func(curr float64, n float64) (res float64) {
return func(curr, n float64) (res float64) {
if math.IsNaN(curr) || n < curr {
return n
}
return curr
}
}
func maxOverTime() func(curr float64, n float64) (res float64) {
return func(curr, n float64) (res float64) {
if math.IsNaN(curr) || n > curr {
return n
}
return curr
}
}