mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Merge "Add scalar() function."
This commit is contained in:
commit
c7daedc840
|
@ -16,6 +16,7 @@ package ast
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -255,6 +256,15 @@ func sampleVectorImpl(timestamp time.Time, view *viewAdapter, args []Node) inter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === scalar(node *VectorNode) Scalar ===
|
||||||
|
func scalarImpl(timestamp time.Time, view *viewAdapter, args []Node) interface{} {
|
||||||
|
v := args[0].(VectorNode).Eval(timestamp, view)
|
||||||
|
if len(v) != 1 {
|
||||||
|
return clientmodel.SampleValue(math.NaN())
|
||||||
|
}
|
||||||
|
return clientmodel.SampleValue(v[0].Value)
|
||||||
|
}
|
||||||
|
|
||||||
var functions = map[string]*Function{
|
var functions = map[string]*Function{
|
||||||
"delta": {
|
"delta": {
|
||||||
name: "delta",
|
name: "delta",
|
||||||
|
@ -274,6 +284,12 @@ var functions = map[string]*Function{
|
||||||
returnType: VECTOR,
|
returnType: VECTOR,
|
||||||
callFn: sampleVectorImpl,
|
callFn: sampleVectorImpl,
|
||||||
},
|
},
|
||||||
|
"scalar": {
|
||||||
|
name: "scalar",
|
||||||
|
argTypes: []ExprType{VECTOR},
|
||||||
|
returnType: SCALAR,
|
||||||
|
callFn: scalarImpl,
|
||||||
|
},
|
||||||
"sort": {
|
"sort": {
|
||||||
name: "sort",
|
name: "sort",
|
||||||
argTypes: []ExprType{VECTOR},
|
argTypes: []ExprType{VECTOR},
|
||||||
|
|
Loading…
Reference in a new issue