Add return expression to the Vector Remap Language.
- #7496
- None.
- Adding a return expression to VRL.
- The
return
can optionally take an expression as an argument and the result of that expression will be returned.
- Adding new keywords for similar purposes such as
drop
. - Defining semantics of keywords that are usually used for other purposes in other languages such as
break
. - Implementation of
return
expressions inside closures.
- Aborting with changing the input cannot be easily done.
- VRL code is often unnecessarily indented because of lack of early returns.
- A
return
expression causes the VRL program to terminate, keeping any modifications made to the event. - A
return
expression must be always followed by another expression, whose value will be used as the emitted event. - The keyword cannot be used inside a closure. Trying to do that will result in a compilation error.
- Implementation will be similar to the current
abort
keyword whendrop_on_abort
is set tofalse
. The only difference is that the returned value will be taken from the provided expression and not from original input. drop_on_abort
will have no effect on return calls and configuration such asdrop_on_return
will not be added.
- It will be possible to write VRL with less indentation making it more readable.
return
is already a reserved word so it can be used without introducing a breaking change.
- The
return
keyword will be given a semantic meaning that will have to be supported going forward.
- Most languages have a way to make early returns.
- There was no prior attempted implementation of returns in VRL to my knowledge.
- New keywords that are not currently a reserved keyword can be added to the language. This would, however, constitute a breaking change.
- This feature can also be rejected as it does not add any functionality that cannot be currently expressed.
Incremental steps to execute this change. These will be converted to issues after the RFC is approved:
- Submit a PR with implementation of returns.
- Adding a
drop
keyword for explicit drop as an alternative to pre-configuredabort
for full control over passing the events to output unchanged, passing them changed, or routing them to the dropped output. - Adding
return
to closures.