Elixir bindings for Vector Remap Language.
Compile a program once with compile/1, then run it against many events
with run/3. The full VRL standard library is available, except for
network functions.
iex> {:ok, program} = VRL.compile(".message = upcase!(.message)")
iex> VRL.run(program, %{"message" => "hello"})
{:ok, %VRL.Result{value: "HELLO", event: %{"message" => "HELLO"}}}Value conversion
| Elixir | VRL |
|---|---|
| binary | string |
| integer (64-bit) | integer |
| float | float |
true / false | boolean |
nil | null |
| map | object |
| list | array |
DateTime | timestamp |
| other atoms | string |
Map keys may be binaries or atoms; returned maps always have binary keys.
Timestamps are returned as UTC DateTimes with microsecond precision.
Other structs are passed as maps, keeping "__struct__" unless the
:strip_structs option is set.
Integer overflow
VRL integer arithmetic (+, -, *) wraps around on 64-bit overflow
without an error or warning. This is upstream VRL behaviour:
iex> {:ok, program} = VRL.compile("9223372036854775807 + 1")
iex> {:ok, %VRL.Result{value: value}} = VRL.run(program)
iex> value
-9223372036854775808
Summary
Functions
Compiles VRL source into a reusable VRL.Program.
Maximum nesting of maps and lists accepted by and returned from run/3.
Runs a compiled program against event.
Types
Functions
@spec compile(String.t()) :: {:ok, VRL.Program.t()} | {:error, String.t()}
Compiles VRL source into a reusable VRL.Program.
Returns {:error, diagnostics} with human-readable diagnostics when the
program is invalid.
@spec max_depth() :: pos_integer()
Maximum nesting of maps and lists accepted by and returned from run/3.
Deeper values return {:error, "maximum nesting depth of 128 exceeded"}.
@spec run(VRL.Program.t(), event(), keyword()) :: {:ok, VRL.Result.t()} | {:error, run_error() | :timeout}
Runs a compiled program against event.
Returns {:ok, %VRL.Result{}} with the program's resulting value and the
transformed event. Returns {:error, {:abort, message}} when the program
calls abort, and {:error, :timeout} when it exceeds the timeout.
Options
:timeout- maximum run time in milliseconds, or:infinity. Defaults to5000. Checked between VRL expressions, so a single long-running function call can overrun it.:strip_structs- whentrue, structs other thanDateTimeare passed as plain maps without the"__struct__"key. Defaults tofalse.