vector_config/external/
vrl.rs1use std::cell::RefCell;
2
3use serde_json::Value;
4use vrl::{compiler::VrlRuntime, datadog_search_syntax::QueryNode, value::Value as VrlValue};
5
6use crate::{
7 schema::{generate_string_schema, SchemaGenerator, SchemaObject},
8 Configurable, GenerateError, Metadata, ToValue,
9};
10
11impl Configurable for VrlRuntime {
12 fn metadata() -> Metadata {
13 let mut metadata = Metadata::default();
14 metadata.set_description("The runtime to use for executing VRL code.");
15 metadata
16 }
17
18 fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {
19 Ok(generate_string_schema())
20 }
21}
22
23impl ToValue for VrlRuntime {
24 fn to_value(&self) -> Value {
25 Value::String(match self {
26 VrlRuntime::Ast => "ast".to_owned(),
27 })
28 }
29}
30
31impl Configurable for QueryNode {
32 fn generate_schema(_gen: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError>
33 where
34 Self: Sized,
35 {
36 Ok(generate_string_schema())
37 }
38}
39
40impl Configurable for VrlValue {
41 fn is_optional() -> bool {
42 true
43 }
44
45 fn metadata() -> Metadata {
46 Metadata::with_transparent(true)
47 }
48
49 fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {
50 Ok(SchemaObject::default())
52 }
53}
54
55impl ToValue for VrlValue {
56 fn to_value(&self) -> Value {
66 serde_json::to_value(self).expect("Unable to serialize VRL value")
67 }
68}