mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 23:15:57 +08:00
chore: add toUnixTimestamp to supported functions (#4877)
This commit is contained in:
parent
51becf7cfb
commit
9f1c45bc32
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/SigNoz/govaluate"
|
"github.com/SigNoz/govaluate"
|
||||||
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
||||||
@ -158,7 +159,7 @@ func processResults(results []*v3.Result, expression *govaluate.EvaluableExpress
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var SupportedFunctions = []string{"exp", "log", "ln", "exp2", "log2", "exp10", "log10", "sqrt", "cbrt", "erf", "erfc", "lgamma", "tgamma", "sin", "cos", "tan", "asin", "acos", "atan", "degrees", "radians"}
|
var SupportedFunctions = []string{"exp", "log", "ln", "exp2", "log2", "exp10", "log10", "sqrt", "cbrt", "erf", "erfc", "lgamma", "tgamma", "sin", "cos", "tan", "asin", "acos", "atan", "degrees", "radians", "now", "toUnixTimestamp"}
|
||||||
|
|
||||||
func evalFuncs() map[string]govaluate.ExpressionFunction {
|
func evalFuncs() map[string]govaluate.ExpressionFunction {
|
||||||
GoValuateFuncs := make(map[string]govaluate.ExpressionFunction)
|
GoValuateFuncs := make(map[string]govaluate.ExpressionFunction)
|
||||||
@ -247,5 +248,21 @@ func evalFuncs() map[string]govaluate.ExpressionFunction {
|
|||||||
GoValuateFuncs["radians"] = func(args ...interface{}) (interface{}, error) {
|
GoValuateFuncs["radians"] = func(args ...interface{}) (interface{}, error) {
|
||||||
return args[0].(float64) * math.Pi / 180, nil
|
return args[0].(float64) * math.Pi / 180, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GoValuateFuncs["now"] = func(args ...interface{}) (interface{}, error) {
|
||||||
|
return time.Now().Unix(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
GoValuateFuncs["toUnixTimestamp"] = func(args ...interface{}) (interface{}, error) {
|
||||||
|
if len(args) != 1 {
|
||||||
|
return nil, fmt.Errorf("toUnixTimestamp requires exactly one argument")
|
||||||
|
}
|
||||||
|
t, err := time.Parse(time.RFC3339, args[0].(string))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return t.Unix(), nil
|
||||||
|
}
|
||||||
|
|
||||||
return GoValuateFuncs
|
return GoValuateFuncs
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user