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
53 changes: 53 additions & 0 deletions examples/v1/logs-pipelines/CreateLogsPipeline_2595757342.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Create a pipeline with Array Processor Key Value Operation returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.LogsPipelinesApi;
import com.datadog.api.client.v1.model.LogsArrayProcessor;
import com.datadog.api.client.v1.model.LogsArrayProcessorOperation;
import com.datadog.api.client.v1.model.LogsArrayProcessorOperationExtractKeyValue;
import com.datadog.api.client.v1.model.LogsArrayProcessorOperationExtractKeyValueType;
import com.datadog.api.client.v1.model.LogsArrayProcessorType;
import com.datadog.api.client.v1.model.LogsFilter;
import com.datadog.api.client.v1.model.LogsPipeline;
import com.datadog.api.client.v1.model.LogsProcessor;
import java.util.Collections;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
LogsPipelinesApi apiInstance = new LogsPipelinesApi(defaultClient);

LogsPipeline body =
new LogsPipeline()
.filter(new LogsFilter().query("source:python"))
.name("testPipelineArrayKeyValue")
.processors(
Collections.singletonList(
new LogsProcessor(
new LogsArrayProcessor()
.type(LogsArrayProcessorType.ARRAY_PROCESSOR)
.isEnabled(true)
.name("extract_kv")
.operation(
new LogsArrayProcessorOperation(
new LogsArrayProcessorOperationExtractKeyValue()
.type(
LogsArrayProcessorOperationExtractKeyValueType
.KEY_VALUE)
.source("tags")
.keyToExtract("name")
.valueToExtract("value"))))));

