Repository navigation
Backport(v1.19): record_accessor: return nil when a parent of a nested key is not a hash (#5657) - #5703
Merged
Conversation
…sh (#5657) A record accessor for a nested key, such as `$.log.level`, used Hash#dig, which raises TypeError when a value on the way is not a hash, for example a string or a number. Unlike delete_nest and set_nest, call_dig did not handle that error. As a result, filter_grep logged "failed to grep events" with a backtrace for every such record and let the record through, even when it did not match the <regexp> condition. Return nil instead, the same as when the key does not exist. Other users of a nested record accessor, such as a nested buffer chunk key, also handle such a record as one without the key. Fixes #5656 Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com> Co-authored-by: Shizuo Fujita <fujita@clear-code.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Watson1978
approved these changes
Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) this PR fixes:
Backport #5657
Fixes #5656
What this PR does / why we need it:
A record accessor for a nested key (for example
$.log.level) usesHash#dig. When a value on the way to the key is not a hash or an array, for example a string or a number,digraisesTypeError.delete_nestandset_nestalready rescue this error and do nothing, butcall_digdid not.The visible effect is in
filter_grep. For<regexp> key $.log.level pattern /error/ </regexp>, a record such as{"log":"plain text line"}madefilter_greplogfailed to grep events error_class=TypeError error="String does not have #dig method"with a backtrace, and the record was passed through even though it does not match. With this change,call_digreturns nil, the same as when the key does not exist, so<regexp>drops the record and<exclude>keeps it, without any warning.Other users of a nested record accessor get the same behavior as for a missing key:
filter_parser(key_name) emits an error event "does not exist" instead of a TypeError. Withreserve_data true, it also passes the record on, as it does for a missing key.formatter_csvwrites an empty field.<buffer $.a.b>, puts the record in the same chunk as records without the key. Before this change, the whole event stream of that emit went to@ERROR, including the valid records. fluent-plugin-rewrite-tag-filter andcopywithignore_if_prev_successalso stop sending such records to@ERROR.Tests:
test_record_accessor.rb(string, integer and array parents) andtest_filter_grep.rb(<regexp>drops and<exclude>keeps such records, with no "failed to grep events" warning). Both fail on master and pass with this change.Docs Changes:
N/A
Release Note:
record_accessor: return nil instead of raising TypeError when a value on the way to a nested key is not a hash, the same as for a missing key. This fixes filter_grep passing non-matching records through with a "failed to grep events" warning. A nested buffer chunk key now puts such records in the same chunk as records without the key, instead of sending the whole event stream to
@ERROR.