-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add append option to add_entries processor #4143
Conversation
Signed-off-by: Hai Yan <[email protected]>
Would it make sense to instead have something like this
Not a blocking comment just something to consider |
@graytaylor0 I like it, making the config more concise. I can do the change if other reviewers think the same. |
public String getAddWhen() { return addWhen; } | ||
|
||
@AssertTrue(message = "Either value or format or expression must be specified, and only one of them can be specified") | ||
public boolean hasValueOrFormatOrExpression() { | ||
return Stream.of(value, format, valueExpression).filter(n -> n!=null).count() == 1; | ||
} | ||
|
||
@AssertTrue(message = "overwrite_if_key_exists and append_if_key_exists can not be set at the same time.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overwrite_if_key_exists and append_if_key_exists can not be set at the same time.
Please change to:
overwrite_if_key_exists and append_if_key_exists can not be set to true at the same time.
They can be "set" together.
@@ -97,4 +101,30 @@ public boolean isReadyForShutdown() { | |||
@Override | |||
public void shutdown() { | |||
} | |||
|
|||
private void mergeValueToEvent(final Event recordEvent, final String key, final Object value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider combining these with the use of Java 8 lambdas.
Here is some starting point for one way to do it.
private void mergeValueToEvent(final Event recordEvent, final String key, final Object value)
mergeValue(recordEvent, () -> recordEvent.getMetadata().getAttribute(key), newValue -> recordEvent.put(key, newValue);
}
mergeValue(Supplier<Object> getter, Consumer<Object> setter) {
final Object currentValue = getter.get();
final List<Object> mergedValue = new ArrayList<>();
if (currentValue instanceof List) {
mergedValue.addAll((List<Object>) currentValue);
} else {
mergedValue.add(currentValue);
}
mergedValue.add(value);
setter.accept(mergedValue);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion!
@graytaylor0 , I like this idea. But, I also think we should aim for consistency. Right now grok has |
Signed-off-by: Hai Yan <[email protected]>
Signed-off-by: Hai Yan <[email protected]>
These processors have similar
grok processor has a I will open a follow-up issue for these and we can discuss further there. |
Description
Adds an
append_if_key_exists
option toadd_entries
processor as described in #4129Issues Resolved
Resolves #4129
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.