vector_config/external/
vrl.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::cell::RefCell;

use serde_json::Value;
use vrl::{compiler::VrlRuntime, datadog_search_syntax::QueryNode, value::Value as VrlValue};

use crate::{
    schema::{generate_string_schema, SchemaGenerator, SchemaObject},
    Configurable, GenerateError, Metadata, ToValue,
};

impl Configurable for VrlRuntime {
    fn metadata() -> Metadata {
        let mut metadata = Metadata::default();
        metadata.set_description("The runtime to use for executing VRL code.");
        metadata
    }

    fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {
        Ok(generate_string_schema())
    }
}

impl ToValue for VrlRuntime {
    fn to_value(&self) -> Value {
        Value::String(match self {
            VrlRuntime::Ast => "ast".to_owned(),
        })
    }
}

impl Configurable for QueryNode {
    fn generate_schema(_gen: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError>
    where
        Self: Sized,
    {
        Ok(generate_string_schema())
    }
}

impl Configurable for VrlValue {
    fn is_optional() -> bool {
        true
    }

    fn metadata() -> Metadata {
        Metadata::with_transparent(true)
    }

    fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {
        // We don't have any constraints on the inputs
        Ok(SchemaObject::default())
    }
}

impl ToValue for VrlValue {
    /// Converts a `VrlValue` into a `serde_json::Value`.
    ///
    /// This conversion should always succeed, though it may result in a loss
    /// of type information for some value types.
    ///
    /// # Panics
    ///
    /// This function will panic if serialization fails, which is not expected
    /// under normal circumstances.
    fn to_value(&self) -> Value {
        serde_json::to_value(self).expect("Unable to serialize VRL value")
    }
}