Add support for including keys based on regex patterns for select entries processor#6094
Conversation
90d544d to
2d9d564
Compare
|
|
||
| // The processor is implemented to support this, but can be made configurable when there is a feature request | ||
| @JsonIgnore | ||
| private String includeKeysRegexPointer; |
There was a problem hiding this comment.
Should this be implemented to default to / instead of having logic with null?
There was a problem hiding this comment.
Currently that does break the tests because this returns false
if (includeKeysRegexPointer != null) {
if (!event.containsKey(includeKeysRegexPointer)) {
return Collections.emptyMap();
}
I can change it to this if you think it's preferred as a default
if (includeKeysRegexPointer != null && !includeKeysRegexPointer.equals("/")) {
if (!event.containsKey(includeKeysRegexPointer)) {
return Collections.emptyMap();
}
| boolean isValidIncludeKeysRegex() { | ||
| if (includeKeysRegex != null && !includeKeysRegex.isEmpty()) { | ||
| try { | ||
| includeKeysRegexPatterns = includeKeysRegex.stream().map(Pattern::compile).collect(Collectors.toList()); |
There was a problem hiding this comment.
Doing validation and setting in one method is not an ideal method structure. It would be better to implement the setter for includeKeysRegex and not even have a field for this.
I believe this would work:
@JsonProperty("include_keys_regex")
@JsonPropertyDescription("A list of regex patterns to match keys be selected from an event.")
private List<String> setIncludeKeysRegex() {
includeKeysRegexPatterns = includeKeysRegex.stream().map(Pattern::compile).collect(Collectors.toList());
}
There was a problem hiding this comment.
Maybe for a future PR - we could update the parser framework to support reading Pattern natively, similar to how we read Java Duration. We are doing this in a lot of plugins now and it would be nice to just have a single:
@JsonProperty("include_keys_regex")
@JsonPropertyDescription("A list of regex patterns to match keys be selected from an event.")
private List<Pattern> includeKeysRegex
There was a problem hiding this comment.
I tried this and it did not get run so it never got set.
I do think having the parser framework handle Pattern is ideal here, but for now this has been the best way to provide a clear error message to customers (you could call it in the constructor but that would mean the error would not be found until the config validations pass.
There was a problem hiding this comment.
I could run the validation in the method and then initialize the patterns in the constructor with a setter if that is preferred. It compiles the patterns twice but that shouldn't matter
There was a problem hiding this comment.
I tried this and it did not get run so it never got set.
Maybe Jackson is bypassing the setter in favor of using the private fields always.
I could run the validation in the method and then initialize the patterns in the constructor with a setter if that is preferred. It compiles the patterns twice but that shouldn't matter
Maybe have the validator call the setter method for clarity?
There was a problem hiding this comment.
I'll make that change
| if (value != null) { | ||
| outMap.put(keyToInclude, value); | ||
| if (keysToInclude != null) { | ||
| for (String keyToInclude: keysToInclude) { |
There was a problem hiding this comment.
This code would be clearer if both took the same approach of having its own private method.
Also, you could use a single Map and pass it as an argument to the private methods.
There was a problem hiding this comment.
I will move it into a private method, but I think it may be easier to read when map is returned from these methods rather than manipulating the final output map from within the method.
There was a problem hiding this comment.
That is fine as well. Create two maps and combine them.
…ries processor Signed-off-by: Taylor Gray <tylgry@amazon.com>
Signed-off-by: Taylor Gray <tylgry@amazon.com>
2d9d564 to
e8d2e97
Compare
Description
This change adds new configuration parameters to the select entries processor
include_keys_regex-> A list of regex patterns to filter out keys to include from the event. Can be used alongsideinclude_keys, and by default will only check keys at the root of the eventNOTE: This is not made configurable at this time but it is implemented for within the processor and tested
include_keys_regex_pointer-> A key pointing to a nested map that will lead to keys being included only from within this poointer. This will result in all other keys to be deleted if they are not in theinclude_keys_regex_pointeror in theinclude_keys.include_keyswas previously required in this processor, and now at least one ofinclude_keysorinclude_keys_regexis required.Issues Resolved
Related to #6087
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.