Problem with some functions in lambda expression
Hi,
I am using docker image kapacitor:1.5.3
I was trying to use some functions inside lambda expression and got results different than expected eg:
-
int(30s)- in your documentation it states that:
Converts a string or float64 into an int64 via Golang’s strconv.ParseInt or simple int64() coercion. Strings are assumed to be decimal numbers. Durations are converted into an int64 with nanoseconds units. A Boolean is converted to an int64 where false -> 0 and true -> 1.
but I'm getting error Cannot call function \"int\" with args (30s: duration), available signatures are [(int), (float), (boolean), (string)].
-
now() - 30s- results in errorinvalid math operator - for type time, should this operation be valid?
Is there any other way than using unixNano(now()) - unixNano("time") to do basic math operations on time types?
@asdfman777 thanks for opening this. It does look like our docs need to be updated. I don't think int supports durations after digging through the code (https://github.com/influxdata/kapacitor/blob/ea9612a26271bc9ed45e1dbe3d188e41337e05c1/tick/stateful/functions_test.go#L94). I'll send this to the docs team.
what is the expected output of int(30s)? 30 or 30000000000?
@russorat Hmm I don't know Go but isn't it handled here in the switch: https://github.com/influxdata/kapacitor/blob/ea9612a26271bc9ed45e1dbe3d188e41337e05c1/tick/stateful/functions.go#L855 but is missing here in the signature: https://github.com/influxdata/kapacitor/blob/ea9612a26271bc9ed45e1dbe3d188e41337e05c1/tick/stateful/functions.go#L883
For int(30s) I would expect to return 30000000000 so I can use it like:
unixNano(now()) - unixNano("time") < int(30s)
I have a similar use case where I wanted to do something like
unixNano(now()) - unixNano("time") > int(30s)
Is there a workaround for this , since this is not officially supported?
I think the only workaround for now would be to define a value for seconds = 1000000000 and use:
unixNano(now()) - unixNano("time") > (30 * seconds)