Skip to content

Commit 22d0ac9

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add key-value type in Logs Array processor (#1863)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent ea8363a commit 22d0ac9

15 files changed

Lines changed: 521 additions & 4 deletions

.generator/schemas/v1/openapi.yaml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6611,6 +6611,7 @@ components:
66116611
- Select value from matching element
66126612
- Compute array length
66136613
- Append a value to an array
6614+
- Extract key-value pairs from an array
66146615
properties:
66156616
is_enabled:
66166617
default: false
@@ -6633,6 +6634,7 @@ components:
66336634
- $ref: "#/components/schemas/LogsArrayProcessorOperationAppend"
66346635
- $ref: "#/components/schemas/LogsArrayProcessorOperationLength"
66356636
- $ref: "#/components/schemas/LogsArrayProcessorOperationSelect"
6637+
- $ref: "#/components/schemas/LogsArrayProcessorOperationExtractKeyValue"
66366638
LogsArrayProcessorOperationAppend:
66376639
description: Operation that appends a value to a target array attribute.
66386640
properties:
@@ -6662,6 +6664,44 @@ components:
66626664
type: string
66636665
x-enum-varnames:
66646666
- APPEND
6667+
LogsArrayProcessorOperationExtractKeyValue:
6668+
description: Operation that extracts key-value pairs from a `source` array and stores the result in the `target` attribute.
6669+
properties:
6670+
key_to_extract:
6671+
description: Key of the attribute in each array element that holds the name to use for the extracted attribute.
6672+
example: name
6673+
type: string
6674+
override_on_conflict:
6675+
default: false
6676+
description: Whether to override the target element if it's already set.
6677+
type: boolean
6678+
source:
6679+
description: Attribute path of the array to extract key-value pairs from.
6680+
example: tags
6681+
type: string
6682+
target:
6683+
description: Attribute that receives the extracted key-value pairs. If not specified, the extracted attributes are added at the root level of the log.
6684+
example: extracted
6685+
type: string
6686+
type:
6687+
$ref: "#/components/schemas/LogsArrayProcessorOperationExtractKeyValueType"
6688+
value_to_extract:
6689+
description: Key of the attribute in each array element that holds the value to use for the extracted attribute.
6690+
example: value
6691+
type: string
6692+
required:
6693+
- type
6694+
- source
6695+
- key_to_extract
6696+
- value_to_extract
6697+
type: object
6698+
LogsArrayProcessorOperationExtractKeyValueType:
6699+
description: Operation type.
6700+
enum: [key-value]
6701+
example: key-value
6702+
type: string
6703+
x-enum-varnames:
6704+
- KEY_VALUE
66656705
LogsArrayProcessorOperationLength:
66666706
description: Operation that computes the length of a `source` array and stores the result in the `target` attribute.
66676707
properties:
@@ -6746,7 +6786,7 @@ components:
67466786
type: string
67476787
override_on_conflict:
67486788
default: false
6749-
description: Override or not the target element if already set,
6789+
description: Whether to override the target element if it's already set.
67506790
type: boolean
67516791
preserve_source:
67526792
default: false
@@ -7912,7 +7952,7 @@ components:
79127952
type: string
79137953
override_on_conflict:
79147954
default: false
7915-
description: Override or not the target element if already set.
7955+
description: Whether to override the target element if it's already set.
79167956
type: boolean
79177957
preserve_source:
79187958
default: false
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Create a pipeline with Array Processor Key Value Operation returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV1::api_logs_pipelines::LogsPipelinesAPI;
4+
use datadog_api_client::datadogV1::model::LogsArrayProcessor;
5+
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperation;
6+
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperationExtractKeyValue;
7+
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType;
8+
use datadog_api_client::datadogV1::model::LogsArrayProcessorType;
9+
use datadog_api_client::datadogV1::model::LogsFilter;
10+
use datadog_api_client::datadogV1::model::LogsPipeline;
11+
use datadog_api_client::datadogV1::model::LogsProcessor;
12+
13+
#[tokio::main]
14+
async fn main() {
15+
let body = LogsPipeline::new("testPipelineArrayKeyValue".to_string())
16+
.filter(LogsFilter::new().query("source:python".to_string()))
17+
.processors(vec![LogsProcessor::LogsArrayProcessor(Box::new(
18+
LogsArrayProcessor::new(
19+
LogsArrayProcessorOperation::LogsArrayProcessorOperationExtractKeyValue(Box::new(
20+
LogsArrayProcessorOperationExtractKeyValue::new(
21+
"name".to_string(),
22+
"tags".to_string(),
23+
LogsArrayProcessorOperationExtractKeyValueType::KEY_VALUE,
24+
"value".to_string(),
25+
),
26+
)),
27+
LogsArrayProcessorType::ARRAY_PROCESSOR,
28+
)
29+
.is_enabled(true)
30+
.name("extract_kv".to_string()),
31+
))])
32+
.tags(vec![]);
33+
let configuration = datadog::Configuration::new();
34+
let api = LogsPipelinesAPI::with_config(configuration);
35+
let resp = api.create_logs_pipeline(body).await;
36+
if let Ok(value) = resp {
37+
println!("{:#?}", value);
38+
} else {
39+
println!("{:#?}", resp.unwrap_err());
40+
}
41+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Create a pipeline with Array Processor Key Value Operation with target and
2+
// override_on_conflict returns "OK" response
3+
use datadog_api_client::datadog;
4+
use datadog_api_client::datadogV1::api_logs_pipelines::LogsPipelinesAPI;
5+
use datadog_api_client::datadogV1::model::LogsArrayProcessor;
6+
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperation;
7+
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperationExtractKeyValue;
8+
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType;
9+
use datadog_api_client::datadogV1::model::LogsArrayProcessorType;
10+
use datadog_api_client::datadogV1::model::LogsFilter;
11+
use datadog_api_client::datadogV1::model::LogsPipeline;
12+
use datadog_api_client::datadogV1::model::LogsProcessor;
13+
14+
#[tokio::main]
15+
async fn main() {
16+
let body = LogsPipeline::new("testPipelineArrayKeyValueTarget".to_string())
17+
.filter(LogsFilter::new().query("source:python".to_string()))
18+
.processors(vec![LogsProcessor::LogsArrayProcessor(Box::new(
19+
LogsArrayProcessor::new(
20+
LogsArrayProcessorOperation::LogsArrayProcessorOperationExtractKeyValue(Box::new(
21+
LogsArrayProcessorOperationExtractKeyValue::new(
22+
"name".to_string(),
23+
"tags".to_string(),
24+
LogsArrayProcessorOperationExtractKeyValueType::KEY_VALUE,
25+
"value".to_string(),
26+
)
27+
.override_on_conflict(true)
28+
.target("extracted".to_string()),
29+
)),
30+
LogsArrayProcessorType::ARRAY_PROCESSOR,
31+
)
32+
.is_enabled(true)
33+
.name("extract_kv_to_target".to_string()),
34+
))])
35+
.tags(vec![]);
36+
let configuration = datadog::Configuration::new();
37+
let api = LogsPipelinesAPI::with_config(configuration);
38+
let resp = api.create_logs_pipeline(body).await;
39+
if let Ok(value) = resp {
40+
println!("{:#?}", value);
41+
} else {
42+
println!("{:#?}", resp.unwrap_err());
43+
}
44+
}

src/datadogV1/model/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,10 @@ pub mod model_logs_array_processor_operation_select;
12421242
pub use self::model_logs_array_processor_operation_select::LogsArrayProcessorOperationSelect;
12431243
pub mod model_logs_array_processor_operation_select_type;
12441244
pub use self::model_logs_array_processor_operation_select_type::LogsArrayProcessorOperationSelectType;
1245+
pub mod model_logs_array_processor_operation_extract_key_value;
1246+
pub use self::model_logs_array_processor_operation_extract_key_value::LogsArrayProcessorOperationExtractKeyValue;
1247+
pub mod model_logs_array_processor_operation_extract_key_value_type;
1248+
pub use self::model_logs_array_processor_operation_extract_key_value_type::LogsArrayProcessorOperationExtractKeyValueType;
12451249
pub mod model_logs_array_processor_operation;
12461250
pub use self::model_logs_array_processor_operation::LogsArrayProcessorOperation;
12471251
pub mod model_logs_array_processor_type;

src/datadogV1/model/model_logs_array_processor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::fmt::{self, Formatter};
1111
/// - Select value from matching element
1212
/// - Compute array length
1313
/// - Append a value to an array
14+
/// - Extract key-value pairs from an array
1415
#[non_exhaustive]
1516
#[skip_serializing_none]
1617
#[derive(Clone, Debug, PartialEq, Serialize)]

src/datadogV1/model/model_logs_array_processor_operation.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub enum LogsArrayProcessorOperation {
1717
LogsArrayProcessorOperationSelect(
1818
Box<crate::datadogV1::model::LogsArrayProcessorOperationSelect>,
1919
),
20+
LogsArrayProcessorOperationExtractKeyValue(
21+
Box<crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValue>,
22+
),
2023
UnparsedObject(crate::datadog::UnparsedObject),
2124
}
2225

@@ -50,6 +53,16 @@ impl<'de> Deserialize<'de> for LogsArrayProcessorOperation {
5053
return Ok(LogsArrayProcessorOperation::LogsArrayProcessorOperationSelect(_v));
5154
}
5255
}
56+
if let Ok(_v) = serde_json::from_value::<
57+
Box<crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValue>,
58+
>(value.clone())
59+
{
60+
if !_v._unparsed {
61+
return Ok(
62+
LogsArrayProcessorOperation::LogsArrayProcessorOperationExtractKeyValue(_v),
63+
);
64+
}
65+
}
5366

5467
return Ok(LogsArrayProcessorOperation::UnparsedObject(
5568
crate::datadog::UnparsedObject { value },
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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+
/// Operation that extracts key-value pairs from a `source` array and stores the result in the `target` attribute.
10+
#[non_exhaustive]
11+
#[skip_serializing_none]
12+
#[derive(Clone, Debug, PartialEq, Serialize)]
13+
pub struct LogsArrayProcessorOperationExtractKeyValue {
14+
/// Key of the attribute in each array element that holds the name to use for the extracted attribute.
15+
#[serde(rename = "key_to_extract")]
16+
pub key_to_extract: String,
17+
/// Whether to override the target element if it's already set.
18+
#[serde(rename = "override_on_conflict")]
19+
pub override_on_conflict: Option<bool>,
20+
/// Attribute path of the array to extract key-value pairs from.
21+
#[serde(rename = "source")]
22+
pub source: String,
23+
/// Attribute that receives the extracted key-value pairs. If not specified, the extracted attributes are added at the root level of the log.
24+
#[serde(rename = "target")]
25+
pub target: Option<String>,
26+
/// Operation type.
27+
#[serde(rename = "type")]
28+
pub type_: crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType,
29+
/// Key of the attribute in each array element that holds the value to use for the extracted attribute.
30+
#[serde(rename = "value_to_extract")]
31+
pub value_to_extract: String,
32+
#[serde(flatten)]
33+
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
34+
#[serde(skip)]
35+
#[serde(default)]
36+
pub(crate) _unparsed: bool,
37+
}
38+
39+
impl LogsArrayProcessorOperationExtractKeyValue {
40+
pub fn new(
41+
key_to_extract: String,
42+
source: String,
43+
type_: crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType,
44+
value_to_extract: String,
45+
) -> LogsArrayProcessorOperationExtractKeyValue {
46+
LogsArrayProcessorOperationExtractKeyValue {
47+
key_to_extract,
48+
override_on_conflict: None,
49+
source,
50+
target: None,
51+
type_,
52+
value_to_extract,
53+
additional_properties: std::collections::BTreeMap::new(),
54+
_unparsed: false,
55+
}
56+
}
57+
58+
pub fn override_on_conflict(mut self, value: bool) -> Self {
59+
self.override_on_conflict = Some(value);
60+
self
61+
}
62+
63+
pub fn target(mut self, value: String) -> Self {
64+
self.target = Some(value);
65+
self
66+
}
67+
68+
pub fn additional_properties(
69+
mut self,
70+
value: std::collections::BTreeMap<String, serde_json::Value>,
71+
) -> Self {
72+
self.additional_properties = value;
73+
self
74+
}
75+
}
76+
77+
impl<'de> Deserialize<'de> for LogsArrayProcessorOperationExtractKeyValue {
78+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
79+
where
80+
D: Deserializer<'de>,
81+
{
82+
struct LogsArrayProcessorOperationExtractKeyValueVisitor;
83+
impl<'a> Visitor<'a> for LogsArrayProcessorOperationExtractKeyValueVisitor {
84+
type Value = LogsArrayProcessorOperationExtractKeyValue;
85+
86+
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
87+
f.write_str("a mapping")
88+
}
89+
90+
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
91+
where
92+
M: MapAccess<'a>,
93+
{
94+
let mut key_to_extract: Option<String> = None;
95+
let mut override_on_conflict: Option<bool> = None;
96+
let mut source: Option<String> = None;
97+
let mut target: Option<String> = None;
98+
let mut type_: Option<
99+
crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType,
100+
> = None;
101+
let mut value_to_extract: Option<String> = None;
102+
let mut additional_properties: std::collections::BTreeMap<
103+
String,
104+
serde_json::Value,
105+
> = std::collections::BTreeMap::new();
106+
let mut _unparsed = false;
107+
108+
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
109+
match k.as_str() {
110+
"key_to_extract" => {
111+
key_to_extract =
112+
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
113+
}
114+
"override_on_conflict" => {
115+
if v.is_null() {
116+
continue;
117+
}
118+
override_on_conflict =
119+
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
120+
}
121+
"source" => {
122+
source = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
123+
}
124+
"target" => {
125+
if v.is_null() {
126+
continue;
127+
}
128+
target = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
129+
}
130+
"type" => {
131+
type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
132+
if let Some(ref _type_) = type_ {
133+
match _type_ {
134+
crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType::UnparsedObject(_type_) => {
135+
_unparsed = true;
136+
},
137+
_ => {}
138+
}
139+
}
140+
}
141+
"value_to_extract" => {
142+
value_to_extract =
143+
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
144+
}
145+
&_ => {
146+
if let Ok(value) = serde_json::from_value(v.clone()) {
147+
additional_properties.insert(k, value);
148+
}
149+
}
150+
}
151+
}
152+
let key_to_extract =
153+
key_to_extract.ok_or_else(|| M::Error::missing_field("key_to_extract"))?;
154+
let source = source.ok_or_else(|| M::Error::missing_field("source"))?;
155+
let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
156+
let value_to_extract =
157+
value_to_extract.ok_or_else(|| M::Error::missing_field("value_to_extract"))?;
158+
159+
let content = LogsArrayProcessorOperationExtractKeyValue {
160+
key_to_extract,
161+
override_on_conflict,
162+
source,
163+
target,
164+
type_,
165+
value_to_extract,
166+
additional_properties,
167+
_unparsed,
168+
};
169+
170+
Ok(content)
171+
}
172+
}
173+
174+
deserializer.deserialize_any(LogsArrayProcessorOperationExtractKeyValueVisitor)
175+
}
176+
}

0 commit comments

Comments
 (0)