datadog_api_client/datadogV2/model/
model_observability_pipeline_custom_processor.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// The `custom_processor` processor transforms events using [Vector Remap Language (VRL)](<https://vector.dev/docs/reference/vrl/>) scripts with advanced filtering capabilities.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ObservabilityPipelineCustomProcessor {
14    /// The unique identifier for this processor.
15    #[serde(rename = "id")]
16    pub id: String,
17    /// A Datadog search query used to determine which logs this processor targets. This field should always be set to `*` for the custom_processor processor.
18    #[serde(rename = "include")]
19    pub include: String,
20    /// A list of component IDs whose output is used as the input for this processor.
21    #[serde(rename = "inputs")]
22    pub inputs: Vec<String>,
23    /// Array of VRL remap rules.
24    #[serde(rename = "remaps")]
25    pub remaps: Vec<crate::datadogV2::model::ObservabilityPipelineCustomProcessorRemap>,
26    /// The processor type. The value should always be `custom_processor`.
27    #[serde(rename = "type")]
28    pub type_: crate::datadogV2::model::ObservabilityPipelineCustomProcessorType,
29    #[serde(flatten)]
30    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
31    #[serde(skip)]
32    #[serde(default)]
33    pub(crate) _unparsed: bool,
34}
35
36impl ObservabilityPipelineCustomProcessor {
37    pub fn new(
38        id: String,
39        include: String,
40        inputs: Vec<String>,
41        remaps: Vec<crate::datadogV2::model::ObservabilityPipelineCustomProcessorRemap>,
42        type_: crate::datadogV2::model::ObservabilityPipelineCustomProcessorType,
43    ) -> ObservabilityPipelineCustomProcessor {
44        ObservabilityPipelineCustomProcessor {
45            id,
46            include,
47            inputs,
48            remaps,
49            type_,
50            additional_properties: std::collections::BTreeMap::new(),
51            _unparsed: false,
52        }
53    }
54
55    pub fn additional_properties(
56        mut self,
57        value: std::collections::BTreeMap<String, serde_json::Value>,
58    ) -> Self {
59        self.additional_properties = value;
60        self
61    }
62}
63
64impl<'de> Deserialize<'de> for ObservabilityPipelineCustomProcessor {
65    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
66    where
67        D: Deserializer<'de>,
68    {
69        struct ObservabilityPipelineCustomProcessorVisitor;
70        impl<'a> Visitor<'a> for ObservabilityPipelineCustomProcessorVisitor {
71            type Value = ObservabilityPipelineCustomProcessor;
72
73            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
74                f.write_str("a mapping")
75            }
76
77            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
78            where
79                M: MapAccess<'a>,
80            {
81                let mut id: Option<String> = None;
82                let mut include: Option<String> = None;
83                let mut inputs: Option<Vec<String>> = None;
84                let mut remaps: Option<
85                    Vec<crate::datadogV2::model::ObservabilityPipelineCustomProcessorRemap>,
86                > = None;
87                let mut type_: Option<
88                    crate::datadogV2::model::ObservabilityPipelineCustomProcessorType,
89                > = None;
90                let mut additional_properties: std::collections::BTreeMap<
91                    String,
92                    serde_json::Value,
93                > = std::collections::BTreeMap::new();
94                let mut _unparsed = false;
95
96                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
97                    match k.as_str() {
98                        "id" => {
99                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
100                        }
101                        "include" => {
102                            include = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
103                        }
104                        "inputs" => {
105                            inputs = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
106                        }
107                        "remaps" => {
108                            remaps = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
109                        }
110                        "type" => {
111                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
112                            if let Some(ref _type_) = type_ {
113                                match _type_ {
114                                    crate::datadogV2::model::ObservabilityPipelineCustomProcessorType::UnparsedObject(_type_) => {
115                                        _unparsed = true;
116                                    },
117                                    _ => {}
118                                }
119                            }
120                        }
121                        &_ => {
122                            if let Ok(value) = serde_json::from_value(v.clone()) {
123                                additional_properties.insert(k, value);
124                            }
125                        }
126                    }
127                }
128                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
129                let include = include.ok_or_else(|| M::Error::missing_field("include"))?;
130                let inputs = inputs.ok_or_else(|| M::Error::missing_field("inputs"))?;
131                let remaps = remaps.ok_or_else(|| M::Error::missing_field("remaps"))?;
132                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
133
134                let content = ObservabilityPipelineCustomProcessor {
135                    id,
136                    include,
137                    inputs,
138                    remaps,
139                    type_,
140                    additional_properties,
141                    _unparsed,
142                };
143
144                Ok(content)
145            }
146        }
147
148        deserializer.deserialize_any(ObservabilityPipelineCustomProcessorVisitor)
149    }
150}