Skip to content

Commit

Permalink
Dynamic renaming of keys bug fix (#5180)
Browse files Browse the repository at this point in the history
Signed-off-by: Divyansh Bokadia <dbokadia@amazon.com>

Dynamic renaming of keys bug fix

Co-authored-by: Divyansh Bokadia <dbokadia@amazon.com>
  • Loading branch information
divbok and Divyansh Bokadia authored Nov 9, 2024
1 parent 347a803 commit f99a08f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public RenameKeyProcessor(final PluginMetrics pluginMetrics, final RenameKeyProc
entry.getRenameWhen()));
}
if (entry.getFromKey() == null && entry.getFromKeyPattern() == null) {
throw new InvalidPluginConfigurationException("Either from_key or from_key_pattern must be specified. Both cannot be set together.");
throw new InvalidPluginConfigurationException("Either from_key or from_key_regex must be specified. ");
}
if (entry.getFromKey() != null && entry.getFromKeyPattern() != null) {
throw new InvalidPluginConfigurationException("Only one of from_key or from_key_pattern should be specified.");
throw new InvalidPluginConfigurationException("Only one of from_key or from_key_regex should be specified.");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.opensearch.dataprepper.model.annotations.AlsoRequired;
import org.opensearch.dataprepper.model.annotations.ExampleValues;
import org.opensearch.dataprepper.model.annotations.ExampleValues.Example;
import org.opensearch.dataprepper.model.event.EventKey;
Expand All @@ -27,13 +28,24 @@
public class RenameKeyProcessorConfig {
@JsonPropertyOrder
public static class Entry {
@JsonProperty("from_key")
@JsonPropertyDescription("The key of the entry to be renamed.")
static final String FROM_KEY = "from_key";
static final String FROM_KEY_REGEX = "from_key_regex";
@JsonProperty(defaultValue = FROM_KEY)
@JsonPropertyDescription("The key of the entry to be renamed. " +
"This field cannot be defined along with <code>from_key_regex</code>.")
@AlsoRequired(values = {
@AlsoRequired.Required(name = FROM_KEY_REGEX, allowedValues = {"null"})
})
@EventKeyConfiguration({EventKeyFactory.EventAction.GET, EventKeyFactory.EventAction.DELETE})
private EventKey fromKey;

@JsonProperty("from_key_regex")
@JsonPropertyDescription("The regex pattern of the key of the entry to be renamed.")

@JsonProperty(defaultValue = FROM_KEY_REGEX)
@JsonPropertyDescription("The regex pattern of the key of the entry to be renamed. " +
"This field cannot be defined along with <code>from_key</code>.")
@AlsoRequired(values = {
@AlsoRequired.Required(name = FROM_KEY, allowedValues = {"null"})
})
private String fromKeyRegex;

@NotEmpty
Expand Down

0 comments on commit f99a08f

Please sign in to comment.