diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index b043de0e648..13b137f25f8 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -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 @@ -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: @@ -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: @@ -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 @@ -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 diff --git a/api/datadogV1/model_logs_array_processor.go b/api/datadogV1/model_logs_array_processor.go index 4e867744a7d..b95ecb94660 100644 --- a/api/datadogV1/model_logs_array_processor.go +++ b/api/datadogV1/model_logs_array_processor.go @@ -15,6 +15,7 @@ import ( // - Select value from matching element // - Compute array length // - Append a value to an array +// - Extract key-value pairs from an array type LogsArrayProcessor struct { // Whether or not the processor is enabled. IsEnabled *bool `json:"is_enabled,omitempty"` diff --git a/api/datadogV1/model_logs_array_processor_operation.go b/api/datadogV1/model_logs_array_processor_operation.go index 3db6b9456af..4847c29d342 100644 --- a/api/datadogV1/model_logs_array_processor_operation.go +++ b/api/datadogV1/model_logs_array_processor_operation.go @@ -10,9 +10,10 @@ import ( // LogsArrayProcessorOperation - Configuration of the array processor operation to perform. type LogsArrayProcessorOperation struct { - LogsArrayProcessorOperationAppend *LogsArrayProcessorOperationAppend - LogsArrayProcessorOperationLength *LogsArrayProcessorOperationLength - LogsArrayProcessorOperationSelect *LogsArrayProcessorOperationSelect + LogsArrayProcessorOperationAppend *LogsArrayProcessorOperationAppend + LogsArrayProcessorOperationLength *LogsArrayProcessorOperationLength + LogsArrayProcessorOperationSelect *LogsArrayProcessorOperationSelect + LogsArrayProcessorOperationExtractKeyValue *LogsArrayProcessorOperationExtractKeyValue // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct UnparsedObject interface{} @@ -33,6 +34,11 @@ func LogsArrayProcessorOperationSelectAsLogsArrayProcessorOperation(v *LogsArray return LogsArrayProcessorOperation{LogsArrayProcessorOperationSelect: v} } +// LogsArrayProcessorOperationExtractKeyValueAsLogsArrayProcessorOperation is a convenience function that returns LogsArrayProcessorOperationExtractKeyValue wrapped in LogsArrayProcessorOperation. +func LogsArrayProcessorOperationExtractKeyValueAsLogsArrayProcessorOperation(v *LogsArrayProcessorOperationExtractKeyValue) LogsArrayProcessorOperation { + return LogsArrayProcessorOperation{LogsArrayProcessorOperationExtractKeyValue: v} +} + // UnmarshalJSON turns data into one of the pointers in the struct. func (obj *LogsArrayProcessorOperation) UnmarshalJSON(data []byte) error { var err error @@ -88,11 +94,29 @@ func (obj *LogsArrayProcessorOperation) UnmarshalJSON(data []byte) error { obj.LogsArrayProcessorOperationSelect = nil } + // try to unmarshal data into LogsArrayProcessorOperationExtractKeyValue + err = datadog.Unmarshal(data, &obj.LogsArrayProcessorOperationExtractKeyValue) + if err == nil { + if obj.LogsArrayProcessorOperationExtractKeyValue != nil && obj.LogsArrayProcessorOperationExtractKeyValue.UnparsedObject == nil { + jsonLogsArrayProcessorOperationExtractKeyValue, _ := datadog.Marshal(obj.LogsArrayProcessorOperationExtractKeyValue) + if string(jsonLogsArrayProcessorOperationExtractKeyValue) == "{}" { // empty struct + obj.LogsArrayProcessorOperationExtractKeyValue = nil + } else { + match++ + } + } else { + obj.LogsArrayProcessorOperationExtractKeyValue = nil + } + } else { + obj.LogsArrayProcessorOperationExtractKeyValue = nil + } + if match != 1 { // more than 1 match // reset to nil obj.LogsArrayProcessorOperationAppend = nil obj.LogsArrayProcessorOperationLength = nil obj.LogsArrayProcessorOperationSelect = nil + obj.LogsArrayProcessorOperationExtractKeyValue = nil return datadog.Unmarshal(data, &obj.UnparsedObject) } return nil // exactly one match @@ -112,6 +136,10 @@ func (obj LogsArrayProcessorOperation) MarshalJSON() ([]byte, error) { return datadog.Marshal(&obj.LogsArrayProcessorOperationSelect) } + if obj.LogsArrayProcessorOperationExtractKeyValue != nil { + return datadog.Marshal(&obj.LogsArrayProcessorOperationExtractKeyValue) + } + if obj.UnparsedObject != nil { return datadog.Marshal(obj.UnparsedObject) } @@ -132,6 +160,10 @@ func (obj *LogsArrayProcessorOperation) GetActualInstance() interface{} { return obj.LogsArrayProcessorOperationSelect } + if obj.LogsArrayProcessorOperationExtractKeyValue != nil { + return obj.LogsArrayProcessorOperationExtractKeyValue + } + // all schemas are nil return nil } diff --git a/api/datadogV1/model_logs_array_processor_operation_extract_key_value.go b/api/datadogV1/model_logs_array_processor_operation_extract_key_value.go new file mode 100644 index 00000000000..21608a6c221 --- /dev/null +++ b/api/datadogV1/model_logs_array_processor_operation_extract_key_value.go @@ -0,0 +1,281 @@ +// 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. + +package datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// LogsArrayProcessorOperationExtractKeyValue Operation that extracts key-value pairs from a `source` array and stores the result in the `target` attribute. +type LogsArrayProcessorOperationExtractKeyValue struct { + // Key of the attribute in each array element that holds the name to use for the extracted attribute. + KeyToExtract string `json:"key_to_extract"` + // Whether to override the target element if it's already set. + OverrideOnConflict *bool `json:"override_on_conflict,omitempty"` + // Attribute path of the array to extract key-value pairs from. + Source string `json:"source"` + // Attribute that receives the extracted key-value pairs. If not specified, the extracted attributes are added at the root level of the log. + Target *string `json:"target,omitempty"` + // Operation type. + Type LogsArrayProcessorOperationExtractKeyValueType `json:"type"` + // Key of the attribute in each array element that holds the value to use for the extracted attribute. + ValueToExtract string `json:"value_to_extract"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:"-"` + AdditionalProperties map[string]interface{} `json:"-"` +} + +// NewLogsArrayProcessorOperationExtractKeyValue instantiates a new LogsArrayProcessorOperationExtractKeyValue object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewLogsArrayProcessorOperationExtractKeyValue(keyToExtract string, source string, typeVar LogsArrayProcessorOperationExtractKeyValueType, valueToExtract string) *LogsArrayProcessorOperationExtractKeyValue { + this := LogsArrayProcessorOperationExtractKeyValue{} + this.KeyToExtract = keyToExtract + var overrideOnConflict bool = false + this.OverrideOnConflict = &overrideOnConflict + this.Source = source + this.Type = typeVar + this.ValueToExtract = valueToExtract + return &this +} + +// NewLogsArrayProcessorOperationExtractKeyValueWithDefaults instantiates a new LogsArrayProcessorOperationExtractKeyValue object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewLogsArrayProcessorOperationExtractKeyValueWithDefaults() *LogsArrayProcessorOperationExtractKeyValue { + this := LogsArrayProcessorOperationExtractKeyValue{} + var overrideOnConflict bool = false + this.OverrideOnConflict = &overrideOnConflict + return &this +} + +// GetKeyToExtract returns the KeyToExtract field value. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetKeyToExtract() string { + if o == nil { + var ret string + return ret + } + return o.KeyToExtract +} + +// GetKeyToExtractOk returns a tuple with the KeyToExtract field value +// and a boolean to check if the value has been set. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetKeyToExtractOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.KeyToExtract, true +} + +// SetKeyToExtract sets field value. +func (o *LogsArrayProcessorOperationExtractKeyValue) SetKeyToExtract(v string) { + o.KeyToExtract = v +} + +// GetOverrideOnConflict returns the OverrideOnConflict field value if set, zero value otherwise. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetOverrideOnConflict() bool { + if o == nil || o.OverrideOnConflict == nil { + var ret bool + return ret + } + return *o.OverrideOnConflict +} + +// GetOverrideOnConflictOk returns a tuple with the OverrideOnConflict field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetOverrideOnConflictOk() (*bool, bool) { + if o == nil || o.OverrideOnConflict == nil { + return nil, false + } + return o.OverrideOnConflict, true +} + +// HasOverrideOnConflict returns a boolean if a field has been set. +func (o *LogsArrayProcessorOperationExtractKeyValue) HasOverrideOnConflict() bool { + return o != nil && o.OverrideOnConflict != nil +} + +// SetOverrideOnConflict gets a reference to the given bool and assigns it to the OverrideOnConflict field. +func (o *LogsArrayProcessorOperationExtractKeyValue) SetOverrideOnConflict(v bool) { + o.OverrideOnConflict = &v +} + +// GetSource returns the Source field value. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetSource() string { + if o == nil { + var ret string + return ret + } + return o.Source +} + +// GetSourceOk returns a tuple with the Source field value +// and a boolean to check if the value has been set. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetSourceOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Source, true +} + +// SetSource sets field value. +func (o *LogsArrayProcessorOperationExtractKeyValue) SetSource(v string) { + o.Source = v +} + +// GetTarget returns the Target field value if set, zero value otherwise. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetTarget() string { + if o == nil || o.Target == nil { + var ret string + return ret + } + return *o.Target +} + +// GetTargetOk returns a tuple with the Target field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetTargetOk() (*string, bool) { + if o == nil || o.Target == nil { + return nil, false + } + return o.Target, true +} + +// HasTarget returns a boolean if a field has been set. +func (o *LogsArrayProcessorOperationExtractKeyValue) HasTarget() bool { + return o != nil && o.Target != nil +} + +// SetTarget gets a reference to the given string and assigns it to the Target field. +func (o *LogsArrayProcessorOperationExtractKeyValue) SetTarget(v string) { + o.Target = &v +} + +// GetType returns the Type field value. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetType() LogsArrayProcessorOperationExtractKeyValueType { + if o == nil { + var ret LogsArrayProcessorOperationExtractKeyValueType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetTypeOk() (*LogsArrayProcessorOperationExtractKeyValueType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *LogsArrayProcessorOperationExtractKeyValue) SetType(v LogsArrayProcessorOperationExtractKeyValueType) { + o.Type = v +} + +// GetValueToExtract returns the ValueToExtract field value. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetValueToExtract() string { + if o == nil { + var ret string + return ret + } + return o.ValueToExtract +} + +// GetValueToExtractOk returns a tuple with the ValueToExtract field value +// and a boolean to check if the value has been set. +func (o *LogsArrayProcessorOperationExtractKeyValue) GetValueToExtractOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ValueToExtract, true +} + +// SetValueToExtract sets field value. +func (o *LogsArrayProcessorOperationExtractKeyValue) SetValueToExtract(v string) { + o.ValueToExtract = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o LogsArrayProcessorOperationExtractKeyValue) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["key_to_extract"] = o.KeyToExtract + if o.OverrideOnConflict != nil { + toSerialize["override_on_conflict"] = o.OverrideOnConflict + } + toSerialize["source"] = o.Source + if o.Target != nil { + toSerialize["target"] = o.Target + } + toSerialize["type"] = o.Type + toSerialize["value_to_extract"] = o.ValueToExtract + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *LogsArrayProcessorOperationExtractKeyValue) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + KeyToExtract *string `json:"key_to_extract"` + OverrideOnConflict *bool `json:"override_on_conflict,omitempty"` + Source *string `json:"source"` + Target *string `json:"target,omitempty"` + Type *LogsArrayProcessorOperationExtractKeyValueType `json:"type"` + ValueToExtract *string `json:"value_to_extract"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.KeyToExtract == nil { + return fmt.Errorf("required field key_to_extract missing") + } + if all.Source == nil { + return fmt.Errorf("required field source missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + if all.ValueToExtract == nil { + return fmt.Errorf("required field value_to_extract missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"key_to_extract", "override_on_conflict", "source", "target", "type", "value_to_extract"}) + } else { + return err + } + + hasInvalidField := false + o.KeyToExtract = *all.KeyToExtract + o.OverrideOnConflict = all.OverrideOnConflict + o.Source = *all.Source + o.Target = all.Target + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + o.ValueToExtract = *all.ValueToExtract + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_logs_array_processor_operation_extract_key_value_type.go b/api/datadogV1/model_logs_array_processor_operation_extract_key_value_type.go new file mode 100644 index 00000000000..01d8489fc92 --- /dev/null +++ b/api/datadogV1/model_logs_array_processor_operation_extract_key_value_type.go @@ -0,0 +1,64 @@ +// 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. + +package datadogV1 + +import ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// LogsArrayProcessorOperationExtractKeyValueType Operation type. +type LogsArrayProcessorOperationExtractKeyValueType string + +// List of LogsArrayProcessorOperationExtractKeyValueType. +const ( + LOGSARRAYPROCESSOROPERATIONEXTRACTKEYVALUETYPE_KEY_VALUE LogsArrayProcessorOperationExtractKeyValueType = "key-value" +) + +var allowedLogsArrayProcessorOperationExtractKeyValueTypeEnumValues = []LogsArrayProcessorOperationExtractKeyValueType{ + LOGSARRAYPROCESSOROPERATIONEXTRACTKEYVALUETYPE_KEY_VALUE, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *LogsArrayProcessorOperationExtractKeyValueType) GetAllowedValues() []LogsArrayProcessorOperationExtractKeyValueType { + return allowedLogsArrayProcessorOperationExtractKeyValueTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *LogsArrayProcessorOperationExtractKeyValueType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = LogsArrayProcessorOperationExtractKeyValueType(value) + return nil +} + +// NewLogsArrayProcessorOperationExtractKeyValueTypeFromValue returns a pointer to a valid LogsArrayProcessorOperationExtractKeyValueType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewLogsArrayProcessorOperationExtractKeyValueTypeFromValue(v string) (*LogsArrayProcessorOperationExtractKeyValueType, error) { + ev := LogsArrayProcessorOperationExtractKeyValueType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for LogsArrayProcessorOperationExtractKeyValueType: valid values are %v", v, allowedLogsArrayProcessorOperationExtractKeyValueTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v LogsArrayProcessorOperationExtractKeyValueType) IsValid() bool { + for _, existing := range allowedLogsArrayProcessorOperationExtractKeyValueTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to LogsArrayProcessorOperationExtractKeyValueType value. +func (v LogsArrayProcessorOperationExtractKeyValueType) Ptr() *LogsArrayProcessorOperationExtractKeyValueType { + return &v +} diff --git a/api/datadogV1/model_logs_attribute_remapper.go b/api/datadogV1/model_logs_attribute_remapper.go index 29c3ac01cfb..129c73e3276 100644 --- a/api/datadogV1/model_logs_attribute_remapper.go +++ b/api/datadogV1/model_logs_attribute_remapper.go @@ -18,7 +18,7 @@ type LogsAttributeRemapper struct { IsEnabled *bool `json:"is_enabled,omitempty"` // Name of the processor. Name *string `json:"name,omitempty"` - // Override or not the target element if already set, + // Whether to override the target element if it's already set. OverrideOnConflict *bool `json:"override_on_conflict,omitempty"` // Remove or preserve the remapped source element. PreserveSource *bool `json:"preserve_source,omitempty"` diff --git a/api/datadogV1/model_logs_schema_remapper.go b/api/datadogV1/model_logs_schema_remapper.go index 42727e0d39e..0cc64e90f3f 100644 --- a/api/datadogV1/model_logs_schema_remapper.go +++ b/api/datadogV1/model_logs_schema_remapper.go @@ -14,7 +14,7 @@ import ( type LogsSchemaRemapper struct { // Name of the logs schema remapper. Name string `json:"name"` - // Override or not the target element if already set. + // Whether to override the target element if it's already set. OverrideOnConflict *bool `json:"override_on_conflict,omitempty"` // Remove or preserve the remapped source element. PreserveSource *bool `json:"preserve_source,omitempty"` diff --git a/examples/v1/logs-pipelines/CreateLogsPipeline_2595757342.go b/examples/v1/logs-pipelines/CreateLogsPipeline_2595757342.go new file mode 100644 index 00000000000..246e215feb1 --- /dev/null +++ b/examples/v1/logs-pipelines/CreateLogsPipeline_2595757342.go @@ -0,0 +1,51 @@ +// Create a pipeline with Array Processor Key Value Operation returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" +) + +func main() { + body := datadogV1.LogsPipeline{ + Filter: &datadogV1.LogsFilter{ + Query: datadog.PtrString("source:python"), + }, + Name: "testPipelineArrayKeyValue", + Processors: []datadogV1.LogsProcessor{ + datadogV1.LogsProcessor{ + LogsArrayProcessor: &datadogV1.LogsArrayProcessor{ + Type: datadogV1.LOGSARRAYPROCESSORTYPE_ARRAY_PROCESSOR, + IsEnabled: datadog.PtrBool(true), + Name: datadog.PtrString("extract_kv"), + Operation: datadogV1.LogsArrayProcessorOperation{ + LogsArrayProcessorOperationExtractKeyValue: &datadogV1.LogsArrayProcessorOperationExtractKeyValue{ + Type: datadogV1.LOGSARRAYPROCESSOROPERATIONEXTRACTKEYVALUETYPE_KEY_VALUE, + Source: "tags", + KeyToExtract: "name", + ValueToExtract: "value", + }}, + }}, + }, + Tags: []string{}, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV1.NewLogsPipelinesApi(apiClient) + resp, r, err := api.CreateLogsPipeline(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LogsPipelinesApi.CreateLogsPipeline`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `LogsPipelinesApi.CreateLogsPipeline`:\n%s\n", responseContent) +} diff --git a/examples/v1/logs-pipelines/CreateLogsPipeline_4041812833.go b/examples/v1/logs-pipelines/CreateLogsPipeline_4041812833.go new file mode 100644 index 00000000000..cca31b716a4 --- /dev/null +++ b/examples/v1/logs-pipelines/CreateLogsPipeline_4041812833.go @@ -0,0 +1,53 @@ +// Create a pipeline with Array Processor Key Value Operation with target and override_on_conflict returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" +) + +func main() { + body := datadogV1.LogsPipeline{ + Filter: &datadogV1.LogsFilter{ + Query: datadog.PtrString("source:python"), + }, + Name: "testPipelineArrayKeyValueTarget", + Processors: []datadogV1.LogsProcessor{ + datadogV1.LogsProcessor{ + LogsArrayProcessor: &datadogV1.LogsArrayProcessor{ + Type: datadogV1.LOGSARRAYPROCESSORTYPE_ARRAY_PROCESSOR, + IsEnabled: datadog.PtrBool(true), + Name: datadog.PtrString("extract_kv_to_target"), + Operation: datadogV1.LogsArrayProcessorOperation{ + LogsArrayProcessorOperationExtractKeyValue: &datadogV1.LogsArrayProcessorOperationExtractKeyValue{ + Type: datadogV1.LOGSARRAYPROCESSOROPERATIONEXTRACTKEYVALUETYPE_KEY_VALUE, + Source: "tags", + KeyToExtract: "name", + ValueToExtract: "value", + Target: datadog.PtrString("extracted"), + OverrideOnConflict: datadog.PtrBool(true), + }}, + }}, + }, + Tags: []string{}, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV1.NewLogsPipelinesApi(apiClient) + resp, r, err := api.CreateLogsPipeline(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LogsPipelinesApi.CreateLogsPipeline`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `LogsPipelinesApi.CreateLogsPipeline`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_returns_OK_response.freeze new file mode 100644 index 00000000000..79a90597f73 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_returns_OK_response.freeze @@ -0,0 +1 @@ +2026-07-22T18:27:14.576Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_returns_OK_response.yaml new file mode 100644 index 00000000000..b1ba8236e02 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_returns_OK_response.yaml @@ -0,0 +1,43 @@ +interactions: +- request: + body: | + {"filter":{"query":"source:python"},"name":"testPipelineArrayKeyValue","processors":[{"is_enabled":true,"name":"extract_kv","operation":{"key_to_extract":"name","source":"tags","type":"key-value","value_to_extract":"value"},"type":"array-processor"}],"tags":[]} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: POST + url: https://api.datadoghq.com/api/v1/logs/config/pipelines + response: + body: '{"id":"KLmRE95XSCKQcsktzgs9eQ","type":"pipeline","name":"testPipelineArrayKeyValue","is_enabled":false,"is_read_only":false,"filter":{"query":"source:python"},"processors":[{"name":"extract_kv","is_enabled":true,"operation":{"source":"tags","key_to_extract":"name","value_to_extract":"value","override_on_conflict":false,"type":"key-value"},"type":"array-processor"}],"tags":[]} + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - '*/*' + id: 1 + method: DELETE + url: https://api.datadoghq.com/api/v1/logs/config/pipelines/KLmRE95XSCKQcsktzgs9eQ + response: + body: '{} + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +version: 2 diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_with_target_and_override_on_conflict_returns_OK_response.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_with_target_and_override_on_conflict_returns_OK_response.freeze new file mode 100644 index 00000000000..fe1037276ab --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_with_target_and_override_on_conflict_returns_OK_response.freeze @@ -0,0 +1 @@ +2026-07-22T18:27:15.202Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_with_target_and_override_on_conflict_returns_OK_response.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_with_target_and_override_on_conflict_returns_OK_response.yaml new file mode 100644 index 00000000000..3b9d1464508 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Logs_Pipelines/Scenario_Create_a_pipeline_with_Array_Processor_Key_Value_Operation_with_target_and_override_on_conflict_returns_OK_response.yaml @@ -0,0 +1,43 @@ +interactions: +- request: + body: | + {"filter":{"query":"source:python"},"name":"testPipelineArrayKeyValueTarget","processors":[{"is_enabled":true,"name":"extract_kv_to_target","operation":{"key_to_extract":"name","override_on_conflict":true,"source":"tags","target":"extracted","type":"key-value","value_to_extract":"value"},"type":"array-processor"}],"tags":[]} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: POST + url: https://api.datadoghq.com/api/v1/logs/config/pipelines + response: + body: '{"id":"LsxyDpcbTL6KztluS2oBYA","type":"pipeline","name":"testPipelineArrayKeyValueTarget","is_enabled":false,"is_read_only":false,"filter":{"query":"source:python"},"processors":[{"name":"extract_kv_to_target","is_enabled":true,"operation":{"source":"tags","target":"extracted","key_to_extract":"name","value_to_extract":"value","override_on_conflict":true,"type":"key-value"},"type":"array-processor"}],"tags":[]} + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - '*/*' + id: 1 + method: DELETE + url: https://api.datadoghq.com/api/v1/logs/config/pipelines/LsxyDpcbTL6KztluS2oBYA + response: + body: '{} + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +version: 2 diff --git a/tests/scenarios/features/v1/logs_pipelines.feature b/tests/scenarios/features/v1/logs_pipelines.feature index ac28f052615..8b584949d9a 100644 --- a/tests/scenarios/features/v1/logs_pipelines.feature +++ b/tests/scenarios/features/v1/logs_pipelines.feature @@ -84,6 +84,20 @@ Feature: Logs Pipelines When the request is sent Then the response status is 200 OK + @team:DataDog/logs-onboarding + Scenario: Create a pipeline with Array Processor Key Value Operation returns "OK" response + Given new "CreateLogsPipeline" request + And body with value {"filter": {"query": "source:python"}, "name": "testPipelineArrayKeyValue", "processors": [{"type": "array-processor", "is_enabled": true, "name": "extract_kv", "operation": {"type": "key-value", "source": "tags", "key_to_extract": "name", "value_to_extract": "value"}}], "tags": []} + When the request is sent + Then the response status is 200 OK + + @team:DataDog/logs-onboarding + Scenario: Create a pipeline with Array Processor Key Value Operation with target and override_on_conflict returns "OK" response + Given new "CreateLogsPipeline" request + And body with value {"filter": {"query": "source:python"}, "name": "testPipelineArrayKeyValueTarget", "processors": [{"type": "array-processor", "is_enabled": true, "name": "extract_kv_to_target", "operation": {"type": "key-value", "source": "tags", "key_to_extract": "name", "value_to_extract": "value", "target": "extracted", "override_on_conflict": true}}], "tags": []} + When the request is sent + Then the response status is 200 OK + @team:DataDog/logs-onboarding Scenario: Create a pipeline with Array Processor Length Operation returns "OK" response Given new "CreateLogsPipeline" request