chore(query-service): update GoValuateFuncs definitions (#5106)

* fix: parse both unix int and RFC3339 string in toUnixTimestamp
* chore: return GoValuateFuncs as float64
* chore: remove toUnixTimestamp function

---------

Signed-off-by: Prashant Shahi <prashant@signoz.io>
This commit is contained in:
Prashant Shahi 2024-05-31 21:22:03 +05:30 committed by GitHub
parent 67779d6c2c
commit 0f9c8d91ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -266,20 +266,9 @@ func EvalFuncs() map[string]govaluate.ExpressionFunction {
GoValuateFuncs["radians"] = func(args ...interface{}) (interface{}, error) {
return args[0].(float64) * math.Pi / 180, nil
}
// Returns the current Unix timestamp in seconds.
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 float64(time.Now().Unix()), nil
}
return GoValuateFuncs