Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6611,6 +6611,7 @@ components:
- Select value from matching element
- Compute array length
- Append a value to an array
- Extract key-value pairs from an array
properties:
is_enabled:
default: false
Expand All @@ -6633,6 +6634,7 @@ components:
- $ref: "#/components/schemas/LogsArrayProcessorOperationAppend"
- $ref: "#/components/schemas/LogsArrayProcessorOperationLength"
- $ref: "#/components/schemas/LogsArrayProcessorOperationSelect"
- $ref: "#/components/schemas/LogsArrayProcessorOperationExtractKeyValue"
LogsArrayProcessorOperationAppend:
description: Operation that appends a value to a target array attribute.
properties:
Expand Down Expand Up @@ -6662,6 +6664,44 @@ components:
type: string
x-enum-varnames:
- APPEND
LogsArrayProcessorOperationExtractKeyValue:
description: Operation that extracts key-value pairs from a `source` array and stores the result in the `target` attribute.
properties:
key_to_extract:
description: Key of the attribute in each array element that holds the name to use for the extracted attribute.
example: name
type: string
override_on_conflict:
default: false
description: Whether to override the target element if it's already set.
type: boolean
source:
description: Attribute path of the array to extract key-value pairs from.
example: tags
type: string
target:
description: Attribute that receives the extracted key-value pairs. If not specified, the extracted attributes are added at the root level of the log.
example: extracted
type: string
type:
$ref: "#/components/schemas/LogsArrayProcessorOperationExtractKeyValueType"
value_to_extract:
description: Key of the attribute in each array element that holds the value to use for the extracted attribute.
example: value
type: string
required:
- type
- source
- key_to_extract
- value_to_extract
type: object
LogsArrayProcessorOperationExtractKeyValueType:
description: Operation type.
enum: [key-value]
example: key-value
type: string
x-enum-varnames:
- KEY_VALUE
LogsArrayProcessorOperationLength:
description: Operation that computes the length of a `source` array and stores the result in the `target` attribute.
properties:
Expand Down Expand Up @@ -6746,7 +6786,7 @@ components:
type: string
override_on_conflict:
default: false
description: Override or not the target element if already set,
description: Whether to override the target element if it's already set.
type: boolean
preserve_source:
default: false
Expand Down Expand Up @@ -7912,7 +7952,7 @@ components:
type: string
override_on_conflict:
default: false
description: Override or not the target element if already set.
description: Whether to override the target element if it's already set.
type: boolean
preserve_source:
default: false
Expand Down
41 changes: 41 additions & 0 deletions examples/v1_logs-pipelines_CreateLogsPipeline_2595757342.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Create a pipeline with Array Processor Key Value Operation returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_logs_pipelines::LogsPipelinesAPI;
use datadog_api_client::datadogV1::model::LogsArrayProcessor;
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperation;
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperationExtractKeyValue;
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType;
use datadog_api_client::datadogV1::model::LogsArrayProcessorType;
use datadog_api_client::datadogV1::model::LogsFilter;
use datadog_api_client::datadogV1::model::LogsPipeline;
use datadog_api_client::datadogV1::model::LogsProcessor;

