Description
Component(s)
pkg/ottl
Is your feature request related to a problem? Please describe.
Currently, OTTL does not have a function that can convert stringified integers (e.g: "0x123", "010101", "1234") of different bases into int64.
Describe the solution you'd like
I would like to add a new OTTL function: ParseInt(s string, b int64)
. This function behaves like Go's strconv.ParseInt, with the exception that there is no bitSize
parameter, i.e: strconv.ParseInt(s, b, 64)
will essentially be called to perform the conversion.
The function's output is an int64
.
s
(string): Any stringified integer.
b
(int64): An int64
integer representing the base of the input string s
.
Examples:
ParseInt("1234", 10) -> 1234
ParseInt("1A", 16) -> 26
ParseInt("0X1A",0) -> 26
The implementation is drafted here: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/40786/files
Describe alternatives you've considered
An alternative could be expanding on the existing Int() ottl function, allowing it to take in an optional base
argument.
This logic in StandardIntLikeGetter.Get
, will have to be relocated to intFunc to access the base
value while doing the integer conversion.
Reason for rejection: The existing Int()
OTTL function covers converting double and boolean to int64. It seems rare that there are use cases requiring a floating point number in base 16 to be converted into an int64, and boolean values don't have a base. Therefore, I propose a new function that exclusively handles converting stringified integers of different bases into integers.
Additional context
No response