mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 15:44:05 -08:00
commit
f35e5b54cc
|
@ -500,6 +500,17 @@ func log10Impl(timestamp clientmodel.Timestamp, args []Node) interface{} {
|
|||
return vector
|
||||
}
|
||||
|
||||
// === sqrt(vector VectorNode) Vector ===
|
||||
func sqrtImpl(timestamp clientmodel.Timestamp, args []Node) interface{} {
|
||||
n := args[0].(VectorNode)
|
||||
vector := n.Eval(timestamp)
|
||||
for _, el := range vector {
|
||||
el.Metric.Delete(clientmodel.MetricNameLabel)
|
||||
el.Value = clientmodel.SampleValue(math.Sqrt(float64(el.Value)))
|
||||
}
|
||||
return vector
|
||||
}
|
||||
|
||||
// === deriv(node MatrixNode) Vector ===
|
||||
func derivImpl(timestamp clientmodel.Timestamp, args []Node) interface{} {
|
||||
matrixNode := args[0].(MatrixNode)
|
||||
|
@ -721,6 +732,12 @@ var functions = map[string]*Function{
|
|||
returnType: VectorType,
|
||||
callFn: sortDescImpl,
|
||||
},
|
||||
"sqrt": {
|
||||
name: "sqrt",
|
||||
argTypes: []ExprType{VectorType},
|
||||
returnType: VectorType,
|
||||
callFn: sqrtImpl,
|
||||
},
|
||||
"sum_over_time": {
|
||||
name: "sum_over_time",
|
||||
argTypes: []ExprType{MatrixType},
|
||||
|
|
|
@ -1197,6 +1197,13 @@ func TestExpressions(t *testing.T) {
|
|||
`{group="canary", instance="0", job="api-server"} => NaN @[%v]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
expr: `sqrt(vector_matching_a)`,
|
||||
output: []string{
|
||||
`{l="x"} => 3.1622776601683795 @[%v]`,
|
||||
`{l="y"} => 4.47213595499958 @[%v]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
expr: `exp(vector_matching_a)`,
|
||||
output: []string{
|
||||
|
|
Loading…
Reference in a new issue