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