datadog_api_client/datadogV2/model/
model_observability_pipeline_quota_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 Quota Processor measures logging traffic for logs that match a specified filter. When the configured daily quota is met, the processor can drop or alert.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ObservabilityPipelineQuotaProcessor {
14    /// If set to `true`, logs that matched the quota filter and sent after the quota has been met are dropped; only logs that did not match the filter query continue through the pipeline.
15    #[serde(rename = "drop_events")]
16    pub drop_events: bool,
17    /// The unique identifier for this component. Used to reference this component in other parts of the pipeline (for example, as the `input` to downstream components).
18    #[serde(rename = "id")]
19    pub id: String,
20    /// If `true`, the processor skips quota checks when partition fields are missing from the logs.
21    #[serde(rename = "ignore_when_missing_partitions")]
22    pub ignore_when_missing_partitions: Option<bool>,
23    /// A Datadog search query used to determine which logs this processor targets.
24    #[serde(rename = "include")]
25    pub include: String,
26    /// A list of component IDs whose output is used as the `input` for this component.
27    #[serde(rename = "inputs")]
28    pub inputs: Vec<String>,
29    /// The maximum amount of data or number of events allowed before the quota is enforced. Can be specified in bytes or events.
30    #[serde(rename = "limit")]
31    pub limit: crate::datadogV2::model::ObservabilityPipelineQuotaProcessorLimit,
32    /// Name of the quota.
33    #[serde(rename = "name")]
34    pub name: String,
35    /// The action to take when the quota is exceeded. Options:
36    /// - `drop`: Drop the event.
37    /// - `no_action`: Let the event pass through.
38    /// - `overflow_routing`: Route to an overflow destination.
39    ///
40    #[serde(rename = "overflow_action")]
41    pub overflow_action:
42        Option<crate::datadogV2::model::ObservabilityPipelineQuotaProcessorOverflowAction>,
43    /// A list of alternate quota rules that apply to specific sets of events, identified by matching field values. Each override can define a custom limit.
44    #[serde(rename = "overrides")]
45    pub overrides:
46        Option<Vec<crate::datadogV2::model::ObservabilityPipelineQuotaProcessorOverride>>,
47    /// A list of fields used to segment log traffic for quota enforcement. Quotas are tracked independently by unique combinations of these field values.
48    #[serde(rename = "partition_fields")]
49    pub partition_fields: Option<Vec<String>>,
50    /// The processor type. The value should always be `quota`.
51    #[serde(rename = "type")]
52    pub type_: crate::datadogV2::model::ObservabilityPipelineQuotaProcessorType,
53    #[serde(flatten)]
54    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
55    #[serde(skip)]
56    #[serde(default)]
57    pub(crate) _unparsed: bool,
58}
59
60impl ObservabilityPipelineQuotaProcessor {
61    pub fn new(
62        drop_events: bool,
63        id: String,
64        include: String,
65        inputs: Vec<String>,
66        limit: crate::datadogV2::model::ObservabilityPipelineQuotaProcessorLimit,
67        name: String,
68        type_: crate::datadogV2::model::ObservabilityPipelineQuotaProcessorType,
69    ) -> ObservabilityPipelineQuotaProcessor {
70        ObservabilityPipelineQuotaProcessor {
71            drop_events,
72            id,
73            ignore_when_missing_partitions: None,
74            include,
75            inputs,
76            limit,
77            name,
78            overflow_action: None,
79            overrides: None,
80            partition_fields: None,
81            type_,
82            additional_properties: std::collections::BTreeMap::new(),
83            _unparsed: false,
84        }
85    }
86
87    pub fn ignore_when_missing_partitions(mut self, value: bool) -> Self {
88        self.ignore_when_missing_partitions = Some(value);
89        self
90    }
91
92    pub fn overflow_action(
93        mut self,
94        value: crate::datadogV2::model::ObservabilityPipelineQuotaProcessorOverflowAction,
95    ) -> Self {
96        self.overflow_action = Some(value);
97        self
98    }
99
100    pub fn overrides(
101        mut self,
102        value: Vec<crate::datadogV2::model::ObservabilityPipelineQuotaProcessorOverride>,
103    ) -> Self {
104        self.overrides = Some(value);
105        self
106    }
107
108    pub fn partition_fields(mut self, value: Vec<String>) -> Self {
109        self.partition_fields = Some(value);
110        self
111    }
112
113    pub fn additional_properties(
114        mut self,
115        value: std::collections::BTreeMap<String, serde_json::Value>,
116    ) -> Self {
117        self.additional_properties = value;
118        self
119    }
120}
121
122impl<'de> Deserialize<'de> for ObservabilityPipelineQuotaProcessor {
123    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
124    where
125        D: Deserializer<'de>,
126    {
127        struct ObservabilityPipelineQuotaProcessorVisitor;
128        impl<'a> Visitor<'a> for ObservabilityPipelineQuotaProcessorVisitor {
129            type Value = ObservabilityPipelineQuotaProcessor;
130
131            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
132                f.write_str("a mapping")
133            }
134
135            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
136            where
137                M: MapAccess<'a>,
138            {
139                let mut drop_events: Option<bool> = None;
140                let mut id: Option<String> = None;
141                let mut ignore_when_missing_partitions: Option<bool> = None;
142                let mut include: Option<String> = None;
143                let mut inputs: Option<Vec<String>> = None;
144                let mut limit: Option<
145                    crate::datadogV2::model::ObservabilityPipelineQuotaProcessorLimit,
146                > = None;
147                let mut name: Option<String> = None;
148                let mut overflow_action: Option<
149                    crate::datadogV2::model::ObservabilityPipelineQuotaProcessorOverflowAction,
150                > = None;
151                let mut overrides: Option<
152                    Vec<crate::datadogV2::model::ObservabilityPipelineQuotaProcessorOverride>,
153                > = None;
154                let mut partition_fields: Option<Vec<String>> = None;
155                let mut type_: Option<
156                    crate::datadogV2::model::ObservabilityPipelineQuotaProcessorType,
157                > = None;
158                let mut additional_properties: std::collections::BTreeMap<
159                    String,
160                    serde_json::Value,
161                > = std::collections::BTreeMap::new();
162                let mut _unparsed = false;
163
164                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
165                    match k.as_str() {
166                        "drop_events" => {
167                            drop_events =
168                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
169                        }
170                        "id" => {
171                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
172                        }
173                        "ignore_when_missing_partitions" => {
174                            if v.is_null() {
175                                continue;
176                            }
177                            ignore_when_missing_partitions =
178                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
179                        }
180                        "include" => {
181                            include = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
182                        }
183                        "inputs" => {
184                            inputs = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
185                        }
186                        "limit" => {
187                            limit = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
188                        }
189                        "name" => {
190                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
191                        }
192                        "overflow_action" => {
193                            if v.is_null() {
194                                continue;
195                            }
196                            overflow_action =
197                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
198                            if let Some(ref _overflow_action) = overflow_action {
199                                match _overflow_action {
200                                    crate::datadogV2::model::ObservabilityPipelineQuotaProcessorOverflowAction::UnparsedObject(_overflow_action) => {
201                                        _unparsed = true;
202                                    },
203                                    _ => {}
204                                }
205                            }
206                        }
207                        "overrides" => {
208                            if v.is_null() {
209                                continue;
210                            }
211                            overrides = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
212                        }
213                        "partition_fields" => {
214                            if v.is_null() {
215                                continue;
216                            }
217                            partition_fields =
218                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
219                        }
220                        "type" => {
221                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
222                            if let Some(ref _type_) = type_ {
223                                match _type_ {
224                                    crate::datadogV2::model::ObservabilityPipelineQuotaProcessorType::UnparsedObject(_type_) => {
225                                        _unparsed = true;
226                                    },
227                                    _ => {}
228                                }
229                            }
230                        }
231                        &_ => {
232                            if let Ok(value) = serde_json::from_value(v.clone()) {
233                                additional_properties.insert(k, value);
234                            }
235                        }
236                    }
237                }
238                let drop_events =
239                    drop_events.ok_or_else(|| M::Error::missing_field("drop_events"))?;
240                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
241                let include = include.ok_or_else(|| M::Error::missing_field("include"))?;
242                let inputs = inputs.ok_or_else(|| M::Error::missing_field("inputs"))?;
243                let limit = limit.ok_or_else(|| M::Error::missing_field("limit"))?;
244                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
245                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
246
247                let content = ObservabilityPipelineQuotaProcessor {
248                    drop_events,
249                    id,
250                    ignore_when_missing_partitions,
251                    include,
252                    inputs,
253                    limit,
254                    name,
255                    overflow_action,
256                    overrides,
257                    partition_fields,
258                    type_,
259                    additional_properties,
260                    _unparsed,
261                };
262
263                Ok(content)
264            }
265        }
266
267        deserializer.deserialize_any(ObservabilityPipelineQuotaProcessorVisitor)
268    }
269}