mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* 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]>
35 lines
743 B
Go
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
|
|
}
|
|
}
|