From a502bcb84f6339e715b19524b6ad7f3e2abac556 Mon Sep 17 00:00:00 2001 From: Hai Yan <8153134+oeyh@users.noreply.github.com> Date: Mon, 29 Jul 2024 11:32:31 -0500 Subject: [PATCH] Add json property description for list-to-map, map-to-list and user-agent processor (#4759) Signed-off-by: Hai Yan Signed-off-by: Krishna Kondaka --- .../mutateevent/ListToMapProcessorConfig.java | 21 +++++++++++++++++++ .../mutateevent/MapToListProcessorConfig.java | 16 ++++++++++++++ .../useragent/UserAgentProcessorConfig.java | 6 ++++++ 3 files changed, 43 insertions(+) diff --git a/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/ListToMapProcessorConfig.java b/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/ListToMapProcessorConfig.java index 228f07f08e..b63deb727c 100644 --- a/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/ListToMapProcessorConfig.java +++ b/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/ListToMapProcessorConfig.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -41,35 +42,55 @@ static FlattenedElement fromOptionValue(final String option) { @NotEmpty @NotNull @JsonProperty("source") + @JsonPropertyDescription("The list of objects with `key` fields to be converted into keys for the generated map.") private String source; @JsonProperty("target") + @JsonPropertyDescription("The target for the generated map. When not specified, the generated map will be " + + "placed in the root node.") private String target = null; @JsonProperty("key") + @JsonPropertyDescription("The key of the fields to be extracted as keys in the generated mappings. Must be " + + "specified if `use_source_key` is `false`.") private String key; @JsonProperty("value_key") + @JsonPropertyDescription("When specified, values given a `value_key` in objects contained in the source list " + + "will be extracted and converted into the value specified by this option based on the generated map. " + + "When not specified, objects contained in the source list retain their original value when mapped.") private String valueKey = null; @JsonProperty("use_source_key") + @JsonPropertyDescription("When `true`, keys in the generated map will use original keys from the source. " + + "Default is `false`.") private boolean useSourceKey = false; @JsonProperty("extract_value") + @JsonPropertyDescription("When `true`, object values from the source list will be extracted and added to " + + "the generated map. When `false`, object values from the source list are added to the generated map " + + "as they appear in the source list. Default is `false`") private boolean extractValue = false; @NotNull @JsonProperty("flatten") + @JsonPropertyDescription("When `true`, values in the generated map output flatten into single items based on " + + "the `flattened_element`. Otherwise, objects mapped to values from the generated map appear as lists.") private boolean flatten = false; @NotNull @JsonProperty("flattened_element") + @JsonPropertyDescription("The element to keep, either `first` or `last`, when `flatten` is set to `true`.") private FlattenedElement flattenedElement = FlattenedElement.FIRST; @JsonProperty("list_to_map_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. Default is `null`. All events will be processed unless otherwise stated.") private String listToMapWhen; @JsonProperty("tags_on_failure") + @JsonPropertyDescription("A list of tags to add to the event metadata when the event fails to process.") private List tagsOnFailure; public String getSource() { diff --git a/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/MapToListProcessorConfig.java b/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/MapToListProcessorConfig.java index 46a2ec79f0..ce317eca49 100644 --- a/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/MapToListProcessorConfig.java +++ b/data-prepper-plugins/mutate-event-processors/src/main/java/org/opensearch/dataprepper/plugins/processor/mutateevent/MapToListProcessorConfig.java @@ -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.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -20,32 +21,47 @@ public class MapToListProcessorConfig { @NotNull @JsonProperty("source") + @JsonPropertyDescription("The source map used to perform the mapping operation. When set to an empty " + + "string (`\"\"`), it will use the root of the event as the `source`.") private String source; @NotEmpty @NotNull @JsonProperty("target") + @JsonPropertyDescription("The target for the generated list.") private String target; @JsonProperty("key_name") + @JsonPropertyDescription("The name of the field in which to store the original key. Default is `key`.") private String keyName = DEFAULT_KEY_NAME; @JsonProperty("value_name") + @JsonPropertyDescription("The name of the field in which to store the original value. Default is `value`.") private String valueName = DEFAULT_VALUE_NAME; @JsonProperty("map_to_list_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. Default is `null`. All events will be processed unless otherwise stated.") private String mapToListWhen; @JsonProperty("exclude_keys") + @JsonPropertyDescription("The keys in the source map that will be excluded from processing. Default is an " + + "empty list (`[]`).") private List excludeKeys = DEFAULT_EXCLUDE_KEYS; @JsonProperty("remove_processed_fields") + @JsonPropertyDescription("When `true`, the processor will remove the processed fields from the source map. " + + "Default is `false`.") private boolean removeProcessedFields = DEFAULT_REMOVE_PROCESSED_FIELDS; @JsonProperty("convert_field_to_list") + @JsonPropertyDescription("If `true`, the processor will convert the fields from the source map into lists and " + + "place them in fields in the target list. Default is `false`.") private boolean convertFieldToList = false; @JsonProperty("tags_on_failure") + @JsonPropertyDescription("A list of tags to add to the event metadata when the event fails to process.") private List tagsOnFailure; public String getSource() { diff --git a/data-prepper-plugins/user-agent-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/useragent/UserAgentProcessorConfig.java b/data-prepper-plugins/user-agent-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/useragent/UserAgentProcessorConfig.java index 0dcf46e2a1..b1660b37d0 100644 --- a/data-prepper-plugins/user-agent-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/useragent/UserAgentProcessorConfig.java +++ b/data-prepper-plugins/user-agent-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/useragent/UserAgentProcessorConfig.java @@ -6,6 +6,7 @@ package org.opensearch.dataprepper.plugins.processor.useragent; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import org.opensearch.dataprepper.model.event.EventKey; @@ -21,21 +22,26 @@ public class UserAgentProcessorConfig { @NotEmpty @NotNull @JsonProperty("source") + @JsonPropertyDescription("The field in the event that will be parsed.") @EventKeyConfiguration(EventKeyFactory.EventAction.GET) private EventKey source; @NotNull @JsonProperty("target") + @JsonPropertyDescription("The field to which the parsed event will write. Default is `user_agent`.") private String target = "user_agent"; @NotNull @JsonProperty("exclude_original") + @JsonPropertyDescription("Determines whether to exclude the original UA string from the parsing result. Defaults to `false`. ") private boolean excludeOriginal = false; @JsonProperty("cache_size") + @JsonPropertyDescription("The cache size of the parser in megabytes. Defaults to `1000`.") private int cacheSize = DEFAULT_CACHE_SIZE; @JsonProperty("tags_on_parse_failure") + @JsonPropertyDescription("The tag to add to an event if the `user_agent` processor fails to parse the UA string.") private List tagsOnParseFailure; public EventKey getSource() {