try {
LogsPipeline result = apiInstance.createLogsPipeline(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LogsPipelinesApi#createLogsPipeline");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
56 changes: 56 additions & 0 deletions examples/v1/logs-pipelines/CreateLogsPipeline_4041812833.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Create a pipeline with Array Processor Key Value Operation with target and override_on_conflict
// returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.LogsPipelinesApi;
import com.datadog.api.client.v1.model.LogsArrayProcessor;
import com.datadog.api.client.v1.model.LogsArrayProcessorOperation;
import com.datadog.api.client.v1.model.LogsArrayProcessorOperationExtractKeyValue;
import com.datadog.api.client.v1.model.LogsArrayProcessorOperationExtractKeyValueType;
import com.datadog.api.client.v1.model.LogsArrayProcessorType;
import com.datadog.api.client.v1.model.LogsFilter;
import com.datadog.api.client.v1.model.LogsPipeline;
import com.datadog.api.client.v1.model.LogsProcessor;
import java.util.Collections;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
LogsPipelinesApi apiInstance = new LogsPipelinesApi(defaultClient);

LogsPipeline body =
new LogsPipeline()
.filter(new LogsFilter().query("source:python"))
.name("testPipelineArrayKeyValueTarget")
.processors(
Collections.singletonList(
new LogsProcessor(
new LogsArrayProcessor()
.type(LogsArrayProcessorType.ARRAY_PROCESSOR)
.isEnabled(true)
.name("extract_kv_to_target")
.operation(
new LogsArrayProcessorOperation(
new LogsArrayProcessorOperationExtractKeyValue()
.type(
LogsArrayProcessorOperationExtractKeyValueType
.KEY_VALUE)
.source("tags")
.keyToExtract("name")
.valueToExtract("value")
.target("extracted")
.overrideOnConflict(true))))));

try {
LogsPipeline result = apiInstance.createLogsPipeline(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling LogsPipelinesApi#createLogsPipeline");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* A processor for extracting, aggregating, or transforming values from JSON arrays within your
* logs. Supported operations are: - Select value from matching element - Compute array length -
* Append a value to an array
* Append a value to an array - Extract key-value pairs from an array
*/
@JsonPropertyOrder({
LogsArrayProcessor.JSON_PROPERTY_IS_ENABLED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,58 @@ public LogsArrayProcessorOperation deserialize(JsonParser jp, DeserializationCon
Level.FINER, "Input data does not match schema 'LogsArrayProcessorOperationSelect'", e);
}

// deserialize LogsArrayProcessorOperationExtractKeyValue
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
if (LogsArrayProcessorOperationExtractKeyValue.class.equals(Integer.class)
|| LogsArrayProcessorOperationExtractKeyValue.class.equals(Long.class)
|| LogsArrayProcessorOperationExtractKeyValue.class.equals(Float.class)
|| LogsArrayProcessorOperationExtractKeyValue.class.equals(Double.class)
|| LogsArrayProcessorOperationExtractKeyValue.class.equals(Boolean.class)
|| LogsArrayProcessorOperationExtractKeyValue.class.equals(String.class)) {
attemptParsing = typeCoercion;
if (!attemptParsing) {
attemptParsing |=
((LogsArrayProcessorOperationExtractKeyValue.class.equals(Integer.class)
|| LogsArrayProcessorOperationExtractKeyValue.class.equals(Long.class))
&& token == JsonToken.VALUE_NUMBER_INT);
attemptParsing |=
((LogsArrayProcessorOperationExtractKeyValue.class.equals(Float.class)
|| LogsArrayProcessorOperationExtractKeyValue.class.equals(Double.class))
&& (token == JsonToken.VALUE_NUMBER_FLOAT
|| token == JsonToken.VALUE_NUMBER_INT));
attemptParsing |=
(LogsArrayProcessorOperationExtractKeyValue.class.equals(Boolean.class)
&& (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
attemptParsing |=
(LogsArrayProcessorOperationExtractKeyValue.class.equals(String.class)
&& token == JsonToken.VALUE_STRING);
}
}
if (attemptParsing) {
tmp =
tree.traverse(jp.getCodec())
.readValueAs(LogsArrayProcessorOperationExtractKeyValue.class);
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
if (!((LogsArrayProcessorOperationExtractKeyValue) tmp).unparsed) {
deserialized = tmp;
match++;
}
log.log(
Level.FINER,
"Input data matches schema 'LogsArrayProcessorOperationExtractKeyValue'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(
Level.FINER,
"Input data does not match schema 'LogsArrayProcessorOperationExtractKeyValue'",
e);
}

LogsArrayProcessorOperation ret = new LogsArrayProcessorOperation();
if (match == 1) {
ret.setActualInstance(deserialized);
Expand Down Expand Up @@ -263,6 +315,11 @@ public LogsArrayProcessorOperation(LogsArrayProcessorOperationSelect o) {
setActualInstance(o);
}

public LogsArrayProcessorOperation(LogsArrayProcessorOperationExtractKeyValue o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}

static {
schemas.put(
"LogsArrayProcessorOperationAppend",
Expand All @@ -273,6 +330,9 @@ public LogsArrayProcessorOperation(LogsArrayProcessorOperationSelect o) {
schemas.put(
"LogsArrayProcessorOperationSelect",
new GenericType<LogsArrayProcessorOperationSelect>() {});
schemas.put(
"LogsArrayProcessorOperationExtractKeyValue",
new GenericType<LogsArrayProcessorOperationExtractKeyValue>() {});
JSON.registerDescendants(
LogsArrayProcessorOperation.class, Collections.unmodifiableMap(schemas));
}
Expand All @@ -285,7 +345,8 @@ public Map<String, GenericType> getSchemas() {
/**
* Set the instance that matches the oneOf child schema, check the instance parameter is valid
* against the oneOf child schemas: LogsArrayProcessorOperationAppend,
* LogsArrayProcessorOperationLength, LogsArrayProcessorOperationSelect
* LogsArrayProcessorOperationLength, LogsArrayProcessorOperationSelect,
* LogsArrayProcessorOperationExtractKeyValue
*
* <p>It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a
* composed schema (allOf, anyOf, oneOf).
Expand All @@ -307,22 +368,30 @@ public void setActualInstance(Object instance) {
super.setActualInstance(instance);
return;
}
if (JSON.isInstanceOf(
LogsArrayProcessorOperationExtractKeyValue.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}

if (JSON.isInstanceOf(UnparsedObject.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}
throw new RuntimeException(
"Invalid instance type. Must be LogsArrayProcessorOperationAppend,"
+ " LogsArrayProcessorOperationLength, LogsArrayProcessorOperationSelect");
+ " LogsArrayProcessorOperationLength, LogsArrayProcessorOperationSelect,"
+ " LogsArrayProcessorOperationExtractKeyValue");
}

/**
* Get the actual instance, which can be the following: LogsArrayProcessorOperationAppend,
* LogsArrayProcessorOperationLength, LogsArrayProcessorOperationSelect
* LogsArrayProcessorOperationLength, LogsArrayProcessorOperationSelect,
* LogsArrayProcessorOperationExtractKeyValue
*
* @return The actual instance (LogsArrayProcessorOperationAppend,
* LogsArrayProcessorOperationLength, LogsArrayProcessorOperationSelect)
* LogsArrayProcessorOperationLength, LogsArrayProcessorOperationSelect,
* LogsArrayProcessorOperationExtractKeyValue)
*/
@Override
public Object getActualInstance() {
Expand Down Expand Up @@ -364,4 +433,16 @@ public LogsArrayProcessorOperationSelect getLogsArrayProcessorOperationSelect()
throws ClassCastException {
return (LogsArrayProcessorOperationSelect) super.getActualInstance();
}

/**
* Get the actual instance of `LogsArrayProcessorOperationExtractKeyValue`. If the actual instance
* is not `LogsArrayProcessorOperationExtractKeyValue`, the ClassCastException will be thrown.
*
* @return The actual instance of `LogsArrayProcessorOperationExtractKeyValue`
* @throws ClassCastException if the instance is not `LogsArrayProcessorOperationExtractKeyValue`
*/
public LogsArrayProcessorOperationExtractKeyValue getLogsArrayProcessorOperationExtractKeyValue()
throws ClassCastException {
return (LogsArrayProcessorOperationExtractKeyValue) super.getActualInstance();
}
}
Loading
Loading