vector_core/
vrl.rs

1use lookup::{OwnedTargetPath, owned_value_path};
2use vrl::{
3    compiler::{CompilationResult, CompileConfig, Function, TypeState, compile_with_state},
4    diagnostic::DiagnosticList,
5};
6
7/// Compiles a VRL program
8/// Vector metadata is set to read-only to prevent it from being mutated
9///
10/// # Errors
11/// If the program fails to compile, a `DiagnosticList` of errors is returned
12pub fn compile_vrl(
13    source: &str,
14    fns: &[Box<dyn Function>],
15    state: &TypeState,
16    mut config: CompileConfig,
17) -> Result<CompilationResult, DiagnosticList> {
18    // Prevent mutating anything under the "vector" path in metadata.
19    //
20    // This path is used to differentiate between log namespaces. It also contains
21    // metadata that transforms / sinks may rely on, so setting it to read-only
22    // prevents users from potentially breaking behavior relying on it.
23    config.set_read_only_path(OwnedTargetPath::metadata(owned_value_path!("vector")), true);
24
25    compile_with_state(source, fns, state, config)
26}