mirror of https://github.com/prometheus/prometheus
Add square root function
parent
54f5c524e5
commit
74aed55e55
|
@ -500,6 +500,17 @@ func log10Impl(timestamp clientmodel.Timestamp, args []Node) interface{} {
|
||||||
return vector
|
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 ===
|
// === deriv(node MatrixNode) Vector ===
|
||||||
func derivImpl(timestamp clientmodel.Timestamp, args []Node) interface{} {
|
func derivImpl(timestamp clientmodel.Timestamp, args []Node) interface{} {
|
||||||
matrixNode := args[0].(MatrixNode)
|
matrixNode := args[0].(MatrixNode)
|
||||||
|
@ -721,6 +732,12 @@ var functions = map[string]*Function{
|
||||||
returnType: VectorType,
|
returnType: VectorType,
|
||||||
callFn: sortDescImpl,
|
callFn: sortDescImpl,
|
||||||
},
|
},
|
||||||
|
"sqrt": {
|
||||||
|
name: "sqrt",
|
||||||
|
argTypes: []ExprType{VectorType},
|
||||||
|
returnType: VectorType,
|
||||||
|
callFn: sqrtImpl,
|
||||||
|
},
|
||||||
"sum_over_time": {
|
"sum_over_time": {
|
||||||
name: "sum_over_time",
|
name: "sum_over_time",
|
||||||
argTypes: []ExprType{MatrixType},
|
argTypes: []ExprType{MatrixType},
|
||||||
|
|
|
@ -1197,6 +1197,13 @@ func TestExpressions(t *testing.T) {
|
||||||
`{group="canary", instance="0", job="api-server"} => NaN @[%v]`,
|
`{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)`,
|
expr: `exp(vector_matching_a)`,
|
||||||
output: []string{
|
output: []string{
|
||||||
|
|
Loading…
Reference in New Issue