Skip to content

Commit

Permalink
Update when condition parameter name
Browse files Browse the repository at this point in the history
Signed-off-by: Dinu John <[email protected]>
  • Loading branch information
dinujoh committed Sep 17, 2024
1 parent ac93eff commit 5eca880
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion data-prepper-plugins/mutate-string-processors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ If `from` substring does not have a match, the key will be returned as it is.
### Configuration
* `entries` - (required) - A list of entries to add to an event
* `source` - (required) - The key to be modified
* `from` - (required) - The substring to be replaced. This cannot be regex.
* `from` - (required) - The substring to be replaced. This doesn't support regex.
* `to` - (required) - The String to be substituted for each match of `from`

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ public ReplaceStringProcessor(final PluginMetrics pluginMetrics, final ReplaceSt
this.expressionEvaluator = expressionEvaluator;

for(final ReplaceStringProcessorConfig.Entry entry : config.getEntries()) {
if (entry.getSubstituteWhen() != null
&& !expressionEvaluator.isValidExpressionStatement(entry.getSubstituteWhen())) {
if (entry.getReplaceWhen() != null
&& !expressionEvaluator.isValidExpressionStatement(entry.getReplaceWhen())) {
throw new InvalidPluginConfigurationException(
String.format("substitute_when %s is not a valid expression statement. See https://opensearch.org/docs/latest/data-prepper/pipelines/expression-syntax/ for valid expression syntax", entry.getSubstituteWhen()));
String.format("substitute_when %s is not a valid expression statement. See https://opensearch.org/docs/latest/data-prepper/pipelines/expression-syntax/ for valid expression syntax", entry.getReplaceWhen()));
}
}
}

@Override
protected void performKeyAction(final Event recordEvent, final ReplaceStringProcessorConfig.Entry entry, final String value)
{
if (Objects.nonNull(entry.getSubstituteWhen()) && !expressionEvaluator.evaluateConditional(entry.getSubstituteWhen(), recordEvent)) {
if (Objects.nonNull(entry.getReplaceWhen()) && !expressionEvaluator.evaluateConditional(entry.getReplaceWhen(), recordEvent)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public static class Entry {
private EventKey source;
@JsonPropertyDescription("The substring to be replaced in the source.")
private String from;
@JsonPropertyDescription("The string to be substituted for each match of `from`.")
@JsonPropertyDescription("The string to be replaced for each match of `from`.")
private String to;

@JsonProperty("substitute_when")
@JsonProperty("replace_when")
@JsonPropertyDescription("A Data Prepper [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 substituteWhen;
private String replaceWhen;

public EventKey getSource() {
return source;
Expand All @@ -43,13 +43,13 @@ public String getTo() {
return to;
}

public String getSubstituteWhen() { return substituteWhen; }
public String getReplaceWhen() { return replaceWhen; }

public Entry(final EventKey source, final String from, final String to, final String substituteWhen) {
public Entry(final EventKey source, final String from, final String to, final String replaceWhen) {
this.source = source;
this.from = from;
this.to = to;
this.substituteWhen = substituteWhen;
this.replaceWhen = replaceWhen;
}

public Entry() {}
Expand Down

0 comments on commit 5eca880

Please sign in to comment.