|
| 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. |
| 4 | +use serde::de::{Error, MapAccess, Visitor}; |
| 5 | +use serde::{Deserialize, Deserializer, Serialize}; |
| 6 | +use serde_with::skip_serializing_none; |
| 7 | +use std::fmt::{self, Formatter}; |
| 8 | + |
| 9 | +/// The `datadog_tags` processor filters logs based on Datadog tags. It can include or exclude logs that have specific tag keys. |
| 10 | +#[non_exhaustive] |
| 11 | +#[skip_serializing_none] |
| 12 | +#[derive(Clone, Debug, PartialEq, Serialize)] |
| 13 | +pub struct ObservabilityPipelineDatadogTagsProcessor { |
| 14 | + /// The action to take on logs that match the specified tag keys. |
| 15 | + #[serde(rename = "action")] |
| 16 | + pub action: crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorAction, |
| 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 | + /// A Datadog search query used to determine which logs this processor targets. |
| 21 | + #[serde(rename = "include")] |
| 22 | + pub include: String, |
| 23 | + /// A list of component IDs whose output is used as the `input` for this component. |
| 24 | + #[serde(rename = "inputs")] |
| 25 | + pub inputs: Vec<String>, |
| 26 | + /// A list of tag keys to filter on. Tag keys must start with a letter and contain only letters, numbers, underscores, hyphens, periods, or slashes. Maximum 100 keys allowed. |
| 27 | + #[serde(rename = "keys")] |
| 28 | + pub keys: Vec<String>, |
| 29 | + /// The filtering mode. Currently only `filter` is supported. |
| 30 | + #[serde(rename = "mode")] |
| 31 | + pub mode: crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorMode, |
| 32 | + /// The processor type. The value should always be `datadog_tags`. |
| 33 | + #[serde(rename = "type")] |
| 34 | + pub type_: crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorType, |
| 35 | + #[serde(flatten)] |
| 36 | + pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>, |
| 37 | + #[serde(skip)] |
| 38 | + #[serde(default)] |
| 39 | + pub(crate) _unparsed: bool, |
| 40 | +} |
| 41 | + |
| 42 | +impl ObservabilityPipelineDatadogTagsProcessor { |
| 43 | + pub fn new( |
| 44 | + action: crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorAction, |
| 45 | + id: String, |
| 46 | + include: String, |
| 47 | + inputs: Vec<String>, |
| 48 | + keys: Vec<String>, |
| 49 | + mode: crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorMode, |
| 50 | + type_: crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorType, |
| 51 | + ) -> ObservabilityPipelineDatadogTagsProcessor { |
| 52 | + ObservabilityPipelineDatadogTagsProcessor { |
| 53 | + action, |
| 54 | + id, |
| 55 | + include, |
| 56 | + inputs, |
| 57 | + keys, |
| 58 | + mode, |
| 59 | + type_, |
| 60 | + additional_properties: std::collections::BTreeMap::new(), |
| 61 | + _unparsed: false, |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + pub fn additional_properties( |
| 66 | + mut self, |
| 67 | + value: std::collections::BTreeMap<String, serde_json::Value>, |
| 68 | + ) -> Self { |
| 69 | + self.additional_properties = value; |
| 70 | + self |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +impl<'de> Deserialize<'de> for ObservabilityPipelineDatadogTagsProcessor { |
| 75 | + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 76 | + where |
| 77 | + D: Deserializer<'de>, |
| 78 | + { |
| 79 | + struct ObservabilityPipelineDatadogTagsProcessorVisitor; |
| 80 | + impl<'a> Visitor<'a> for ObservabilityPipelineDatadogTagsProcessorVisitor { |
| 81 | + type Value = ObservabilityPipelineDatadogTagsProcessor; |
| 82 | + |
| 83 | + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 84 | + f.write_str("a mapping") |
| 85 | + } |
| 86 | + |
| 87 | + fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> |
| 88 | + where |
| 89 | + M: MapAccess<'a>, |
| 90 | + { |
| 91 | + let mut action: Option< |
| 92 | + crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorAction, |
| 93 | + > = None; |
| 94 | + let mut id: Option<String> = None; |
| 95 | + let mut include: Option<String> = None; |
| 96 | + let mut inputs: Option<Vec<String>> = None; |
| 97 | + let mut keys: Option<Vec<String>> = None; |
| 98 | + let mut mode: Option< |
| 99 | + crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorMode, |
| 100 | + > = None; |
| 101 | + let mut type_: Option< |
| 102 | + crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorType, |
| 103 | + > = None; |
| 104 | + let mut additional_properties: std::collections::BTreeMap< |
| 105 | + String, |
| 106 | + serde_json::Value, |
| 107 | + > = std::collections::BTreeMap::new(); |
| 108 | + let mut _unparsed = false; |
| 109 | + |
| 110 | + while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? { |
| 111 | + match k.as_str() { |
| 112 | + "action" => { |
| 113 | + action = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 114 | + if let Some(ref _action) = action { |
| 115 | + match _action { |
| 116 | + crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorAction::UnparsedObject(_action) => { |
| 117 | + _unparsed = true; |
| 118 | + }, |
| 119 | + _ => {} |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + "id" => { |
| 124 | + id = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 125 | + } |
| 126 | + "include" => { |
| 127 | + include = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 128 | + } |
| 129 | + "inputs" => { |
| 130 | + inputs = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 131 | + } |
| 132 | + "keys" => { |
| 133 | + keys = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 134 | + } |
| 135 | + "mode" => { |
| 136 | + mode = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 137 | + if let Some(ref _mode) = mode { |
| 138 | + match _mode { |
| 139 | + crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorMode::UnparsedObject(_mode) => { |
| 140 | + _unparsed = true; |
| 141 | + }, |
| 142 | + _ => {} |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + "type" => { |
| 147 | + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); |
| 148 | + if let Some(ref _type_) = type_ { |
| 149 | + match _type_ { |
| 150 | + crate::datadogV2::model::ObservabilityPipelineDatadogTagsProcessorType::UnparsedObject(_type_) => { |
| 151 | + _unparsed = true; |
| 152 | + }, |
| 153 | + _ => {} |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | + &_ => { |
| 158 | + if let Ok(value) = serde_json::from_value(v.clone()) { |
| 159 | + additional_properties.insert(k, value); |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + let action = action.ok_or_else(|| M::Error::missing_field("action"))?; |
| 165 | + let id = id.ok_or_else(|| M::Error::missing_field("id"))?; |
| 166 | + let include = include.ok_or_else(|| M::Error::missing_field("include"))?; |
| 167 | + let inputs = inputs.ok_or_else(|| M::Error::missing_field("inputs"))?; |
| 168 | + let keys = keys.ok_or_else(|| M::Error::missing_field("keys"))?; |
| 169 | + let mode = mode.ok_or_else(|| M::Error::missing_field("mode"))?; |
| 170 | + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; |
| 171 | + |
| 172 | + let content = ObservabilityPipelineDatadogTagsProcessor { |
| 173 | + action, |
| 174 | + id, |
| 175 | + include, |
| 176 | + inputs, |
| 177 | + keys, |
| 178 | + mode, |
| 179 | + type_, |
| 180 | + additional_properties, |
| 181 | + _unparsed, |
| 182 | + }; |
| 183 | + |
| 184 | + Ok(content) |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + deserializer.deserialize_any(ObservabilityPipelineDatadogTagsProcessorVisitor) |
| 189 | + } |
| 190 | +} |
0 commit comments