@ -650,6 +650,30 @@ func funcLabelReplace(ev *evaluator, args Expressions) model.Value {
return vector
return vector
}
}
// === vector(s scalar, vector model.ValVectora={}) Vector ===
func funcVector ( ev * evaluator , args Expressions ) model . Value {
m := model . Metric { }
if len ( args ) >= 2 {
if vs , ok := args [ 1 ] . ( * VectorSelector ) ; ok {
for _ , matcher := range vs . LabelMatchers {
if matcher . Type == metric . Equal && matcher . Name != model . MetricNameLabel {
m [ matcher . Name ] = matcher . Value
}
}
}
}
return vector {
& sample {
Metric : metric . Metric {
Metric : m ,
Copied : true ,
} ,
Value : model . SampleValue ( ev . evalFloat ( args [ 0 ] ) ) ,
Timestamp : ev . Timestamp ,
} ,
}
}
var functions = map [ string ] * Function {
var functions = map [ string ] * Function {
"abs" : {
"abs" : {
Name : "abs" ,
Name : "abs" ,
@ -845,6 +869,13 @@ var functions = map[string]*Function{
ReturnType : model . ValVector ,
ReturnType : model . ValVector ,
Call : funcTopk ,
Call : funcTopk ,
} ,
} ,
"vector" : {
Name : "vector" ,
ArgTypes : [ ] model . ValueType { model . ValScalar , model . ValVector } ,
ReturnType : model . ValVector ,
OptionalArgs : 1 ,
Call : funcVector ,
} ,
}
}
// getFunction returns a predefined Function object for the given name.
// getFunction returns a predefined Function object for the given name.