#[tokio::main]
async fn main() {
let body = LogsPipeline::new("testPipelineArrayKeyValue".to_string())
.filter(LogsFilter::new().query("source:python".to_string()))
.processors(vec![LogsProcessor::LogsArrayProcessor(Box::new(
LogsArrayProcessor::new(
LogsArrayProcessorOperation::LogsArrayProcessorOperationExtractKeyValue(Box::new(
LogsArrayProcessorOperationExtractKeyValue::new(
"name".to_string(),
"tags".to_string(),
LogsArrayProcessorOperationExtractKeyValueType::KEY_VALUE,
"value".to_string(),
),
)),
LogsArrayProcessorType::ARRAY_PROCESSOR,
)
.is_enabled(true)
.name("extract_kv".to_string()),
))])
.tags(vec![]);
let configuration = datadog::Configuration::new();
let api = LogsPipelinesAPI::with_config(configuration);
let resp = api.create_logs_pipeline(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
44 changes: 44 additions & 0 deletions examples/v1_logs-pipelines_CreateLogsPipeline_4041812833.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Create a pipeline with Array Processor Key Value Operation with target and
// override_on_conflict returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_logs_pipelines::LogsPipelinesAPI;
use datadog_api_client::datadogV1::model::LogsArrayProcessor;
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperation;
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperationExtractKeyValue;
use datadog_api_client::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType;
use datadog_api_client::datadogV1::model::LogsArrayProcessorType;
use datadog_api_client::datadogV1::model::LogsFilter;
use datadog_api_client::datadogV1::model::LogsPipeline;
use datadog_api_client::datadogV1::model::LogsProcessor;

#[tokio::main]
async fn main() {
let body = LogsPipeline::new("testPipelineArrayKeyValueTarget".to_string())
.filter(LogsFilter::new().query("source:python".to_string()))
.processors(vec![LogsProcessor::LogsArrayProcessor(Box::new(
LogsArrayProcessor::new(
LogsArrayProcessorOperation::LogsArrayProcessorOperationExtractKeyValue(Box::new(
LogsArrayProcessorOperationExtractKeyValue::new(
"name".to_string(),
"tags".to_string(),
LogsArrayProcessorOperationExtractKeyValueType::KEY_VALUE,
"value".to_string(),
)
.override_on_conflict(true)
.target("extracted".to_string()),
)),
LogsArrayProcessorType::ARRAY_PROCESSOR,
)
.is_enabled(true)
.name("extract_kv_to_target".to_string()),
))])
.tags(vec![]);
let configuration = datadog::Configuration::new();
let api = LogsPipelinesAPI::with_config(configuration);
let resp = api.create_logs_pipeline(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
4 changes: 4 additions & 0 deletions src/datadogV1/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,10 @@ pub mod model_logs_array_processor_operation_select;
pub use self::model_logs_array_processor_operation_select::LogsArrayProcessorOperationSelect;
pub mod model_logs_array_processor_operation_select_type;
pub use self::model_logs_array_processor_operation_select_type::LogsArrayProcessorOperationSelectType;
pub mod model_logs_array_processor_operation_extract_key_value;
pub use self::model_logs_array_processor_operation_extract_key_value::LogsArrayProcessorOperationExtractKeyValue;
pub mod model_logs_array_processor_operation_extract_key_value_type;
pub use self::model_logs_array_processor_operation_extract_key_value_type::LogsArrayProcessorOperationExtractKeyValueType;
pub mod model_logs_array_processor_operation;
pub use self::model_logs_array_processor_operation::LogsArrayProcessorOperation;
pub mod model_logs_array_processor_type;
Expand Down
1 change: 1 addition & 0 deletions src/datadogV1/model/model_logs_array_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::fmt::{self, Formatter};
/// - Select value from matching element
/// - Compute array length
/// - Append a value to an array
/// - Extract key-value pairs from an array
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
Expand Down
13 changes: 13 additions & 0 deletions src/datadogV1/model/model_logs_array_processor_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub enum LogsArrayProcessorOperation {
LogsArrayProcessorOperationSelect(
Box<crate::datadogV1::model::LogsArrayProcessorOperationSelect>,
),
LogsArrayProcessorOperationExtractKeyValue(
Box<crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValue>,
),
UnparsedObject(crate::datadog::UnparsedObject),
}

Expand Down Expand Up @@ -50,6 +53,16 @@ impl<'de> Deserialize<'de> for LogsArrayProcessorOperation {
return Ok(LogsArrayProcessorOperation::LogsArrayProcessorOperationSelect(_v));
}
}
if let Ok(_v) = serde_json::from_value::<
Box<crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValue>,
>(value.clone())
{
if !_v._unparsed {
return Ok(
LogsArrayProcessorOperation::LogsArrayProcessorOperationExtractKeyValue(_v),
);
}
}

return Ok(LogsArrayProcessorOperation::UnparsedObject(
crate::datadog::UnparsedObject { value },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// Operation that extracts key-value pairs from a `source` array and stores the result in the `target` attribute.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct LogsArrayProcessorOperationExtractKeyValue {
/// Key of the attribute in each array element that holds the name to use for the extracted attribute.
#[serde(rename = "key_to_extract")]
pub key_to_extract: String,
/// Whether to override the target element if it's already set.
#[serde(rename = "override_on_conflict")]
pub override_on_conflict: Option<bool>,
/// Attribute path of the array to extract key-value pairs from.
#[serde(rename = "source")]
pub source: String,
/// Attribute that receives the extracted key-value pairs. If not specified, the extracted attributes are added at the root level of the log.
#[serde(rename = "target")]
pub target: Option<String>,
/// Operation type.
#[serde(rename = "type")]
pub type_: crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType,
/// Key of the attribute in each array element that holds the value to use for the extracted attribute.
#[serde(rename = "value_to_extract")]
pub value_to_extract: String,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}

impl LogsArrayProcessorOperationExtractKeyValue {
pub fn new(
key_to_extract: String,
source: String,
type_: crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType,
value_to_extract: String,
) -> LogsArrayProcessorOperationExtractKeyValue {
LogsArrayProcessorOperationExtractKeyValue {
key_to_extract,
override_on_conflict: None,
source,
target: None,
type_,
value_to_extract,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}

pub fn override_on_conflict(mut self, value: bool) -> Self {
self.override_on_conflict = Some(value);
self
}

pub fn target(mut self, value: String) -> Self {
self.target = Some(value);
self
}

pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}

impl<'de> Deserialize<'de> for LogsArrayProcessorOperationExtractKeyValue {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct LogsArrayProcessorOperationExtractKeyValueVisitor;
impl<'a> Visitor<'a> for LogsArrayProcessorOperationExtractKeyValueVisitor {
type Value = LogsArrayProcessorOperationExtractKeyValue;

fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}

fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut key_to_extract: Option<String> = None;
let mut override_on_conflict: Option<bool> = None;
let mut source: Option<String> = None;
let mut target: Option<String> = None;
let mut type_: Option<
crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType,
> = None;
let mut value_to_extract: Option<String> = None;
let mut additional_properties: std::collections::BTreeMap<
String,
serde_json::Value,
> = std::collections::BTreeMap::new();
let mut _unparsed = false;

while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"key_to_extract" => {
key_to_extract =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"override_on_conflict" => {
if v.is_null() {
continue;
}
override_on_conflict =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"source" => {
source = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"target" => {
if v.is_null() {
continue;
}
target = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"type" => {
type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _type_) = type_ {
match _type_ {
crate::datadogV1::model::LogsArrayProcessorOperationExtractKeyValueType::UnparsedObject(_type_) => {
_unparsed = true;
},
_ => {}
}
}
}
"value_to_extract" => {
value_to_extract =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
additional_properties.insert(k, value);
}
}
}
}
let key_to_extract =
key_to_extract.ok_or_else(|| M::Error::missing_field("key_to_extract"))?;
let source = source.ok_or_else(|| M::Error::missing_field("source"))?;
let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
let value_to_extract =
value_to_extract.ok_or_else(|| M::Error::missing_field("value_to_extract"))?;

let content = LogsArrayProcessorOperationExtractKeyValue {
key_to_extract,
override_on_conflict,
source,
target,
type_,
value_to_extract,
additional_properties,
_unparsed,
};

Ok(content)
}
}

deserializer.deserialize_any(LogsArrayProcessorOperationExtractKeyValueVisitor)
}
}
Loading
Loading