kapacitor icon indicating copy to clipboard operation
kapacitor copied to clipboard

Problem with some functions in lambda expression

Open asdfman777 opened this issue 6 years ago • 4 comments

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 error invalid 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 avatar Feb 14 '20 13:02 asdfman777

@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 avatar Feb 20 '20 23:02 russorat

@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)

asdfman777 avatar Feb 21 '20 14:02 asdfman777

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?

prashanthjbabu avatar Mar 11 '20 05:03 prashanthjbabu

I think the only workaround for now would be to define a value for seconds = 1000000000 and use:

unixNano(now()) - unixNano("time") > (30 * seconds)

russorat avatar Mar 11 '20 16:03 russorat