Skip to content

Commit

Permalink
Add json property descriptions to dissect, flatten, copy_value and tr…
Browse files Browse the repository at this point in the history
…anslate processor (opensearch-project#4760)

Signed-off-by: Hai Yan <[email protected]>
Signed-off-by: Krishna Kondaka <[email protected]>
  • Loading branch information
oeyh authored and Krishna Kondaka committed Aug 8, 2024
1 parent 69c839a commit 80315d3
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opensearch.dataprepper.plugins.processor.dissect;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import jakarta.validation.constraints.NotNull;
import org.opensearch.dataprepper.plugins.processor.mutateevent.TargetType;

Expand All @@ -9,10 +10,17 @@
public class DissectProcessorConfig {
@NotNull
@JsonProperty("map")
@JsonPropertyDescription("Defines the `dissect` patterns for specific keys. For details on how to define fields " +
"in the `dissect` pattern, see [Field notations](#field-notations).")
private Map<String, String> map;
@JsonProperty("target_types")
@JsonPropertyDescription("Specifies the data types for extract fields. Valid options are `integer`, " +
"`double`, `string`, and `boolean`. By default, all fields are of the `string` type.")
private Map<String, TargetType> targetTypes;
@JsonProperty("dissect_when")
@JsonPropertyDescription("Specifies a condition for performing the `dissect` operation using a " +
"[Data Prepper expression]({{site.url}}{{site.baseurl}}/data-prepper/pipelines/expression-syntax/). " +
"If specified, the `dissect` operation will only run when the expression evaluates to true.")
private String dissectWhen;

public String getDissectWhen(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotNull;

Expand All @@ -19,28 +20,43 @@ public class FlattenProcessorConfig {

@NotNull
@JsonProperty("source")
@JsonPropertyDescription("The source key on which to perform the operation. If set to an empty string (`\"\"`), " +
"then the processor uses the root of the event as the source.")
private String source;

@NotNull
@JsonProperty("target")
@JsonPropertyDescription("The target key to put into the flattened fields. If set to an empty string (`\"\"`), " +
"then the processor uses the root of the event as the target.")
private String target;

@JsonProperty("remove_processed_fields")
@JsonPropertyDescription("When `true`, the processor removes all processed fields from the source. Default is `false`.")
private boolean removeProcessedFields = false;

@JsonProperty("remove_list_indices")
@JsonPropertyDescription("When `true`, the processor converts the fields from the source map into lists and " +
"puts the lists into the target field. Default is `false`.")
private boolean removeListIndices = false;

@JsonProperty("remove_brackets")
@JsonPropertyDescription("When `true`, the processor also removes brackets around the indices. Can only be " +
"set to `true` when `remove_list_indices` is `true`.")
private boolean removeBrackets = false;

@JsonProperty("exclude_keys")
@JsonPropertyDescription("The keys from the source field that should be excluded from processing. " +
"Default is an empty list (`[]`).")
private List<String> excludeKeys = DEFAULT_EXCLUDE_KEYS;

@JsonProperty("flatten_when")
@JsonPropertyDescription("A [conditional expression](https://opensearch.org/docs/latest/data-prepper/pipelines/expression-syntax/), " +
"such as `/some-key == \"test\"'`, that determines whether the `flatten` processor will be run on the " +
"event. Default is `null`, which means that all events will be processed unless otherwise stated.")
private String flattenWhen;

@JsonProperty("tags_on_failure")
@JsonPropertyDescription("A list of tags to add to the event metadata when the event fails to process.")
private List<String> tagsOnFailure;

public String getSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.opensearch.dataprepper.plugins.processor.mutateevent;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotEmpty;
Expand All @@ -18,17 +19,23 @@ public static class Entry {
@NotEmpty
@NotNull
@JsonProperty("from_key")
@JsonPropertyDescription("The key of the entry to be copied.")
private String fromKey;

@NotEmpty
@NotNull
@JsonProperty("to_key")
@JsonPropertyDescription("The key of the new entry to be added.")
private String toKey;

@JsonProperty("copy_when")
@JsonPropertyDescription("A [conditional expression](https://opensearch.org/docs/latest/data-prepper/pipelines/expression-syntax/), " +
"such as `/some-key == \"test\"'`, that will be evaluated to determine whether the processor will be run on the event.")
private String copyWhen;

@JsonProperty("overwrite_if_to_key_exists")
@JsonPropertyDescription("When set to `true`, the existing value is overwritten if `key` already exists in " +
"the event. The default value is `false`.")
private boolean overwriteIfToKeyExists = false;

public String getFromKey() {
Expand Down Expand Up @@ -60,15 +67,19 @@ public Entry() {
@NotEmpty
@NotNull
@Valid
@JsonPropertyDescription("A list of entries to be copied in an event.")
private List<Entry> entries;

@JsonProperty("from_list")
@JsonPropertyDescription("The source list to copy values from.")
private String fromList;

@JsonProperty("to_list")
@JsonPropertyDescription("The target list to copy values to.")
private String toList;

@JsonProperty("overwrite_if_to_list_exists")
@JsonPropertyDescription("When set to `true`, the existing value is overwritten if `key` already exists in the event. The default value is `false`.")
private boolean overwriteIfToListExists = false;

@AssertTrue(message = "Both from_list and to_list should be specified when copying entries between lists.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
package org.opensearch.dataprepper.plugins.processor.translate;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.List;

public class FileParameterConfig {

@JsonProperty("name")
@JsonPropertyDescription("The full path to a local file or key name for an S3 object.")
@NotNull
private String fileName;

@JsonProperty("aws")
@JsonPropertyDescription("The AWS configuration when the file is an S3 object. ")
@Valid
private S3ObjectConfig awsConfig;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opensearch.dataprepper.plugins.processor.translate;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotNull;
Expand All @@ -12,10 +13,12 @@
public class MappingsParameterConfig {

@JsonProperty("source")
@JsonPropertyDescription("The source field to translate. Can be a string or a list of strings.")
@NotNull
private Object source;

@JsonProperty("targets")
@JsonPropertyDescription("A list of target field configurations, such as the target field key or translation maps.")
@Valid
private List<TargetsParameterConfig> targetsParameterConfigs = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
package org.opensearch.dataprepper.plugins.processor.translate;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import jakarta.validation.constraints.NotNull;

public class S3ObjectConfig {

@JsonProperty("bucket")
@JsonPropertyDescription("The Amazon S3 bucket name.")
@NotNull
private String bucket;

@JsonProperty("region")
@JsonPropertyDescription("The AWS Region to use for credentials.")
@NotNull
private String region;

@JsonProperty("sts_role_arn")
@JsonPropertyDescription("The AWS Security Token Service (AWS STS) role to assume for requests to Amazon S3.")
@NotNull
private String stsRoleArn;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opensearch.dataprepper.plugins.processor.translate;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
Expand All @@ -22,18 +23,28 @@ public class TargetsParameterConfig {
private final Map<String, Object> individualMappings = new HashMap<>();
private final Map<Pattern, Object> compiledPatterns = new HashMap<>();
@JsonProperty("target")
@JsonPropertyDescription("The key that specifies the field in the output in which the translated value will be placed.")
@NotNull
@NotEmpty
private String target;
@JsonProperty("map")
@JsonPropertyDescription("A list of key-value pairs that define the translations. Each key represents a possible " +
"value in the source field, and the corresponding value represents what it should be translated to. " +
"For examples, see [map option](#map-option). At least one of `map` and `regex` should be configured.")
private Map<String, Object> map;
@JsonProperty("translate_when")
@JsonPropertyDescription("Uses a [Data Prepper expression]({{site.url}}{{site.baseurl}}/data-prepper/pipelines/expression-syntax/) " +
"to specify a condition for performing the translation. When specified, the expression will only translate when the condition is met.")
private String translateWhen;
@JsonProperty("regex")
@JsonPropertyDescription("A map of keys that defines the translation map. For more options, see [regex option](#regex-option). " +
"At least one of `map` and `regex` should be configured.")
private RegexParameterConfiguration regexParameterConfig;
@JsonProperty("default")
@JsonPropertyDescription("The default value to use when no match is found during translation.")
private String defaultValue;
@JsonProperty("type")
@JsonPropertyDescription("Specifies the data type for the target value.")
private TargetType targetType = TargetType.STRING;

public TargetsParameterConfig(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertTrue;

Expand All @@ -19,10 +20,12 @@
public class TranslateProcessorConfig {

@JsonProperty("file")
@JsonPropertyDescription("Points to the file that contains mapping configurations. For more information, see [file](#file).")
@Valid
private FileParameterConfig fileParameterConfig;

@JsonProperty("mappings")
@JsonPropertyDescription("Defines inline mappings. For more information, see [mappings](#mappings).")
@Valid
private List<MappingsParameterConfig> mappingsParameterConfigs = new ArrayList<>();

Expand Down

0 comments on commit 80315d3

Please sign in to comment.